如何使Watson捕获数字序列(input.text.extract) [英] How to make Watson capture a sequence of numbers (input.text.extract)

查看:71
本文介绍了如何使Watson捕获数字序列(input.text.extract)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的示例中,我要求提供一个个人文件编号,该编号有11位数字,并且如果用户正确键入11个数字,我需要沃森继续进行对话,如果没有,沃森将通知一位我定义的讯息.该怎么做?

In my example, I ask for a personal documentation number, the number has 11 digits, and I need that in case the user type the 11 numbers correctly the watson continue with the conversation, and if not, the watson will inform a message defined by me. How to do this?

我的案子: 沃森说: 好吧,我会检查.您的协议号是什么?

My case: Watson says: All right, I'll check. What is your protocol number?

我说: 例如:35158811233

I says: Ex: 35158811233

沃森说: 您要结束服务吗?

Watson says: Would you like to finish the service?

沃森(Watson)不重新确认电话号码,我的对话结束了.请问有人知道如何解决这个问题吗?

Watson dont reconigze the number and my conversation flows to the finish. Does someone know how to solve this, please?

沃森能理解:

  "intents": [
    {
      "intent": "goodbye",
      "confidence": 0.24506947419646477
    }
  ],
  "entities": [],
  "input": {
    "text": "35158811233"
  },
  "output": {
    "log_messages": [],
    "text": [
      "Would you like to finish the service? \n \n <button id=\"button-yes\" onclick=\"yesBye();\">Yes</button> <button id=\"button-no\" onclick=\"noBye();\">No</button>"
    ],

推荐答案

要与Watson对话服务匹配号码,您可以使用可以在实体标签中打开的实体sys-number-但这将匹配所有数字而你是一个特定的人.

To match numbers with Watson conversation service you can either use the entity sys-number that can be turned on in the entities tab - but this will match all the numbers and yours is a specific one.

对于此用例,您可以添加对文本用户输入的其他检查. Watson对话支持正则表达式检查.如果您通过以下方式创建对话框节点的条件:input.text.matches('^[^\d]*[\d]{11}[^\d]*$'),则仅当input.text(它是用户提交的确切文本字符串的访问者)与定义的正则表达式(regexp)匹配时,此节点才会匹配作为^[^\d]*[\d]{11}[^\d]*$.

For this use case you can add additional check of the textual user input. The Watson conversation supports regexps checks. If you create a condition of dialog node in this way: input.text.matches('^[^\d]*[\d]{11}[^\d]*$') then this node will match only if the input.text which is an accessor to the exact text String that was submitted by the user will match the regular expression (regexp) defined as ^[^\d]*[\d]{11}[^\d]*$.

仅当输入中有11位数字且其他位置没有其他数字时,此特定表达式才匹配,但该数字前后均允许有其他文本.

This particular expression will match only if there is 11 digits number in the input and no other digits elsewhere, but additional text in front and after the number is allowed.

现在要将这个数字捕获到变量中,您可以将以下内容添加到与该数字匹配的对话框节点的context中:

Now to capture this number to a variable you can add the following to the context of the dialog node that is matching this number:

"context": {
    "number": "<?input.text.extract('^[^\\d]*[\\d]{11}[^\\d]*$',0)?>"
}

请注意,由于context字段的JSON性质,上下文中对\\d的转义有所不同.

Note that there is different escaping of \\don the context due to JSON nature of the context field.

然后,您可以在对话框节点的输出文本中编写类似"Ok, number $number was matched."的内容,以在聊天窗口中显示该号码.

In the output text of a dialog node you can then write something like "Ok, number $number was matched." to display the number in the chat window.

另一件事-包含正则表达式信息的好地方,您还可以在其中尝试各种类型的正则表达式,并且它们匹配的是 Regex 101网页.

One more thing - great place with info about regexps where you can also try various type of regular expressions and what they match is Regex 101 web page.

这篇关于如何使Watson捕获数字序列(input.text.extract)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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