2017-04-07 48 views
0

使用音调分析仪时,我只能检索1个结果。例如,如果我使用以下输入文本。音调分析仪仅返回1句话的分析

string m_StringToAnalyse = "The World Rocks ! I Love Everything !! Bananas are awesome! Old King Cole was a merry old soul!";

结果仅返回用于文档级和分析sentence_id = 0,即。 “世界岩石!”。接下来的3个句子的分析不会被返回。

任何想法我做错了或我错过了什么?运行提供的示例代码时也是如此。

string m_StringToAnalyse = "This service enables people to discover and understand, and revise the impact of tone in their content. It uses linguistic analysis to detect and interpret emotional, social, and language cues found in text.";

运行使用上面提供的示例句子示例代码也返回该文件和仅在第一句子结果音调分析。

我尝试过版本“2016-02-19”以及“2017-03-15”,结果相同。

回答

0

我相信,如果你想逐句分析你需要发送每一个单独的句子作为JSON对象。然后它将返回分析数组,其中id = SENTENCE_NUM。

这里有一个的例子我没有使用多个YouTube评论功能(使用Python):无论你想用JSON对象

def get_comments(video): 
    #Get the comments from the Youtube API using requests 

    url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&maxResults=100&videoId='+ video +'&key=' + youtube_credentials['api_key'] 

    r = requests.get(url) 
    comment_dict = list() 

    # for item in comments, add an object to the list with the text of the comment 

    for item in r.json()['items']: 
     the_comment = {"text": item['snippet']['topLevelComment']['snippet']['textOriginal']} 
     comment_dict.append(the_comment) 

    # return the list as JSON to the sentiment_analysis function 
    return json.dumps(comment_dict) 

def sentiment_analysis(words): 

    # Load Watson Credentials using Python SDK 

    tone_analyzer = ToneAnalyzerV3(
    username=watson_credentials['username'], password=watson_credentials['password'], version='2016-02-11') 

    # Get the tone, based on the JSON object that is passed to sentiment_analysis 
    return_sentiment = json.dumps(tone_analyzer.tone(text=words), indent=2) 
    return_sentiment = json.loads(return_sentiment) 

之后,你可以做。如果你想对许多对象进行分析,我还想对其他任何人进行说明,你可以在tone_analyzer.tone函数中添加句子= False。