IBM Watson Assistant: Chatbot Entity Confusion over regular expression

戏子无情 提交于 2019-12-13 03:13:14

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/52383292/ibm-watson-assistant-chatbot-entity-confusion-over-regular-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!