我跟随了这个答案:Stanford nlp for python
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发布于 2017-05-08 14:06:43
问题是'timeout':1000
我将其更改为'timeout':10000
https://stackoverflow.com/questions/43849689
复制相似问题