是否可以根据一组依赖于另一个上下文值的条件来设置上下文变量的值?我正在尝试将 NLU(自然语言理解)服务与对话服务集成,并希望根据 NLU 返回的值设置一些上下文变量。例如,我从 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
}
}]
}
}
}
并且想要创建一个值为“Jon Doe”的上下文变量 EntityPerson_1,仅当实体对象中存在 type="Person" 的值时。换句话说,在响应节点中可能是这样的:
{
...
"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:'' ?>
}
}