简体   繁体   English

Dialogflow-如何在数字识别中处理空格

[英]Dialogflow - How to handle blanks in number recognition

In my Dialogflow, I am using entity @sys.number to recognize a 12-digit number spoken in by the user. 在我的Dialogflow中,我使用实体@ sys.number来识别用户说出的12位数字。 Depending on how the user spells the number, it is not recognized as a single 12-digit number but sometimes as two numbers, either 3 and 9, 6 and 6 or whatsoever. 根据用户的拼写方式,它不会被识别为单个12位数字,但有时会被识别为两个数字,分别是3、9、6和6或任何数字。 However, Dialogflow recognizes "123 456 789 123" as intended which appears to be a very random behavior to me. 但是,Dialogflow可以按预期识别“ 123 456 789 123”,这对我来说似乎是非常随机的行为。

How can I make Dialogflow recognize any 12 digits as a 12-digit number? 如何让Dialogflow将任意12位数字识别为12位数字?

What I have tried so far: 到目前为止我尝试过的是:

  • make the required parameter "number" a list, but this makes numbers skip zeros, so that "000111" will be recognized just as "111", which is not intended 将所需的参数“ number”设置为列表,但是这会使数字跳过零,因此“ 000111”将被识别为“ 111”,这不是故意的

  • make the intent match any number and after that @sys.any, which can be any string and try to concatenate this with the beginning number. 使意图匹配任何数字,然后在@ sys.any之后(可以是任何字符串),并尝试将其与起始数字连接。 Does not really work as I would have to provide any given possibility to split up any 12-digit number into a leading number of length 1 to 12 and then any combination of digits and numbers. 确实不起作用,因为我必须提供任何给定的可能性,以将任何12位数字拆分为长度为1到12的前导数字,然后再拆分数字和数字的任何组合。 And it would also accept letters in the first place 它也将首先接受字母

  • make the intent match up to 12 single digits. 使意图匹配最多12个数字。 This is problematic as it does not provide any information if these digits are in direct succession. 这是有问题的,因为如果这些数字是直接连续的,它将不提供任何信息。 Also, it is very tedious to provide enough training data for this to be recognized. 另外,提供足够的训练数据以使其被识别是非常繁琐的。

Google adds white spaces for each pause that a user makes when they input their digit, this is why you get the random blanks in your number sometimes. 当用户输入数字时,Google会在用户输入的每个停顿处添加空格,这就是为什么有时会在数字中出现随机空格的原因。

I've had a similar issue when I had to recognize a product code that consisted of 9 characters, either letters or numbers. 当我不得不识别由9个字符(字母或数字)组成的产品代码时,我遇到了类似的问题。 In my approach I used the @sys.any parameter for the input. 在我的方法中,我使用@ sys.any参数作为输入。 Once a user inputted a string, I removed all the whitespaces from the input so that I would get the sentence in one piece. 一旦用户输入了字符串,我就从输入中删除了所有空格,以便将句子分成一个整体。 After that I used a regex to extract the codes. 之后,我使用了正则表达式来提取代码。

  const response = conv.parameters.input;
  // remove whitespaces
  const textWithoutWhitespaces = response.replace(/\s/g,"");
  // Look into the string for a 12 digit number
  const regExp = new RegExp(/\d{12}/g);
  const result = regExp.test(textWithoutWhitespaces);

  if(result === true) {
    // continue
  }
  else { 
   // error
  };

If an input wasn't found, I would conv.ask() and ask the user to put it in again. 如果找不到输入,我将conv.ask()并要求用户再次输入。 Otherwise I would continue with the code. 否则,我将继续代码。

Does it make sense to have your utterance end with the number? 以数字结束您的发言是否有意义?

If so I might try making sure to place the number at the end and us @sys.any to catch whatever it is they say. 如果是这样,我可能会尝试确保将数字放在末尾,然后我们使用@ sys.any来捕捉他们所说的内容。 At that point concatenating all of the numbers together might work, though you'd obviously have to handle situations where they said something that wasn't a valid number. 到那时,将所有数字连接在一起可能是可行的,尽管您显然必须处理它们说的不是有效数字的情况。

That or make the user say "One hundred and twenty three billion, four hundred and fifty six million, seven hundred and eighty nine thousand, six hundred and sixty six." 或使用户说“ 123亿,456.65亿,79.89万,666.6”。 Easy peasy :-p 简单容易:-p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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