使用PY-corenlp解析字符串有许多句子
问题描述:
我有当我使用PY-corenlp解析字符串有许多句子使用PY-corenlp解析字符串有许多句子
Python的输出图像
输出显示问题它只是解析第一句,然后跳过下两句
但是当我使用CoreNLP服务器来解析我的句子时,它会自动将行分成三个句子并分别解析它们。
正确的结果图像
那么,如何解决这个问题?我非常感谢你的帮助。
答
迭代通过output['sentences']
列表:
text=‘This is it, kid. This is our chance. When you got a chance, you better take it.’
output = nlp.annotate(text, properties={‘annotators’: ‘tokenize,ssplit,lemma,pos,depparse,parse’, ‘outputFormat’: ‘json’})
for sent in output[‘sentences’]:
print(sent[‘parse’])
或者,您可以使用NLTK的CoreNLP API,见https://github.com/nltk/nltk/blob/develop/nltk/parse/corenlp.py#L343
什么'LEN(输出[ '句'])'在Python的例子?据推测,在正常操作中应该是3。 –
编写代码,不要粘贴屏幕截图......否则“真的很难帮助我们。 – alvas