IBM Watson Assistant:Chatbot实体对正则表达式的混淆 [英] IBM Watson Assistant: Chatbot Entity Confusion over regular expression

查看:89
本文介绍了IBM Watson Assistant:Chatbot实体对正则表达式的混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 @material_number 的实体,其中存储了两个值。

I have an entity called "@material_number" in which two values are stored.

第一个值为 material_number1 ,其格式为(\d {3})。(\d {3} )

First value is "material_number1" with the pattern (\d{3}).(\d{3})

第二个值为 material_number2 ,其格式为(\d {3})。( \d {3})。(\d {3})

The second value is "material_number2" with the pattern (\d{3}).(\d{3}).(\d{3})

当用户输入物料编号时,我会在上下文中存储值变量 $ materialnumber ,然后将此变量的值设置为 ?@ material_number.literal?。最后,机器人会回答 好吧,物料号是$ materialnumber。

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."

问题是当用户输入一个像 123.123.123 这样的材料编号,机器人会认为该材料编号是 123.123 。基本上,它忽略了后三位数字,并提示输入 好吧,物料号是123.123

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?

推荐答案

我对此进行了快速测试,并且存在两个问题。首先,点(是一个特殊的通配符,需要转义。其次,Watson Assistant不支持完整的正则表达式选项,并且在键入更长的数字。

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}

由于正则表达式评估的麻烦我在表达式本身中解决了,Watson Assistant将较长的匹配项保留为第二个值(如果已匹配),下面的表达式将查找是否已匹配长数material_number2,然后为其提取正确的值

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

这篇关于IBM Watson Assistant:Chatbot实体对正则表达式的混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆