Stanford Parser and NLTK

后端 未结 18 2359
既然无缘
既然无缘 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:23

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

    A slight update (or simply alternative) on danger89's comprehensive answer on using Stanford Parser in NLTK and Python

    With stanford-parser-full-2015-04-20, JRE 1.8 and nltk 3.0.4 (python 2.7.6), it appears that you no longer need to extract the englishPCFG.ser.gz from stanford-parser-x.x.x-models.jar or setting up any os.environ

    from nltk.parse.stanford import StanfordParser
    
    english_parser = StanfordParser('path/stanford-parser.jar', 'path/stanford-parser-3.5.2-models.jar')
    
    s = "The real voyage of discovery consists not in seeking new landscapes, but in having new eyes."
    
    sentences = english_parser.raw_parse_sents((s,))
    print sentences #only print  for this version
    
    #draw the tree
    for line in sentences:
        for sentence in line:
            sentence.draw()
    

提交回复
热议问题