解析LuisResult以获取JSON字段

时间:2017-03-23 16:37:22

标签: c# json botframework luis

我使用LUIS了解微软的Bot框架。我试图制作一个能理解数学短语的简单数学机器人。当用户键入"什么是2加3"或类似的东西,LUIS明白这个人想要加两个和三个。结果是LuisResult看起来像这样:

{
  "query": "what is one plus three",
  "topScoringIntent": {
    "intent": "addition",
    "score": 0.999997139
  },
  "intents": [
    {
      "intent": "addition",
      "score": 0.999997139
    },
{
  "intent": "None",
  "score": 0.03979478
}
],
  "entities": [
    {
      "entity": "one",
      "type": "builtin.number",
      "startIndex": 8,
      "endIndex": 10,
      "resolution": {
        "value": "1"
    }
    },
    {
      "entity": "three",
      "type": "builtin.number",
      "startIndex": 17,
      "endIndex": 21,
      "resolution": {
        "value": "3"
      }
    }
  ]
}

我需要提取"值"实体列表中的字段。目前我只知道如何提取第一个实体"一个"通过做

string numberResult = "";
EntityRecommendation rec;
if(result.TryFindEntity("builtin.number", out rec))
{
     numberResult = rec.Entity;
     this.number = Int32.Parse(numberResult);
 }

有没有办法提取两个值字段" 1"和" 3"从这个?

1 个答案:

答案 0 :(得分:2)

LuisResult有一个list of all the detected Entities。您可以迭代它们而不是使用TryFindEntity方法。