我已经创建了一个 LUIS 帐户并完成了所有需要的操作。我编写了以下代码并从 LUIS 得到了结果。我需要知道如何将我的查询结果保存到一个变量中,我想用它来搜索数据库或网络。下面是代码..static async void MakeRequest(string qz) { var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); var luisAppId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; var endpointKey = "XXXXXXXXXXXX"; client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", endpointKey); // The "q" parameter contains the utterance to send to LUIS queryString["q"] = qz; // These optional request parameters are set to their default values queryString["timezoneOffset"] = "0"; queryString["verbose"] = "false"; queryString["spellCheck"] = "false"; queryString["staging"] = "false"; var endpointUri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" + luisAppId + "?" + queryString; var response = await client.GetAsync(endpointUri.); var strResponseContent = await response.Content.ReadAsStringAsync(); // Display the JSON result from LUIS Console.WriteLine(strResponseContent.ToString()); }还有这里是查询结果。{ "query": "the best resturant in Paris", "topScoringIntent": { "intent": "city", "score": 0.436210483 }, "entities": [ { "entity": "paris", "type": "city", "startIndex": 22, "endIndex": 26, "score": 0.7153605 } ]}现在我想保存这个"entity": "paris","type": "city",到一个变量。请指导我,因为我对 MS LUIS 完全陌生。例子:string result = "paris" /// 应从 luis 查询中获取该值string type = "city" /// 应该从 luis 查询中获取哪个值
1 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
一种选择是将Newtonsoft.Json NuGet 包引用到您的项目。
然后你可以创建两个类(随意更改名称)
public class LuisExtractionLuisResult
{
public List<LuisEntity> entities { get; set; }
}
public class LuisEntity
{
public string entity { get; set; }
public string type { get; set; }
}
那么一个使用示例是
var target = JsonConvert.DeserializeObject<LuisExtractionLuisResult>(strResponseContent);
然后通过以下方式检索请求的值:
string result = target.entities[0].entity;
string type = target.entities[0].type;
还有一个问题,如果在查询中我们有多个实体。如何获得呢?
foreach(LuisEntity oneEntity in target.entities)
{
string result oneEntity.entity;
string type = oneEntity.type;
}
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消