带有NLTK的斯坦福解析器产生空输出 [英] Stanford parser with NLTK produces empty output

查看:94
本文介绍了带有NLTK的斯坦福解析器产生空输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个用NLTK接口用Python编写的小型应用程序中使用Stanford解析器.我尝试了下面给出的代码.

I am trying to use the Stanford parser in a small application written in Python with the NLTK interface. I tried the code given below.

一切似乎都正常,没有错误,启动了Java,但是我系统地得到了一个空的iterator(),并且该程序未显示解析树.

Everything seems to work right, no errors, Java is launched but I systematically get an empty iterator () and the program does not display the parsing tree.

我使用Windows 7,Python 3.4.3,JRE jre1.8.0_51.我对POS标记器做了同样的操作,但是得到了相同的空结果.

I use Windows 7, Python 3.4.3, JRE jre1.8.0_51. I did the same with the POS tagger but got the same empty result.

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() 

推荐答案

尝试:

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() 

这篇关于带有NLTK的斯坦福解析器产生空输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆