Stanford Parser and NLTK

后端 未结 18 2656
既然无缘
既然无缘 2020-11-22 01:32

Is it possible to use Stanford Parser in NLTK? (I am not talking about Stanford POS.)

18条回答
  •  忘掉有多难
    2020-11-22 02:16

    Note that this answer applies to NLTK v 3.0, and not to more recent versions.

    Here is an adaptation of danger98's code that works with nltk3.0.0 on windoze, and presumably the other platforms as well, adjust directory names as appropriate for your setup:

    import os
    from nltk.parse import stanford
    os.environ['STANFORD_PARSER'] = 'd:/stanford-parser'
    os.environ['STANFORD_MODELS'] = 'd:/stanford-parser'
    os.environ['JAVAHOME'] = 'c:/Program Files/java/jre7/bin'
    
    parser = stanford.StanfordParser(model_path="d:/stanford-grammars/englishPCFG.ser.gz")
    sentences = parser.raw_parse_sents(("Hello, My name is Melroy.", "What is your name?"))
    print sentences
    

    Note that the parsing command has changed (see the source code at www.nltk.org/_modules/nltk/parse/stanford.html), and that you need to define the JAVAHOME variable. I tried to get it to read the grammar file in situ in the jar, but have so far failed to do that.

提交回复
热议问题