IBM Watson Assistant: Trying to evaluate and compare multiple context variables - ibm-cloud

I've just started trying out Watson Assistant and have no clue what I'm doing.
I'm trying to built a chatbot that asks a series of questions and then outputs an evaluation based on the user's inputs.
E.g. Inputs:
Q1 "How many apples do you have?"
Q2 "How many apples does your neighbour have?"
Q3 "Did you eat any apples?"
With my desired output as:
IF ((Q1 > Q2) AND Q3 = "No")
THEN output "You have more apples"
ELSEIF ((Q1 > Q2) AND Q3 = "Yes")
THEN output "You might not have more apples"
ENDIF
I've currently used slots to collect all the inputs in one node but I don't know how to evaluate them to give the correct outputs.

In Watson Assistant inside the skill / dialog editor, you can edit the responses. For a response it is possible to contain expressions. The documentation for Watson Assistant has a section on Expression anguage methods and on Expressions for accessing objects. I have several examples in this GitHub repo Watson Conversation Variables which demonstrate how to evaluate the context variables and produce and output like you want.
Look here on how to use the ternary operator.

Related

how do duckduckgo spice IA secondary API calls get their parameters?

I have been looking through the spice instant answer source code. Yes, I know it is in maintenance mode, but I am still curious.
The documentation makes it fairly clear that the primary spice to API gets its numerical parameters $1, $2, etc. from the handle function.
My question: should there be secondary API calls included with spice alt_to as, say, in the movie spice IA, where do the numerical parameters to that API call come from?
Note, for instance, the $1 in both the movie_image and cast_image secondary API calls in spice alt_to at the preceding link. I am asking which regex capture returns those instances of $1.
I believe I see how this works now. The flow of information is still a bit murky to me, but at least I see how all of the requisite information is there.
I'll take the cryptocurrency instant answer as an example. The alt_to element in the perl package file at that link has a key named cryptonator. The corresponding .js file constructs a matching endpoint:
var endpoint = "/js/spice/cryptonator/" + from + "/" + to;
Note the general shape of the "remainder" past /js/spice/cryptonator: from/to, where from and to will be two strings.
Back in the perl package the hash alt_to->{cryptonator} has a key from which receives, I think, this remainder from/to. The value corresponding to that key is a regex meant to split up that string into its two constituents:
from => '([^/]+)/([^/]*)'
Applied to from/to, that regex will return $1=from and $2=to. These, then, are the $1 and $2 that go into
to => 'https://api.cryptonator.com/api/full/$1-$2'
in alt_to.
In short:
The to field of alt_to->{blah} receives its numerical parameters by having the from regex operate on the remainder past /js/spice/blah/ of the name of the corresponding endpoint constructed in the relevant .js file.

RASA: Automatic generation of stories

I want to know whether it is possible to automatically generate stories to train the chatbot using RASA.
I have built my training data using the online training session to generate the stories and I found it very impractical. I would like to know whether there is some automatic way to do the story conversion of any conversation.
You can use interactive learning to create training data while speaking to the bot. See the docs here for more information on how to use interactive learning.
This is probably too late of a response but it is for the rest of the community who might still need an answer to this. A few months ago, I personally experienced that it would take too long to conduct interactive learning to train your RASA bot (especially when you have hundreds of intents and actions).
What I did was:
1) Compile all my named intents and actions(utter_) into a .csv file with following column headers : [subject] | [intent_name] | [utter_name]
2) Parse the intent name along with its respective action name in the same row into Markdown(.md) format while adding the respective strings to follow the formatting of the stories.md file
Package this into a function and call in a for loop:
subcell = "## " + column[0] + "\n" # [subject] header for stories
subcell += "* " + column[1] + "\n" + " - " + column[2] + "\n" + "\n" # [intent_name] + [utter_name]
3) The generated stories.md output will have all the direct intent-action pairings for your simple conversation flows. Likewise, you can apply this concept for generating domain.yml
Hope this helps!

Layout for importing .csv intent file for IBM watson chatbot

I am in the process of creating a chatbot and need to import a .csv file to act as the intents. My question is regarding the layout; I currently have a list of cities however when importing should my intent name be in row A next to the city name or in row B seperated with a "," before the city ?
Thanks.
Intents should be questions where there is a clear intent of what is being asked.
Saying "Dubai" doesn't mean anything except as a word meaning. Using city names for training in intents will not give you great results.
File format for Intents is listed here. It is question,intent format.
Example:
Tell me the current weather conditions.,weather_conditions
Is it raining?,weather_conditions
What's the temperature?,weather_conditions
Where is your nearest location?,find_location
Do you have a store in Raleigh?,find_location
Entites are non standard format of entitiy,value, synomns,...
Example:
weekday,Monday,Mon
weekday,Tuesday,Tue,Tues
weekday,Wednesday,Wed
weekday,Thursday,Thur,Thu,Thurs
weekday,Friday,Fri
weekday,Saturday,Sat
weekday,Sunday,Sun
More details for entities here.

Recognize undefined Entities in Watson Conversation

Please, I wanted to know if it is possible to catch different entities on Watson conversation without defining their values.
For example, I am working on a Mobile up for room booking in my company and I can't define all the room's names so I want that my Bot recognize the name just according to the used pattern for example
"Book #room for tomorrow"
and whatever I put in place of #room it takes it as a room name.
thank you
Its now available check out https://console.bluemix.net/docs/services/conversation/entities.html#pattern-entities
A pattern must be entered as a regular expression in the field.
For instance internationalPhone: ^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$, e.g., +44 1962 815000
EDIT: The solution below still works but right now the pattern entities as discussed by Dudi are more systematic solution. Leaving this here for legacy reasons.
Right now the regexp support inside Watson Conversation Service is probably the est bet.
For your particular example, you can use the following expression inside the dialog node condition:
input.text.matches('^[bB]ook[^\w]+(\w+).+ (tomorrow|today)$')
and inside that node you can add the following regexp to node context to extract the second word (or the word after "Book") to a variable:
"room" : "<? input.text.extract('^[bB]ook[^\\w]+(\\w+).+ (tomorrow|today)$',1) ?>"
(note that in context unlike in conditions you need to actually escape \ with another \)
This will match inputs such as "book bathroom for today" or "book r101 for tomorrow".
A good place where you can try your regexp expressions is https://regex101.com/

how to write mathematical equations and symbols in IBM Conversation

I have created a chat bot using Conversation Service of IBM Watson but I am not able to write mathematical equations and symbols in the intents, entities and dialog. Can anyone help me with this?
Mathematical symbols such as +,-,* or / are just characters and can be used in intent/entities examples. So you could create an intent #add with +, plus, add as an examples.
Then you can use predefined #sys-number entity to detect numbers (just turn it on in entities, system entities tab). You would then create a dialog node with a condition #add && #sys-number.length == 2 - to be sure there are two numbers in the user input - and in the Watson says, you could write expression such as:
<? #sys-number[0].numeric_value + #sys-number[1].numeric_value ?>
to get the result.