2017-05-30 8 views
1

別のコンテキスト値の値に依存する一連の条件に基づいてコンテキスト変数の値を設定できますか?私はNLU(Natural Language Understanding)サービスと会話サービスを統合しようとしており、NLUが返す値に基づいていくつかのコンテキスト変数を設定したいと考えています。ワトソン会話サービスのコンテキスト変数に基づく処理条件

{ 
... 
"context": { 
    ... 
    "nlu_response": { 
     "entities": [{ 
      "type": "Person", 
      "relevance": 0.5, 
      "count": 1, 
      "text": "Jon Doe", 
      "emotion": { 
       "anger": 0.082378, 
       "disgust": 0.033499, 
       "fear": 0.072588, 
       "joy": 0.100971, 
       "sadness": 0.147584 
      }, 
      "sentiment": { 
       "score": 0.409803 
      } 
     }, 
     { 
      "type": "Person", 
      "relevance": 0.5, 
      "count": 1, 
      "text": "Jane Doe", 
      "emotion": { 
       "anger": 0.140151, 
       "disgust": 0.091598, 
       "fear": 0.059244, 
       "joy": 0.046762, 
       "sadness": 0.165763 
      }, 
      "sentiment": { 
       "score": 0 
      } 
     }] 
    } 
} 

}

と=タイプを持つエンティティオブジェクトの値がある場合にのみ、「ジョン・ドウ」の値がコンテキスト変数EntityPerson_1を作成したいと思います:たとえば、私はNLUから次のエンティティを取得しています"人"。

{ 
... 
"context": { 
    ... 
    "EntityPerson_1": <? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?> 
} 

}

答えて

0

はい、それは可能である:すなわち は、応答ノードで可能このようなものです。あなたのコードはほぼ正しいです。作業するコードは次のとおりです。

{ 
... 
"context": { 
... 
"EntityPerson_1": "<? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?>" 
} 

enter image description here

関連する問題