Reputation: 521
Is it possible to put an entity inside of a regex?
for example, giving that the entity "@pizza-toppings"
contains toppings:
"topping": "<? input.text.extract('(?i)\.+(@pizza-toppings)(?-i)', 1) ?>"
So, if @pizza-toppings
matches "onion", then "(?i)\.+(@pizza-toppings)(?-i)"
will be "(?i)\.+(onion)(?-i)"
. If it matches "cheese"
, then it will be "(?i)\.+(cheese)(?-i)"
and so on and so forth.
I've been trying to find a solution but so far I didn't find anything.
Upvotes: 1
Views: 695
Reputation: 17176
Without testing, after I noticed you were including the entity reference into the string. Try to do something like this:
"topping": "<? input.text.extract('(?i)\.+('+@pizza-toppings+')(?-i)', 1) ?>"
Upvotes: 2
Reputation: 227
In general when you use a pattern entity, this will match the pattern and add the entity with the hardcoded value from the entity definition. But if you want the value that was matched, you should do as the documentation suggests (https://console.bluemix.net/docs/services/conversation/entities.html#creating-entities) and add in the node response section a statement which creates a context variable and assigns the value of the pattern matched bit to that context variable:
{
"context" : {
"topping": "<? @pizza-toppings.literal ?>"
}
}
So if your pizza topping matches onion, your context variable topping will have the value "onion".
For example in this sample https://github.com/IBM/watson-assistant-app-connect there is a single entity @customerId which matches against a customer ID "[a-zA-Z\d]{15,18}".
In the dialog node AppConnect in "Then check for:" it checks for the @customerId entity. In "Then set context:" it sets $id to "" and this is where the value that matched for @customerId is set in the context variable $id.
Upvotes: 1