为 google 操作的函数中的值创建实体和训练短语

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

我使用 SDK 创建了一个问答游戏,它接受用户输入,然后将其与我的数据库中的值进行比较,看它是否正确。

目前,我只是通过我的对话传递一个原始输入变量,这意味着当它误听用户时它经常会失败,因为拾取的确切字符串很少 == 到数据库中的值.

具体来说,我希望它只提取数字,例如意识到它必须从 'my answer is 10'.

的语音输入中提取 '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());

});

在之前的项目中,我使用了 dialogflow UI 并使用了这个 @system.entities 数字参数以及创建了一些训练短语,以便它理解不同的语音模式。

我通过 conv 传递的这个 input 参数只是一个原始字符串,我希望使用某种实体模式对其进行过滤。

如何使用 JSON 文件创建与训练 phrases/entities 相同的效果?

您无法仅使用 Action SDK 执行此操作。您还需要一个自然语言处理系统(例如 Dialogflow)来处理这个问题。 Action SDK 本身将进行语音到文本的转换,并将使用 actions.json 配置来帮助塑造如何解释文本。但它只会 return 来自用户的整个文本 - 它不会尝试确定它如何匹配 Intent,也不会确定其中可能存在哪些参数。

为此,您需要一个 NLP/NLU 系统。您不需要使用 Dialogflow,但您将需要进行解析的东西。尝试用简单的模式匹配或正则表达式来做会导致噩梦 - 找一个好的系统来做。

如果您想坚持自己可以编辑的内容,Dialogflow 允许您下载其配置文件(它们只是 JSON)、编辑它们,并通过 UI 或 API.