LoginSignup
2

More than 5 years have passed since last update.

Watson Assitantで配列の特定の要素だけを抜き出す

Posted at

Watson AssistantでEntityの値のリストを取得したい

Watson Assistant(旧Conversation)では、SpEL(Spring Expression Language)に従ってスクリプトを記述することができるのですが、使いこなせている人はあまりいないのではないでしょうか?
Entityで取得した複数の値をContextに格納したかったのですがその際に躓いたのでメモ。

Collection Projectionを使用する

結論から言うと、Collection Projectionを用いるとうまく行きます。
書式は、
![projectionExpression]
です。

例えばYoubiというEntityを定義し、月曜日と火曜日を含むような文章を入力すると以下のようにentities.Youbiが認識されます。やりたいことは、

[{"entity":"Youbi","location":[0,3],"value":"月曜日","confidence":1},{"entity":"Youbi","location":[4,7],"value":"火曜日","confidence":1}]

これを
entities.Youbi.![value]
とすることで、以下のようにvalueの値の配列にすることができます。

["月曜日","火曜日"]

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2