private void intentGreet(luisResponse luisResponse) { try { if (luisResponse.entities.Count > 0) { var hasName = false; foreach (var ent in luisResponse.entities) { if (ent.type == "Name") { hasName = true; if (peopleList[ent.entity.ToUpper()] == "WILL") { callLights("HI"); } else { callLights("NOT_" + peopleList[ent.entity.ToUpper()]); } } } } else { callLights("HI"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void intentLocate(luisResponse luisResponse) { try { if (luisResponse.entities.Count > 0) { var hasName = false; foreach (var ent in luisResponse.entities) { if (ent.type == "Name") { hasName = true; switch (peopleList[ent.entity.ToUpper()]) { case "WILL": callLights("HERE"); break; case "HOPPER": callLights("UPSIDE_DOWN"); break; case "ELEVEN": callLights("KICKING_ASS"); break; } } } } else { callLights("HERE"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private async void buildResponse(string userQuery) { try { var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key); queryString["q"] = userQuery; var endpointUri = luisUri + AppId + "?" + queryString; var response = await client.GetAsync(endpointUri); var jsonStream = await response.Content.ReadAsStreamAsync(); var ser = new DataContractJsonSerializer(typeof(luisResponse)); luisResponse luisResponse = ser.ReadObject(jsonStream) as luisResponse; jsonStream.Close(); switch (luisResponse.topScoringIntent.intent) { case "Locate": intentLocate(luisResponse); break; case "greet": intentGreet(luisResponse); break; case "None": intentNone(luisResponse); break; } //call child methods for intent branching } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void intentNone(luisResponse luisResponse) { callLights("RUN"); }