我试图在一个用Python编写的带有NLTK接口的小应用程序中使用Stanford解析器。我尝试了下面给出的代码。
一切似乎都正常,没有错误,Java已启动,但我系统地获取一个空的iterator(),程序不会显示解析树。
我使用Windows 7,Python 3.4.3,JRE jre1.8.0_51。我对POS标签做了同样的事,但得到了相同的空结果。
import os
from nltk.parse import stanford
os.environ['STANFORD_PARSER'] = 'path\\jars'
os.environ['STANFORD_MODELS'] = 'path\\jars'
os.environ['JAVAHOME']= "path\\Java\jre1.8.0_51\\bin"
parser = stanford.StanfordParser(model_path="path\\englishPCFG.ser.gz")
sentences = parser.raw_parse_sents(("Hello the world.", "Thank you for helping me with this problem."))
print(sentences)
for line in sentences:
for sentence in line:
sentence.draw()
答案 0 :(得分:0)
尝试:
sentences = list(parser.raw_parse_sents(("Hello the world.", "Thank you for helping me with this problem.")))
for line in sentences:
for sentence in line:
sentence.draw()