Processing conditions based on context variables in Watson Conversation Service

289 Views Asked by At

Is it possible to set the value of a context variable based on a set of conditions which depend on value of another context value? I am trying to integrate NLU(Natural Language Understanding) service with Conversation service and would like to set some context variables based on the values returned by NLU. For example I am getting following entities from 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
            }
        }]
    }
}

}

and would like to create a context variable EntityPerson_1 with a value of "Jon Doe" only if there are values in entity object with type="Person". In other words is something like this possible in a response node:

{
...
"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:'' ?>
}

}

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, it is possible. Your code is almost correct. Working code is:

{
 ...
 "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