【发布时间】:2019-04-18 00:19:14
【问题描述】:
我正在使用 IBM Watson 的语气分析器分析文本,并且我正在尝试提取与句子语气相关的所有信息(例如,sentence_id、text、tones、tone_id、tone_name、@987654326 @) 并将其添加到数据框(带有列;sentence_id、text、tones、tone_id、score 和 tone_name)。这是我的输出示例:
> [{'document_tone': {'tones': [{'score': 0.551743,
'tone_id': 'analytical',
'tone_name': 'Analytical'}]},
'sentences_tone': [{'sentence_id': 0,
'text': '@jozee25 race is the basis on which quotas are implemented.',
'tones': []},
{'sentence_id': 1, 'text': 'helloooooo', 'tones': []}]},
{'document_tone': {'tones': []}},
{'document_tone': {'tones': [{'score': 0.802429,
'tone_id': 'analytical',
'tone_name': 'Analytical'},
{'score': 0.60167, 'tone_id': 'confident', 'tone_name': 'Confident'}]},
'sentences_tone': [{'sentence_id': 0,
'text': '@growawaysa @cricketandre i have the answer on top yard from dpw:it is not currently "surplus to govt requirements".it is still being used for garaging until a new facility is ready in maitland.the',
'tones': [{'score': 0.631014,
'tone_id': 'analytical',
'tone_name': 'Analytical'}]},
{'sentence_id': 1,
'text': 'cost of the housing options will of course depend on prospects for cross subsidisation.',
'tones': [{'score': 0.589295,
'tone_id': 'analytical',
'tone_name': 'Analytical'},
{'score': 0.509368, 'tone_id': 'confident', 'tone_name': 'Confident'}]}]},
{'document_tone': {'tones': [{'score': 0.58393,
'tone_id': 'tentative',
'tone_name': 'Tentative'},
{'score': 0.641954, 'tone_id': 'analytical', 'tone_name': 'Analytical'}]}},
{'document_tone': {'tones': [{'score': 0.817073,
'tone_id': 'joy',
'tone_name': 'Joy'},
{'score': 0.920556, 'tone_id': 'analytical', 'tone_name': 'Analytical'},
{'score': 0.808202, 'tone_id': 'tentative', 'tone_name': 'Tentative'}]},
'sentences_tone': [{'sentence_id': 0,
'text': 'thanks @khayadlangaand colleagues for the fascinating tour yesterday.really',
'tones': [{'score': 0.771305, 'tone_id': 'joy', 'tone_name': 'Joy'},
{'score': 0.724236, 'tone_id': 'analytical', 'tone_name': 'Analytical'}]},
{'sentence_id': 1,
'text': 'eyeopening and i learnt a lot.',
'tones': [{'score': 0.572756, 'tone_id': 'joy', 'tone_name': 'Joy'},
{'score': 0.842108, 'tone_id': 'analytical', 'tone_name': 'Analytical'},
{'score': 0.75152, 'tone_id': 'tentative', 'tone_name': 'Tentative'}]}]},
这是我为获得此输出而编写的代码:
result =[]
for i in helen['Tweets']:
tone_analysis = tone_analyzer.tone(
{'text': i},
'application/json'
).get_result()
result.append(tone_analysis)
【问题讨论】:
-
你有什么问题?
标签: python python-3.x ibm-watson tone-analyzer