我已經創建了一個 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 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消