首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >py TypeError:字符串索引必须是整数

py TypeError:字符串索引必须是整数
EN

Stack Overflow用户
提问于 2017-05-08 14:01:16
回答 1查看 838关注 0票数 2

我跟随了这个答案:Stanford nlp for python

代码语言:javascript
复制
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"]))

我使用较长的文本作为输入,并遇到以下错误:

代码语言:javascript
复制
 for s in res["sentences"]:
TypeError: string indices must be integers
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-08 14:06:43

问题是'timeout':1000

我将其更改为'timeout':10000

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43849689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档