agentile / PHP-Stanford-NLP

PHP interface to Stanford NLP tools (POS Tagger, NER, Parser)
168 stars 51 forks source link

Parser not producing correct output #6

Closed liantze closed 9 years ago

liantze commented 9 years ago

While trying out the sample code for the StanfordNLPParser, I got the following messages:

Notice: Undefined offset: 1 in C:\xampp\htdocs\stanford-nlp-test\PHP-Stanford-NLP-master\src\StanfordNLP\Parser.php on line 177

Notice: Undefined offset: 2 in C:\xampp\htdocs\stanford-nlp-test\PHP-Stanford-NLP-master\src\StanfordNLP\Parser.php on line 182
{"wordsAndTags":[["We","PRP"],["watched","VBD"],["the","DT"],["reddest","JJ"],["sunset","NN\r\n\r\n(ROOT\r\n"],["",""],["","(S\r\n"],["",""],["",""],["",""],["","(NP"],["","(PRP"],["","We))\r\n"],["",""],["",""],["",""],["","(VP"],["","(VBD"],["","watched)\r\n"],["",""],["",""],["",""],["",""],["",""],["","(NP"],["","(DT"],["","the)"],["","(JJ"],["","reddest)"],["","(NN"],["","sunset)))))\r\n\r\nnsubj(watched-2,"],["","We-1)\nroot(ROOT-0,"],["","watched-2)\ndet(sunset-5,"],["","the-3)\namod(sunset-5,"],["","reddest-4)\ndobj(watched-2,"],["","sunset-5)"]],
"penn":{"parent":null,"children":[]},
"typedDependencies":[]}

I'm using PHP 5.5.11 on Windows, tested against both stanford-parser-full-2014-10-31 and stanford-parser-full-2013-11-12, same results. (In contrast, the StanfordNLPPosTagger is running fine.)

liantze commented 9 years ago

Solved -- modify line 152 in Parser.php to

        $output = explode("\r\n\r\n", trim($this->getOutput()));