C Stephens
C Stephens

Reputation: 75

Conditionally set a context in Watson Conversation

I'm using Watson Conversation and trying to conditionally set a context variable.

In response to a question we ask, some people say "yes," some say "no," and some say "no, but my husband has" (or some similar variations). I have the entity @other_person that recognizes "husband" (and wife, and friend, etc).

What I'm trying to do is set a context variable $mentionother to true if they mention another person, and false otherwise.
So far I have this, but it's not working and I can't quite figure it out. I haven't been able to find good documentation on this so I may be way off.

"context": {
  "mentionother": "(@other_person==null ? false : true)"
}

Can anyone provide some help here, and/or tell me where to look for better documentation on this?
I'm actually not 100% sure what language to look under; I think I've read this is Java but I'm out of practice so not positive.

Upvotes: 0

Views: 1228

Answers (2)

Sayuri Mizuguchi
Sayuri Mizuguchi

Reputation: 5330

In this case, @R. Timmer is correct. But you need to set the condition inside the <? ?>, so, is basically this:

{
  "context": {
    "otherPerson": "<? (@other_person==null)? false : true ?>"
  },
  "output": {
    "text": {
      "values": [
        "Now you can see $otherPerson true or false"
      ],
      "selection_policy": "sequential"
    }
  }
}

Please, consider marking the answer for R. Timmer, I just supplemented his answer.

Upvotes: 2

R. Timmer
R. Timmer

Reputation: 56

Conditional variables work like this:

variable x = (expression) ? value if true : value if false

try this: "(@other_person==null)? false : true"

since you are not sure what you are using next to json i'm not 100% positive this works.

source: https://www.tutorialspoint.com/java/java_basic_operators.htm

Upvotes: 1

Related Questions