Detect tweet or message mood

Are there any APIs that can extract moods from a string (for use in PHP, but can be implemented in any language)?

If it does not exist, how would I like to build a classifier, presumably something related to machine learning, where I extract words with a known positive / negative.

+8
php machine-learning
source share
2 answers

I would suggest AlchemyAPI . They have fairly simple APIs (which should not be difficult to use. For your specific case, see here

+2
source share

Using the AlchemyapI suggestion above, here is a really simple system based on Facebook statuses

$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 />'; } 
0
source share

All Articles