C#LUIS Chatbot从LuisResult中提取所有意图

时间:2017-12-06 22:30:00

标签: c# json bots botframework luis

我有一个与LUIS连接的聊天机器人,我知道虽然对话框只会进入具有最高匹配意图的对话框,但是我仍然希望显示其余意图的分数,有没有办法要做到这一点? 我已经

[LuisModel("XXXX", "XXXX", Verbose = true)]

到目前为止,这就是我正在使用的内容:

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {

        string allIntents = "";



        //Loop throught all intents found in JSON
        foreach (var foundIntent in result.Intents)
        {
            allIntents += ("Intent: " + foundIntent.Intent + "\n\n" + "Score: " + foundIntent.Score + "\n\n");
        }
        await context.PostAsync(allIntents);
        context.Wait(this.MessageReceived);
    }

我的JSON就像

{
  "query": "hey there",
  "topScoringIntent": {
  "intent": "None",
  "score": 0.17292054
  },
  "intents": [
    {
      "intent": "None",
      "score": 0.17292054
    },
    {
      "intent": "intentSearch",
      "score": 0.122199811
    },
    {
      "intent": "fromIntent",
      "score": 0.0327471271
    },
    {
      "intent": "goWithIntent",
      "score": 0.010828237
    }
  ],
  "entities": []
}

然而,我的机器人只会返回无意图及其分数。有没有办法在对话框中返回所有意图?

编辑:答案以某种方式解决了一个新项目,我不知道为什么

1 个答案:

答案 0 :(得分:3)

你必须在你的LuisModelAttribute中将verbose标志设置为true,如下所示:

[LuisModel("e7a9c2d5-0b92-47d3-9d73-xxxxxxxxxxxx",
"4941fa348c49494db1e8e8xxxxxxxxxx", Verbose = true)]

这是获取所有意图的代码,您可以从

获得分数
    [LuisIntent("greeting")]
    public async Task Greeting(IDialogContext context, LuisResult result)
    {
        string allIntents = "";
        //Loop throught all intents found in JSON
        foreach (var foundIntent in result.Intents)
        {
            allIntents += ("Intent: " + foundIntent.Intent + "\n\n" + "Score: " + foundIntent.Score + "\n\n");
        }
        await context.PostAsync(allIntents);

        context.Wait(this.MessageReceived);
    }

使用此代码我得到了这个结果: enter image description here