2017-04-19 34 views
2

我正在使用自然語言理解api。 文字我使用「hmmmm納瓦喔文是我戈納贏DS錫」,它是給錯誤WatsonException:錯誤:不支持的文本語言,代碼:400

WatsonException: Error: unsupported text language, Code: 400 

我的代碼是:

response = natural_language_understanding.analyze(
    text='hmmmm nawa ohh wen am I gona win ds tin', 
    features=[features.Sentiment(), features.Keywords(), features.Emotion(), features.Categories()]) 

如何將這些類型的文本傳遞給NLU API 。 需要幫助。

回答

2

這是失敗的,因爲在它試圖確定功能之前,它會嘗試猜測語言是什麼。設置語言將防止這種情況。

例如:

question = 'hmmmm nawa ohh wen am I gona win ds tin' 

f = [ 
    features.Categories(), 
    features.Concepts(), 
    features.Emotion(), 
    features.Entities(), 
    features.Relations(), 
    features.SemanticRoles(), 
    features.Sentiment() 
] 
r = nlu.analyze(text=question, features=f, language='en') 

print(json.dumps(r, indent=2)) 

輸出這樣的:

{ 
    "sentiment": { 
    "document": { 
     "score": 0.0, 
     "label": "neutral" 
    } 
    }, 
    "semantic_roles": [ 
    { 
     "subject": { 
     "text": "I" 
     }, 
     "sentence": "hmmmm nawa ohh wen am I gona win ds tin", 
     "object": { 
     "text": "ds tin" 
     }, 
     "action": { 
     "verb": { 
      "text": "win", 
      "tense": "present" 
     }, 
     "text": "win", 
     "normalized": "win" 
     } 
    } 
    ], 
    "relations": [], 
    "language": "en", 
    "entities": [], 
    "emotion": { 
    "document": { 
     "emotion": { 
     "sadness": 0.193275, 
     "joy": 0.309168, 
     "fear": 0.167981, 
     "disgust": 0.06316, 
     "anger": 0.130959 
     } 
    } 
    }, 
    "concepts": [], 
    "categories": [ 
    { 
     "score": 0.899547, 
     "label": "/art and entertainment" 
    }, 
    { 
     "score": 0.365657, 
     "label": "/hobbies and interests/reading" 
    }, 
    { 
     "score": 0.189432, 
     "label": "/art and entertainment/movies and tv/movies" 
    } 
    ] 
} 

這不是正確的英語的,所以我不希望結果是好的。

這裏你可以看到支持的語言特點:

https://www.ibm.com/watson/developercloud/doc/natural-language-understanding/index.html#supported-languages

+0

是我以前沒有提供語言=「EN」,讓我得到錯誤。謝謝。 – tom