【问题标题】:Parsing LuisResult to get JSON fields解析 LuisResult 以获取 JSON 字段
【发布时间】:2017-03-23 16:37:22
【问题描述】:

我正在学习使用 LUIS 的 Microsoft Bot Framework。我正在尝试制作一个能够理解数学短语的简单数学机器人。当用户键入“什么是二加三”或类似内容时,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”?

【问题讨论】:

    标签: c# json botframework azure-language-understanding


    【解决方案1】:

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

    【讨论】:

    • 我对 c# 还是比较陌生,我将如何遍历实体的 IList 以获取值? @EzequielJadib
    • 你可以在 C# 中使用 for 循环进行迭代。
    • 抱歉,我了解如何迭代,我仍然不确定如何访问实体中的“值”字段。这有点像 var valuesEntity = result.Entities;诠释 i = 0; foreach(valuesEntity 中的变量名称){ await context.PostAsync($"{valuesEntity[i]}");我++; }
    • 我没记错 Entity 属性将包含实体的值。
    • 我正在寻找“values”字段而不是实体“entity”的值:“three”,“type”:“builtin.number”,“startIndex”:17,“endIndex ": 21, "resolution": { "value": "3" } json实体中的最后一个字段
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    • 2021-12-29
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多