【问题标题】:How can I get the value of an entity from LuisResult object? (LUIS with Bot Framework .NET)如何从 LuisResult 对象中获取实体的值? (带有 Bot Framework .NET 的 LUIS)
【发布时间】:2018-11-15 00:57:51
【问题描述】:

以下是我调用 LUIS api 端点时的 JSON。

  {
        "query": "How do I install citrix?",
        "topScoringIntent": {
            "intent": "Setup Instructions",
            "score": 0.9999997
        },
        "intents": [
            {
                "intent": "Setup Instructions",
                "score": 0.9999997
            },
            {
                "intent": "OS Availability",
                "score": 0.0000021111066
            },
            {
                "intent": "Service Guide",
                "score": 8.18181149e-7
            },
            {
                "intent": "Service Description",
                "score": 5.55555232e-7
            },
            {
                "intent": "None",
                "score": 9e-9
            },
            {
                "intent": "Greeting",
                "score": 1.41666667e-9
            },
            {
                "intent": "Compassion",
                "score": 8.1e-10
            },
            {
                "intent": "Images",
                "score": 8.1e-10
            }
        ],
        "entities": [
            {
                "entity": "citrix",
                "type": "Service",
                "startIndex": 17,
                "endIndex": 22,
                "resolution": {
                    "values": [
                        "Citrix Receiver"
                    ]
                },
                "role": ""
            }
        ],
        "sentimentAnalysis": {
            "label": "positive",
            "score": 0.7695234
        }
    }

我正在尝试从下面获取字符串“Citrix Receiver”。

下面是我的代码

LuisResult result
var strEntity = result.Entities[0].Resolution.Values[0]

但我无法将索引应用于ICollection<object> 类型的表达式。看起来resolution 似乎被定义为字典,并且在研究后,我看到其他带有resolution 的JSON 主体具有多个键值对。是否有可能主体已更改但 MS Bot Builder 框架中的 Luis 扩展没有?

谢谢。

【问题讨论】:

  • 为了解决同样的问题:从"resolution": { "values": ["xxxxxxxxx"]}中提取数据,我使用的是var resval = result.Entities[0].Resolution.Values.Select(s => ((List)s)[0]).FirstOrDefault();

标签: c# .net botframework bots azure-language-understanding


【解决方案1】:

我之前有同样的问题来获取已解决实体的列表,我使用以下代码解决了它:

result.Entities.First().Resolution.Values.Select(s => JArray.Parse(s.ToString()).Distinct().ToList();

所以对你来说,它可能会更短一些:

result.Entities.First().Resolution.Values.First(s => JArray.Parse(s.ToString());

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多