0

私の質問は、ユーザーが指定した値をエンティティに追加する方法です。ユーザーが指定した値は動的です。

添付の画像でわかるように、Watson の応答は、ユーザーが指定した値で toppings 変数を上書きします。

 {
   "output": {
   "text": "I got an order to add one or more toppings. 
            Adding <?context.toppings.append('toppings')?>. 
            Toppings to provide: <?entities['toppings']?.toString()?>"
    },
   "context": {
   "toppings": "<? entities['toppings']?.toString()?>"
    }
 }

ここに画像の説明を入力

4

1 に答える 1

1

関数を使用して配列に追加できます.append()

あなたの例では、"toppings": "<? entities['toppings']?.toString()?>"このノードが実際に認識されたエンティティで処理されるたびに、式は toppings 変数を上書きします@toppings。まず、$toppings変数を配列として定義する必要があります。例:

"context" : { "toppings" : [] }

次にcontext、ダイアログ ノードの一部に次のように記述できます。

"context" : { "toppings" : "<?$toppings.append(entities['toppings'].toJsonArray())?>" }

詳細については、ドキュメントをご覧ください: Watson Conversation Doc

編集:これについて考えると、エンティティとそれを格納する変数に同じ名前を付けることはおそらく良い考えではありません.:-)

于 2016-11-08T15:29:32.267 に答える