0
我正在使用Google Cloud Natural Language API。我的目标是在大块文本中提取句子和情绪,并对它们进行情感分析。Google Cloud Natural Language API - 句子提取(Python 2.7)
我收到以下“unexpected indent”错误。根据我的研究,它似乎不是一个“基本”缩进错误(如流氓空间等)。
print('Sentence {} has a sentiment score of {}'.format(index,sentence_sentiment)
IndentationError:unexpected indent
的代码内的for循环以下行(见下文全码)引起的问题。如果我删除它,问题就会消失。
print(sentence.content)
另外,如果我提出这个print语句的循环之外,我没有得到一个错误,但只有文字的大块的最后一句印刷(如可以预期)。
我对编程完全陌生 - 所以如果有人能够用非常简单的术语解释我做错了什么,并指出我在正确的方向,我会非常感激。
完整的脚本如下
迈克
from google.cloud import language
text = 'Terrible, Terrible service. I cant believe how bad this was.'
client = language.Client()
document = client.document_from_text(text)
sent_analysis = document.analyze_sentiment()
sentiment = sent_analysis.sentiment
annotations = document.annotate_text(include_sentiment=True, include_syntax=True, include_entities=True)
print ('this is the full text to be analysed:')
print(text)
print('Here is the sentiment score and magnitude for the full text')
print(sentiment.score, sentiment.magnitude)
#now for the individual sentence analyses
for index, sentence in enumerate(annotations.sentences):
sentence_sentiment = sentence.sentiment.score
print(sentence.content)
print('Sentence {} has a sentiment score of {}'.format(index, sentence_sentiment))
正确─白色空间的问题消失。我非常感谢您花时间帮忙。 – Mike