agentile / PHP-Stanford-NLP

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

[Win7] Empty array being returned when running Stanford Parser #3

Closed PGDesolator closed 10 years ago

PGDesolator commented 10 years ago

Hi, I had simillar issues with the POS and NER but was able to resolve them using samkool suggestion in the other thread. However, the format for command for the Parser is different and I'm having difficulties setting up the path. This is the output im getting when running the following code

<? require './NER/StanfordNLP/Base.php'; require './NER/StanfordNLP/Exception.php'; require './NER/StanfordNLP/Parser.php'; require './NER/StanfordNLP/StanfordTagger.php'; require './NER/StanfordNLP/NERTagger.php';

        $parser = new \StanfordNLP\Parser(
            'C:/somepath/stanford-parser-full-2013-11-12/stanford-parser.jar'
            );
        $result = $parser->parseSentence("What does the fox say?"); 
        var_dump($result);
        var_dump($parser);

?> Output

array (size=3) 'wordsAndTags' => array (size=0) empty 'penn' => array (size=2) 'parent' => null 'children' => array (size=0) empty 'typedDependencies' => array (size=0) empty

object(StanfordNLP\Parser)[1] public 'output_format' => string 'wordsAndTags,penn,typedDependencies' (length=35) public 'lexicalized_parser' => boolean false protected 'java_path' => string 'java' (length=4) protected 'jar' => string 'C:/somepath/stanford-parser-full-2013-11-12/stanford-parser.jar' (length=103) protected 'java_options' => array (size=1) 0 => string '-mx300m' (length=7) protected 'output' => null protected 'errors' => string 'Error: Could not find or load main class edu.stanford.nlp.parser.lexparser.LexicalizedParser ' (length=94)

PGDesolator commented 10 years ago

Holy moly, spent like 6 hours resolving this particular issue and finally was able to solve it. The problem was that the code needs specification of the model.jar file as well i.e. "stanford-parser-3.3.0-models.jar". Therefore I had to edit the code to this in Parser.php at line 89-91

    $otherJar= "stanford-parser-3.3.0-models.jar";
    $cmd = $this->getJavaPath() . " $options -cp " . $this->getJar()
    .";$otherJar "
    ." edu.stanford.nlp.parser.lexparser.LexicalizedParser "
    . "-outputFormat \"".$this->getOutputFormat()."\" " 
    ."-outputFormatOptions \"nonCollapsedDependencies\" "
    .$parser." "
    .$tmpfname
    ;
agentile commented 10 years ago

Trying to find some time to incorporate these issue changes into the codebase. Will try to do it soon. Thanks!