Get the K best parses of a sentence with Stanford Parser

前端 未结 2 688
滥情空心
滥情空心 2021-01-21 18:03

I want to have the K best parses of a sentence, I figured that this can be done with ExhaustivePCFGParser Class , the problem is that I don\'t know how to use this class , more

2条回答
  •  情深已故
    2021-01-21 18:50

    In general you do things via a LexicalizedParser object which is a "grammar" which provides all these things (the grammars, lexicon, indices, etc.).

    From the command-line, the following will work:

    java -mx500m -cp "*" edu.stanford.nlp.parser.lexparser.LexicalizedParser -printPCFGkBest 20 edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz data/testsent.txt
    

    At the API level, you need to get a LexicalizedParserQuery object. Once you have a LexicalizedParser lp (as in ParserDemo.java) you can do the following:

    LexicalizedParser lp = ... // Load / train a model
    LexicalizedParserQuery lpq = lp.parserQuery();
    lpq.parse(sentence);
    List> kBest = lpq.getKBestPCFGParses(20);
    

    A LexicalizedParserQuery is sort of equivalent to a java regex Matcher.

    Note: at present kBest parsing works well only for PCFG not factored grammars.

提交回复
热议问题