如何从 LuisResult 对象获取实体的值? (带有 Bot Framework .NET 的 LUIS)
How can I get the value of an entity from LuisResult object? (LUIS with Bot Framework .NET)
下面是我调用 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
被定义为一个字典,经过研究,我已经看到其他 JSON 主体 resolution
具有多个键值对。是否可能正文已更改但 MS Bot Builder Framework 中的 Luis 扩展没有?
谢谢。
我之前在获取已解决实体列表时遇到了同样的问题,我使用以下代码解决了它:
result.Entities.First().Resolution.Values.Select(s => JArray.Parse(s.ToString()).Distinct().ToList();
所以对你来说它可能有点短,比如:
result.Entities.First().Resolution.Values.First(s => JArray.Parse(s.ToString());
下面是我调用 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
被定义为一个字典,经过研究,我已经看到其他 JSON 主体 resolution
具有多个键值对。是否可能正文已更改但 MS Bot Builder Framework 中的 Luis 扩展没有?
谢谢。
我之前在获取已解决实体列表时遇到了同样的问题,我使用以下代码解决了它:
result.Entities.First().Resolution.Values.Select(s => JArray.Parse(s.ToString()).Distinct().ToList();
所以对你来说它可能有点短,比如:
result.Entities.First().Resolution.Values.First(s => JArray.Parse(s.ToString());