Watson Conversation Service 中基于上下文变量的处理条件
Processing conditions based on context variables in Watson Conversation Service
是否可以根据一组取决于另一个上下文值的值的条件来设置上下文变量的值?我正在尝试将 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
}
}]
}
}
}
并且想要创建一个上下文变量 EntityPerson_1,只有当实体对象中存在类型为 "Person" 的值时,其值为 "Jon Doe"。
换句话说,在响应节点中可能是这样的:
{
...
"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:'' ?>
}
}
是的,这是可能的。您的代码几乎是正确的。工作代码是:
{
...
"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:'' ?>"
}
是否可以根据一组取决于另一个上下文值的值的条件来设置上下文变量的值?我正在尝试将 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
}
}]
}
}
}
并且想要创建一个上下文变量 EntityPerson_1,只有当实体对象中存在类型为 "Person" 的值时,其值为 "Jon Doe"。 换句话说,在响应节点中可能是这样的:
{
...
"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:'' ?>
}
}
是的,这是可能的。您的代码几乎是正确的。工作代码是:
{
...
"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:'' ?>"
}