Discovering QiChat, the SBR language for creating chatbots

# Taking conversational context into account¶

## 1. Using the "first" function¶

Now that we can create varied inputs and outputs, it's time to take conditions into account so that the robot can answer according to context.

Use the function ^first to select outputs according to predefined conditions. The ordering of the outputs is relevant: the first one whose condition is true will be said.

Conditions are written $variable==value, with the following operators: == (equal), < (inferior), > (superior), <> (different). u:(what do you know about me) ^first[ "$asked_joke==1 Your name is $name and you like jokes!" "Your name is$name !"
"I don't know anything about you, sorry."
]


As you can see here, putting a variable in the output counts as a condition: the second output will only be said if the variable $name has a value. The variable $asked_joke works as a boolean: if its value is 1, the condition will be true, but if it has another value or isn't instantiated, it will be false.

Note: don't forget to add a default output, in case all of the conditions are false (without a default output, if none of the conditions are true, the robot will not say anything).

If you integrate this rule as is, and ask your robot "what do you know about me", he will always answer "I don't know anything about you, sorry.": you will have to instantiate the variables so that he can learn more.

In step 3, we created the following rule:

u:(my name is _*)
Nice to meet you $1 !  Here the robot is only able to repeat the name, he hasn't learnt it. Add the variable$name:

u:(my name is _*)
$name=$1
Nice to meet you $name !  Now say "what do you know about me": the robot should answer with your name! In the previous step (Randomizing jokes), we created the following rule: u:(tell me a joke) ^rand[ "You know the one about the vertical bed? It will make your hair stand up straight!" "Do you know the difference between roast beef and pea soup? Anyone can roast beef!" "Two peanuts were walking down the street and one was a salted." "I tried to catch some fog the other day. I mist!" ]  The robot is able to tell you a joke to entertain you, but doesn't remember having done so. Add the variable$asked_joke:

u:(tell me a joke)