function tag_the_content($the_text) { $time_start = microtime(true); // sets DIR path variable $dir = dirname(__FILE__); // loads tagger include $dir . '/PHP-Stanford-NLP/autoload.php'; // creates tagger $pos = new \StanfordNLP\POSTagger($dir . '/PHP-Stanford-NLP/stanford-postagger-2015-04-20/models/english-left3words-distsim.tagger', $dir . '/PHP-Stanford-NLP/stanford-postagger-2015-04-20/stanford-postagger.jar'); // calls tagger to tag the_content // $result = $pos->tag(explode(' ', get_the_content() )); // *** change back to this in production *** $result = $pos->tag(explode(' ', $the_text)); // echo json_encode($result); return $result; }
$pos++; break; case "neg": $neg++; break; } } } //Calculate percentages for each opinion type $total = $pos + $neg + $neu; $posPercent = round($pos / $total * 100); $negPercent = round($neg / $total * 100); $neuPercent = round($neu / $total * 100); speak("{$posPercent} % positive, {$negPercent} % negative, {$neuPercent} % neutral"); //FIND TEN MOST REPRESENTATIVE NOUNS AND SPEAK THEM, USES POS TAGGING $result = $pos->tag(explode(' ', $totalTweetText)); foreach ($result as $inner_arr) { $value = $inner_arr[1]; if (stripos($value, "NN") !== false) { $allnouns .= $inner_arr[0] . " "; //String of all nouns } } $popularnouns = array_count_values(explode(' ', $allnouns)); arsort($popularnouns); $toptensortednouns = array_slice($popularnouns, 0, 10); $keys = array_keys($toptensortednouns); //Store the hashtags in an array echo "<br><br>"; speak("The most representative nouns on this topic are: "); echo "<br>";