Search code examples
javanlpstanford-nlp

Stanford CoreNLP ExhaustivePCFGParser Initialization Query


I am a NLP student and relatively new to Stanford CoreNLP. I wanted to try PCFG parser for my sentence because I wanted to get the probability score for the best parse tree the parser fetches. I was able to successfully use LexicalizedParser as

    LexicalizedParser myParser = LexicalizedParser.loadModel();
    myParser.parse(tokenLabels); // where List<CoreLabel> tokenLabels

But I don't see any loadModel method for ExhaustivePCFGParser so am confused as to how to initialize and start using parse function for it. I can see the constructor defined for it but have no idea what the parameters means ? Could you please provide some guidance for this.


Solution

  • You almost certainly still want to work by using a LexicalizedParser. From that you can get a ParserQuery object (just as the parse(List<? extends HasWord> lst) method of LexicalizedParser does) and then operate with it:

    ParserQuery pq = myParser.parserQuery();
    if (pq.parse(tokenLabels)) {
        System.out.println("Viterbi probability  is " + pq.getPCFGScore());
    }