Detect a number in entity in IBM Watson Conversation - ibm-cloud

I need the user to input his flight number in order to fetch its details for him.
Is there any way to detect and store the flight number (3-4 digits + words) that he entered?
I know that I can create an entity in order to store some parts of the user inputs, but it seems like I have to hard-code values which I want to retrieve, which is not practical.
So, is there any option to make watson automatically detect a part of user input (not limited to numbers).

In your condition section you can put in the following.
input.text.matches('.*?[0-9]{3,4}.*?')
For your output area, go to advanced mode and do the following.
{
"output": {
"text": "You typed a 3-4 digit number. I stored it in Context variable 'found'"
},
"context": {
"found": "<? input.text ?>"
}
}
You can then query the context variable found in your code to do more complex actions on it.
Conversation has been updated since this answer. You can now use input.text.extract() instead of just input.text.
Like so:
"found": "<? input.text.extract('.*?([0-9]{3,4}).*?',1) ?>"

Related

Getting the user's name without directly asking for it (Watson Assistant)

I'm creating a chatbot for fun and want to implement something to collect the user's name, but only if he says something like "my name is ..." or close to that; the intention of giving the name would come from the user, the bot won't ask for it, maybe only suggest it. Kind of like in Google Assistant, I think. So, it could be given at any time the user wants.
My idea is:
1st create an intent with different ways the user would tell his name to the bot (like in the example above).
2nd use slots and, if the intent is detected, save it as a variable. So far, I've managed.
3rd is the part that I'm stuck in, since it's only an idea and I don't know how I'd do it. Before saving the whole text as a variable, I'd like to delete the part that's included in the intent (my name is) and save only the rest in the variable. So, for example, the user says "my name is XXX"; the command deletes the "my name is" part and saves only "XXX" in the $name intent.
I don't know if this'd be possible, since I don't know coding. I used some special syntax before, like to capitalize the first letter of some other variable, but I don't really know how to use the JSON editor.
Is my idea viable? I don't know how I'd delete the intent corresponding portion and save only the remaining part as the intent. Dunno what would be the command for that, nor where I'd write it.
You can suggest something else if you have an idea.
Last thing, I'm created the skill in portuguese, so there's no access to the #sys-person entity.
Thanks for reading.
I use portuguese skills and face the same issue. I see two solutions, althougt they are not perfect:
Using intents:
When the intent is identified, the bot asks the name again, telling the user that he should only say his name, e.g without "my name is", then store the whole input on a context variable, using:
<? input.text ?>
For embedding such logic inside slots, you probaly will need to use digressions.
But, this is boring to the user.
Using entities:
Entities identification carries along they start and end position in the input text, but intents not. With this, is possible to slice the input, cutting the entity:
<? input.text.substring(entities.name.location[1], input.text.length()) ?>
Entites would be "My name is", "People call me", "I'm called", "I'm baptized", "I was baptized".
So, "Hello, my name is Gustavo", would be cut after "my name is" ending, resulting in "Gustavo". Additional input in the beggining is ignored, but problems arrise with additional input after the name. Also, you need to define more "my name is" like entities, likely all possibilities, than would need if using intents, cause even with fuzzy matching, entities identification doesn't take in account synonymus and similar meaning words.
https://cloud.ibm.com/docs/assistant?topic=assistant-dialog-methods#dialog-methods-strings-substring
https://cloud.ibm.com/docs/assistant?topic=assistant-expression-language#expression-language-access-entity

Google DLP - Displaying the Region using InfoTypes.list()

After integrating the Google DLP API, the ListInfoTypes() currently returns the name, description, supported types of the infotypes present in the infotypes reference. Is it possible to also obtain the region for the infotypes like "Australia" or "Argentina" as a seperate field?
Currently this is my output:
"name": "AUSTRALIA_MEDICARE_NUMBER",
"displayName": "Australia medicare number",
"supportedBy": [
"INSPECT"
],
"description": "A 9-digit Australian Medicare account
I need the Region as well for example Region: "Australia" for every other infotypes.
I also got around to see locations.infoTypes.list() but I'm not sure which location I should enter in the filter to get any value.
Looking at the REST API there doesn't appear to be identifying data that can be formally used to determine the region. If we look at the InfoTypeDescription JSON structure found here:
https://cloud.google.com/dlp/docs/reference/rest/v2/ListInfoTypesResponse#InfoTypeDescription
we see that "name" is described as an "internal name of the InfoType". I wondered if we could depend on a structure of the string ... perhaps (.)*_.* as a regular expression grouping. While this might work, it shouldn't be relied upon without investigation of more samples and the docs don't describe the structure.
If you really need a solution, my recommendation would be to dump ALL the InfoTypes and then manually group the "name" fields into the regions of interest to you. You could then store this as CSV or JSON and have a reference piece of data that you could use in your app and regenerate as needed.
It's a great feature request I'll forward to the team. In the short term you can hack the name as ones that are regional will say they are in their name.

Can you list multiple features within the same Schema.org "LocationFeatureSpecification"?

I am working on Schema.org Resort schema for a ton of resorts on a travel website and am trying to find the most efficient ways of filling out the schema with regards to amenities.
The current code looks something like this:
"amenityFeature": [
{
"#type":"http://schema.org/LocationFeatureSpecification",
"name":"Spa",
"value":"true"
},
{
"#type":"http://schema.org/LocationFeatureSpecification",
"name":"Internet Access",
"value":"true"
},
{
"#type":"http://schema.org/LocationFeatureSpecification",
"name":"Tennis Courts",
"value":"true"
}
]
My question is, can I write it like this instead to shorten lines of code:
{
"#type":"http://schema.org/LocationFeatureSpecification",
"name":[
"Spa", "Internet Access", "Tennis Courts"
],
"value":"true"
}
When I test it in Google’s Structured Data Testing Tool, it doesn’t give any errors. Here is what it looks like in the SDTT when I write it the short way:
And here is what it looks like if I do it the first/long way:
If I do it the short way, I want to make sure all those items are getting listed as amenities and not just different names for the same amenity. Otherwise, I'll go the long route.
No, each LocationFeatureSpecification represents one feature:
Specifies a location feature by providing a structured value representing a feature of an accommodation as a property-value pair of varying degrees of formality.
Your second snippet would represent one feature with multiple names.

IBM Chatbot Assistant: Handling Multiple Entities

I have an entity called #spare_part and this entity has 4 values with the following example synonyms each:
both with synonyms filter, oil level indicator
not_defined with a synonym spare part
only_gear with synonyms valve, seal
whole_gear_box with a synonym complete set of gearbox
I want to be able to handle multiple entities given in the same input and address them later on, if needed. With this purpose I have coded the following in JSON editor:
{
"context": {
"sparepartrequest": "#spare_part.values"
},
"output": {
"generic": [
{
"values": [
{
"text": "You want an offer for the following parts: <?
$sparepartrequest.join(', ') ?>."
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
}
}
I have created a context variable called sparepartrequest as can be seen from the code lines above. For instance when the user says "I want an offer for a filter and a seal", the output of the bot is the following sentence:
You want an offer for the following parts: both, only_gear.
I don´t want the bot to prompt back the names of the values of the entity #spare_part, I rather want it to store the exact input of the user, for our case which would be filter and seal. So if the bot worked as I wanted it to, the output would look like the following:
You want an offer for the following parts: filter, valve.
Again, I believe that this can be handled with JSON Editor. Thank you !
Use two context variables. sparepartrequest as already done and sparepartrequest_literals as follows:
"sparepartrequest_literals":"<? entities['spare_part'].![literal].join(', ') ?>".
Then, in your text response call it by $sparepartrequest_literals to print the mentioned parts or use $sparepartrequest to refer to the detected values.

IBM Watson Assistant: Chatbot Entity Confusion over regular expression

I have an entity called "#material_number" in which two values are stored.
First value is "material_number1" with the pattern (\d{3}).(\d{3})
The second value is "material_number2" with the pattern (\d{3}).(\d{3}).(\d{3})
When the user enters a material number, I store the value with a context variable called "$materialnumber" and I set the value of this variable to "?#material_number.literal?". And at the end the bot responds "Oh okay, the material number is $materialnumber."
The problem is that when the user enters a material number like "123.123.123", the bot thinks that the material number is "123.123". Basically it neglects the last three digits and prompts back "Oh okay, the material number is 123.123".
What can I do in order to fix this confusion?
I quickly tested this and there are two problems. First, the dot (. is a special wildcard and needs to be escaped. Second, Watson Assistant does not support the full regex options and seems to match both numbers when typing in the longer number.
You can simply escape using a \ and change your definition or use mine:
num1: (\d{3}\.){1}\d{3}
num2: (\d{3}\.){2}\d{3}
Because of the trouble with the regex evaluation I solved that in the expression itself. Watson Assistant holds the longer match as second value (if matched). The following expression looks if the long number, material_number2, has been matched, then extracts the correct value for it. It assumes that the shorter (incorrect) match is stored first.
{
"context": {
"materialnumber": "<? #matrial_number:matnum2 ? entities.material_number[1].literal : entities.material_number[0].literal ?>"
}
}