2017-04-07 44 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。