dumb2champ Posted March 15, 2015 Share Posted March 15, 2015 I use PHPInsight scripts which provide opinion mining test.Below are example codes that provide scores and it class either positive, negative, or neutral <?php //sentimen order if (PHP_SAPI != 'cli') { echo "<pre>"; } $strings = array( 1 => 'Weather today is rubbish', 2 => 'This cake looks amazing', 3 => 'His skills are mediocre', 4 => 'He is very talented', 5 => 'She is seemingly very agressive', 6 => 'Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.', 7 => 'To be or not to be?', ); require_once __DIR__ . '/../autoload.php'; $sentiment = new \PHPInsight\Sentiment(); foreach ($strings as $string) { // calculations: $scores = $sentiment->score($string); $class = $sentiment->categorise($string); // output: echo "String: $string\n"; echo "Dominant: $class, scores: "; print_r($scores); echo "\n"; echo $a; } Result from above scripts => http://postimg.org/image/bf6fugyo5/ The result show scores and classes of each strings...But how to summarize total scores and classes of entire strings??? For example if negative more(>) than positive, then total class will be negative and vice versa. And also total scores of each string into one single scores which not more than 1Kindy need help...thanks Quote Link to comment https://forums.phpfreaks.com/topic/295265-calculate-total-score-of-strings/ Share on other sites More sharing options...
Solution kicken Posted March 15, 2015 Solution Share Posted March 15, 2015 Create a $totals array with the same pos/neu/neg indexes and sum the values as you loop. $totals=array('pos' => 0, 'neu' => 0, 'neg' => 0); foreach ($strings as $string){ $scores = $sentiment->score($string); $class = $sentiment->categorise($string); $totals[$class] += $scores[$class]; } var_dump($totals); 1 Quote Link to comment https://forums.phpfreaks.com/topic/295265-calculate-total-score-of-strings/#findComment-1508163 Share on other sites More sharing options...
dumb2champ Posted March 15, 2015 Author Share Posted March 15, 2015 Thanks kicken.. I really appreciate alot...but how to summarise which classes are most used(neg,neu,pos) from above result...not from each string but whole strings... Quote Link to comment https://forums.phpfreaks.com/topic/295265-calculate-total-score-of-strings/#findComment-1508165 Share on other sites More sharing options...
Barand Posted March 15, 2015 Share Posted March 15, 2015 Pretty much the same way. An array of counts. $counts=array('pos' => 0, 'neu' => 0, 'neg' => 0); foreach ($strings as $string){ $scores = $sentiment->score($string); $class = $sentiment->categorise($string); $counts[$class]++; // increment count for the class } Quote Link to comment https://forums.phpfreaks.com/topic/295265-calculate-total-score-of-strings/#findComment-1508166 Share on other sites More sharing options...
dumb2champ Posted March 15, 2015 Author Share Posted March 15, 2015 You guys help me alot...i`m really stupid...thanks alot...kicken and barand Quote Link to comment https://forums.phpfreaks.com/topic/295265-calculate-total-score-of-strings/#findComment-1508167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.