1

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.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
lat94
  • 511
  • 1
  • 5
  • 18
  • Do you mean inside a regex that is evaluated in a dialog node? Could you add more details of what you want to accomplish? – data_henrik Nov 13 '18 at 12:49
  • Yes, I am inside a dialog node.The string `"toppings"` will be assigned with the return of the extract – lat94 Nov 13 '18 at 13:29
  • And it is **only 1** topping. Not toppings. I edited the question and changed it. – lat94 Nov 13 '18 at 13:32
  • So, if it matches a topping inside the entity `@pizza-toppings`, the value will be assigned to the string `"topping"`. – lat94 Nov 13 '18 at 13:37
  • Why do you want to do it? Maybe there is a different way... Could you first try to compose the pattern string, then use a variable with the string as parameter? – data_henrik Nov 13 '18 at 13:52
  • Yeah, I've managed to do it in a similar way using context variables. But using the entity would be really better. I will wait a while and reseach a little bit more and see if it's really not possible to do it in the way that I'm willing to, then post my results here. – lat94 Nov 13 '18 at 14:11

2 Answers2

2

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) ?>"
data_henrik
  • 16,724
  • 2
  • 28
  • 49
  • There are something missing in the snippet you sent to me. over here: `('+@pizza-toppings'+')`. I tried to change it properly but didnt not run succesfully. – lat94 Nov 13 '18 at 19:43
1

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.

DSeager
  • 217
  • 1
  • 4
  • Yeah, that would solve it. This is how I managed to get it done. But, I think that the solution I'm asking for is not available yet, right? t – lat94 Nov 13 '18 at 20:09