<html> <body> <?php error_reporting(E_ALL); include_once 'lib/stanford-nlp/autoload.php'; /* standford nlp autoloader inclusion */ $ner = new \StanfordNLP\NERTagger(__DIR__ . '/lib/stanford-ner-2015-04-20/classifiers/english.all.3class.distsim.crf.ser.gz', __DIR__ . '/lib/stanford-ner-2015-04-20/stanford-ner.jar'); $result = $ner->tag(explode(' ', "The Federal Reserve Bank of New York led by Timothy R. Geithner.")); echo "<h3>Log</h3>"; echo "<pre>"; var_dump($ner->getErrors()); echo "</pre>"; echo "<h3>Results</h3>"; echo "<pre>"; var_dump($result); echo "</pre>"; ?> </body> </html>
//EXTRACT SPOKEN WORDS if (substr($mySentence, 0, 8) === "What is ") { $valid = true; $position = strpos($mySentence, "is "); $query = substr($mySentence, $position + strlen("is ")); $query = ucwords($query); //echo $query; $_SESSION["query"] = $query; //Store the search term in the session echo "<br>"; $firstload = true; //Page has been loaded the first time } //FIND THE TAG OF THE USERS SPOKEN WORD, after the page is loaded the first time if ($firstload) { $result = $ner->tag(explode(' ', $query)); //Use NER tagging to identify the tag of the topic $tag = $result[0][1]; //Store the tag in a variable if ($query == "Adidas" || $query == "Samsung") { $tag = "ORGANIZATION"; } // CHECK IF THE SPOKEN WORD IS A PERSON, LOCATION OR ORGANIZATION. Tell the user if ($tag == "PERSON") { echo $query . " is a person"; } else { if ($tag == "LOCATION") { echo $query . " is a location"; } else { if ($tag == "ORGANIZATION") { echo $query . " is a organization";
public static function NER($sentences) { Yii::setPathOfAlias('StanfordNLP', Yii::app()->basePath . '/components/StanfordNLP'); $ner = new StanfordNLP\NERTagger(Yii::app()->params['stanfordNerPath'] . 'classifiers/english.muc.7class.distsim.crf.ser.gz', Yii::app()->params['stanfordNerPath'] . 'stanford-ner.jar'); $result = $ner->tag(explode('.', $sentences)); return $result; }