2017-10-16 96 views
1

我有當我使用PY-corenlp解析字符串有許多句子使用PY-corenlp解析字符串有許多句子

Python的輸出圖像

enter image description here

輸出顯示問題它只是解析第一句,然後跳過下兩句

但是當我使用CoreNLP服務器來解析我的句子時,它會自動將行分成三個句子並分別解析它們。

正確的結果圖像

enter image description here

那麼,如何解決這個問題?我非常感謝你的幫助。

+0

什麼'LEN(輸出[ '句'])'在Python的例子?據推測,在正常操作中應該是3。 –

+0

編寫代碼,不要粘貼屏幕截圖......否則「真的很難幫助我們。 – alvas

回答

0

迭代通過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