亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取LUIS的查詢結果

獲取LUIS的查詢結果

C#
墨色風雨 2021-12-25 16:20:27
我已經創建了一個 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;

}


查看完整回答
反對 回復 2021-12-25
  • 1 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號