简体   繁体   中英

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 ?>"
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM