2017-05-08 145 views
2

我也跟着这样的回答: Stanford nlp for pythonPY-corenlp - 类型错误:字符串索引必须是整数

from pycorenlp import StanfordCoreNLP 
from newspaper import Article 

url = u'newsArticle.example.html' 
nlp = StanfordCoreNLP('http://localhost:9000') 
article = Article(url) 
article.download() 
article.parse() 


LARGE_TEXT=article.text 


res = nlp.annotate(LARGE_TEXT, 
       properties={ 
        'annotators': 'sentiment', 
        'outputFormat': 'json', 
        'timeout': 1000, 
       }) 
for s in res["sentences"]: 
    print ("%d: '%s': %s %s" % (
     s["index"], 
     " ".join([t["word"] for t in s["tokens"]]), 
     s["sentimentValue"], s["sentiment"])) 

我用一个较长的文本输入,遇到以下错误:

for s in res["sentences"]: 
TypeError: string indices must be integers 

回答

1

的问题是'timeout':1000

我将其更改为'timeout':10000

相关问题