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