Create Entities and training phrases for values in functions for google action

匆匆过客 提交于 2019-12-11 13:04:41

问题


I have created a trivia game using the SDK, it takes user input and then compares it to a value in my DB to see if its correct.

At the moment, I am just passing a raw input variable through my conversation, this means that it regularly fails when it mishears the user since the exact string which was picked up is rarely == to the value in the DB.

Specifically I would like it to only pick up numbers, and for example realise that it must extract '10' , from a speech input of 'my answer is 10'.

  {
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "welcome"
      },
      "intent": {
        "name": "actions.intent.MAIN"
      }
    },
    {
      "description": "response",
      "name": "Raw input",
      "fulfillment": {
        "conversationName": "rawInput"
      },
      "intent": {
        "name": "raw.input",
        "parameters": [{
          "name": "number",
          "type": "org.schema.type.Number"
        }],
        "trigger": {
          "queryPatterns":[
            "$org.schema.type.Number:number is the answer",
            "$org.schema.type.Number:number",
            "My answer is $org.schema.type.Number:number"
          ]
        }
      }
    }
  ],
  "conversations": {
    "welcome": {
      "name": "welcome",
      "url": "https://us-central1-triviagame",
      "fulfillmentApiVersion": 2
    },
    "rawInput": {
      "name": "rawInput",
      "url": "https://us-central1-triviagame",
      "fulfillmentApiVersion": 2
    }
  }
}

app.intent('actions.intent.MAIN', (conv) => {
  conv.data.answers = answersArr;
  conv.data.questions = questionsArr;
  conv.data.counter = answersArr.length;
  var thisQuestion = conv.data.questions;
  conv.ask((conv.data.answers)[0]));
});

app.intent('raw.input', (conv, input) => {

if(input == ((conv.data.answers)[0])){


       conv.ask(nextQuestion());
}


app.intent('actions.intent.TEXT', (conv,input) => {
 //verifying if input and db value are equal
// at the moment input is equal to 'my number is 10' (for example) instead of '10'

//therefore the string verification never works
conv.ask(nextQuestion());

});

In a previous project i used the dialogflow UI and I used this @system.entities number parameter along with creating some training phrases so it understands different speech patterns.

This input parameter I am passing through my conv , is only a raw string where I'd like it to be filtered using some sort of entity schema.

How do I create the same effect of training phrases/entities using the JSON file?


回答1:


You can't do this using just the Action SDK. You need a Natural Language Processing system (such as Dialogflow) to handle this as well. The Action SDK, by itself, will do speech-to-text, and will use the actions.json configuration to help shape how to interpret the text. But it will only return the entire text from the user - it will not try to determine how it might match an Intent, nor what parameters may exist in it.

To do that, you need an NLP/NLU system. You don't need to use Dialogflow, but you will need something that does the parsing. Trying to do it with simple pattern matching or regular expressions will lead to nightmares - find a good system to do it.

If you want to stick to things you can edit yourself, Dialogflow does allow you to download its configuration files (they're just JSON), edit them, and update or replace the configuration through the UI or an API.



来源:https://stackoverflow.com/questions/52539238/create-entities-and-training-phrases-for-values-in-functions-for-google-action

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