简体   繁体   中英

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. 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. However, Dialogflow recognizes "123 456 789 123" as intended which appears to be a very random behavior to me.

How can I make Dialogflow recognize any 12 digits as a 12-digit number?

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

  • 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. 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. And it would also accept letters in the first place

  • make the intent match up to 12 single digits. 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.

I've had a similar issue when I had to recognize a product code that consisted of 9 characters, either letters or numbers. In my approach I used the @sys.any parameter for the input. 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. 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. 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." Easy peasy :-p

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