2017-04-19 14 views
2

私は自然言語理解APIを使用しています。私が使用しています テキスト「うーむ名和おおウェンはIゴナ勝利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

関連する問題