我在Dialogflow上创建了一个非常简单的代理,它只包含两个额外的意图以及 Default Welcome IntentDefault Fallback Intent . 第一个意图叫做 Car_size ,它只包含训练短语 Do you know that I have a big car? . 第二个意图叫做 Car_colour ,它只包含训练短语 I have a blue car . 我还定义了两个实体 .

第一个被称为 @size ,它包括诸如 bigsmall 等词,第二个被称为 @colour ,它包括诸如 blueblackgreen 等词 . 因此,在 Car_size 意图中,单词 big 被识别为参数 @size 实体和 Car_colour 意图中的单词 blue 被标识为 @colour 实体的参数 . 我已根据需要设置了这两个参数,以便通过webhook在后端获取正确的信息 .

从Dialogflow接收POST请求(webhook)的php脚本如下:

<?php
$dbServername = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'Questions';
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];

if($method == 'POST'){
    $requestBody = file_get_contents('php://input');
    $json = json_decode($requestBody, TRUE);    
    $action = $json["result"]["action"];

    $sql = "SELECT * FROM cars WHERE id = $action;";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);
    if ($resultCheck > 0) {
       while ($row = mysqli_fetch_assoc($result)) {

            $answer = $row["answer"];

       }
    }
    else {
        $speech = "Sorry, no answer for this.";
    }

    $response = new \stdClass();
    $response->speech = $answer;
    $response->displayText = $answer;
    $response->source = "agent";
    echo json_encode($response);
}
else
{
    echo "Method not allowed";
}
?>

在这个简单的演示中使用webhook可能没用,但我的最终目标明显大于此,并且使用webhook连接到数据库对此至关重要 .

My problem is the following. When I say to the agent I have a big car then this triggers the Car_colour intent instead of the Car_size intent. Evidently, the phrase I have a big car is way closer syntactically to the I have a blue car training phrase of the Car_colour intent than to the Do you know that I have a big car? training phrase of the Car_size intent. However, I thought that exactly because I defined the distinct entities @size and @colour and set them as required parameters in both the above intents then this would give priority to words like big and blue for the respective intents when they are trained and then triggered. Therefore, I thought that the Dialogflow ML training and algorithm which triggers the intents would pay firstly attention to these words (big, blue) to decide which intent to trigger and then to the overall syntax and form of the training phrases of each intent.

Therefore, my question is the following: Do parameters and entities play any role in the ML training of the phrases of intents and therefore in which intent is triggered or they only exist to provide to the "backend" (after the intents are triggered independently of them) some specific information about the question of the user?