【发布时间】:2021-03-06 13:50:37
【问题描述】:
需要一些帮助 - 我正在尝试分析新闻文章。 我有一个积极词和消极词的列表。我正在文章内容中搜索单词 a 的实例。
我的问题是否定词列表比肯定词列表长很多,所以所有结果都偏向否定。
我正在寻找一种方法来规范化结果,以便积极词相对于消极词略微加权,以平衡找到消极词的机会相当高的事实。不幸的是,我不知道从哪里开始。
感谢您抽出宝贵时间阅读本文。
下面是我目前的代码。
function process_scores($content)
{
$positive_score = 0;
for ($i = 0; $i < count($this->positive_words); $i++) {
if($this->positive_words[$i] != "")
{
$c = substr_count( strtolower($content) , $this->positive_words[$i] );
if($c > 0)
{
$positive_score += $c;
}
}
}
$negative_score = 0;
for ($i = 0; $i < count($this->negative_words); $i++) {
if($this->negative_words[$i] != "")
{
$c = substr_count( strtolower($content) , $this->negative_words[$i] );
if($c > 0)
{
$negative_score += $c;
}
}
}
return ["positive_score" => $positive_score, "negative_score" => $negative_score];
}
【问题讨论】:
-
不确定PHP Sentiment Analyzer 是否有兴趣。
标签: php math statistics