8

是否有任何 API 可以从字符串中提取情绪(用于 PHP,但可以用任何语言实现)?

如果一个不存在,我将如何构建一个分类器,大概与机器学习相关的东西,我提取具有已知正面/负面的单词。

4

2 回答 2

2

我会建议AlchemyAPI。他们有非常简单的 API(应该不难使用。对于您的具体情况,请查看此处

于 2012-05-17T16:29:53.957 回答
0

使用 AlchemyapI 的上述建议,这是一个基于 Facebook 状态的非常简单的系统

  $id = CURRENT USER ID;
  $message = array(); //the users posts with scores
  $status = $fb->fql("SELECT status_id, message FROM status WHERE uid=$id LIMIT 10");
  foreach($status as $stat) {
    $message = file_get_contents("http://access.alchemyapi.com/calls/text/TextGetTextSentiment"
                      ."?outputMode=json&apikey=MYAPIKEY"
                      ."&text=".urlencode($stat['message']));
    $data = json_decode($message); //get reply
    $messages[] = array("status"=>$stat['message'], "score"=>($data->docSentiment->type!="neutral") ? $data->docSentiment->score : 0); //save reply
  }

  $user = $fb->api("/".$id); //query the user

  $content .= "<h3>".$user['name']."</h3>";

  $total = 0;
  $count = 0;
  foreach($messages as $message) {
    $total += $message['score'];
    if($message['score']!=0) $count++;
  }

  $content .= 'Has an average rating of '.$total/$count.' <meter min="-1" max="1" value="'.$total/$count.'"></meter><br /><br />';

  foreach($messages as $message) {
    $content .= '<b>'.$message['status'].'</b> '.$message['score'].'</br>'
               .'<meter ' //class="'.($message['score'] == 0 ? "yellow" : $message['score'] < 0 ? "red" : "green").'" '
               .'value="'.$message['score'].'" min="-0.5" max="0.5" optimum="0">'.$message['score'].' out of -1 to 1</meter><br /><br />';
  }
于 2012-05-20T08:27:42.457 回答