Используя следующий код, я получаю сообщение об ошибке
TypeError: невозможно преобразовать элемент последовательности обновления словаря # 0 в последовательность
Используется следующий код:
import watson_developer_cloud as WDC
import watson_developer_cloud.natural_language_understanding.features.v1 as nluFeatures
#from wdc_config import nlu_config
nlu = WDC.NaturalLanguageUnderstandingV1('2017-02-27',username='myusernamehere',password='mypasswordhere')
data = ([1, "I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser Gate. All those moments will be lost in time, like tears in rain. Time to die."])
def nlu_analyze():
response = nlu.analyze(text=data,features=[nluFeatures.Keywords(),nluFeatures.Entities(),nluFeatures.Categories(),nluFeatures.Emotion(),nluFeatures.Sentiment()])
return response
response = nlu_analyze()
print(response["keywords"])
print(response["entities"])
print(response["categories"])
print(response["emotion"])
print(response["sentiment"])
Почему я получаю эту ошибку?
решаемые
Благодаря chughts эта проблема решена.
import watson_developer_cloud as WDC
from watson_developer_cloud.natural_language_understanding_v1 import Features, KeywordsOptions, EntitiesOptions, CategoriesOptions, EmotionOptions, SentimentOptions
nlu = WDC.NaturalLanguageUnderstandingV1('2017-02-27',username='yourusername',password='yourpassword')
data = ("I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser Gate. All those moments will be lost in time, like tears in rain. Time to die.")
def nlu_analyze():
response = nlu.analyze(text=data, features=Features(keywords=KeywordsOptions(), entities=EntitiesOptions(), categories=CategoriesOptions(), emotion=EmotionOptions(), sentiment=SentimentOptions()))
return response
response = nlu_analyze()
print(response["keywords"])
print(response["entities"])
print(response["categories"])
print(response["emotion"])
print(response["sentiment"])