/// <summary> /// Call LUIS to submit a dictation result. /// </summary> public IEnumerator SubmitRequestToLuis(string dictationResult) { WWWForm webForm = new WWWForm(); string queryString; queryString = string.Concat(Uri.EscapeDataString(dictationResult)); using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString)) { unityWebRequest.downloadHandler = new DownloadHandlerBuffer(); yield return(unityWebRequest.SendWebRequest()); long responseCode = unityWebRequest.responseCode; try { using (Stream stream = GenerateStreamFromString(unityWebRequest.downloadHandler.text)) { StreamReader reader = new StreamReader(stream); AnalysedQuery analysedQuery = new AnalysedQuery(); analysedQuery = JsonUtility.FromJson <AnalysedQuery>(unityWebRequest.downloadHandler.text); //analyse the elements of the response AnalyseResponseElements(analysedQuery); } } catch (Exception exception) { Debug.Log("Luis Request Exception Message: " + exception.Message); } yield return(null); } }
private void AnalyseResponseElements(AnalysedQuery aQuery) { string topIntent = aQuery.topScoringIntent.intent; // Create a dictionary of entities associated with their type Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { entityDic.Add(ed.type, ed.entity); } // Depending on the topmost recognised intent, read the entities name switch (aQuery.topScoringIntent.intent) { case "ToolIsReady": string toolName = null; foreach (var pair in entityDic) { if (pair.Key == "Tool") { toolName = pair.Value; } } Behaviours.instance.ToolReady(toolName); break; } }
/// <summary> /// Call LUIS to submit a dictation result. /// The done Action is called at the completion of the method. /// </summary> public IEnumerator SubmitRequestToLuis(string dictationResult, Action done) { string queryString = string.Concat(Uri.EscapeDataString(dictationResult)); using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString)) { yield return(unityWebRequest.SendWebRequest()); if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError) { Debug.Log(unityWebRequest.error); } else { try { AnalysedQuery analysedQuery = JsonUtility.FromJson <AnalysedQuery>(unityWebRequest.downloadHandler.text); //analyse the elements of the response AnalyseResponseElements(analysedQuery); } catch (Exception exception) { Debug.Log("Luis Request Exception Message: " + exception.Message); } } done(); yield return(null); } }
private void UnpackResults(AnalysedQuery aQuery) { string topIntent = aQuery.topScoringIntent.intent; Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { entityDic.Add(ed.type, ed.entity); } switch (aQuery.topScoringIntent.intent) { case "PressButton": string actionToTake = null; string targetButton = null; foreach (var pair in entityDic) { if (pair.Key == "Target") { targetButton = pair.Value; } else if (pair.Key == "Action") { actionToTake = pair.Value; } } ProcessResults(targetButton, actionToTake); break; } CompleteButtonPress(); }
/// <summary> /// Call LUIS to submit a dictation result. /// </summary> public IEnumerator SubmitRequestToLuis(string dictationResult) { if (string.IsNullOrEmpty(dictationResult)) { StartCoroutine(DictationInputManager.StartRecording()); yield break; } submittedRequest = true; string queryString = string.Concat(Uri.EscapeDataString(dictationResult)); using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString)) { unityWebRequest.downloadHandler = new DownloadHandlerBuffer(); yield return(unityWebRequest.SendWebRequest()); long responseCode = unityWebRequest.responseCode; if (responseCode != 200) { Debug.LogError(unityWebRequest.responseCode + " " + unityWebRequest.downloadHandler.text); } AnalysedQuery analysedQuery = JsonUtility.FromJson <AnalysedQuery>(unityWebRequest.downloadHandler.text); //analyse the elements of the response AnalyseResponseElements(analysedQuery); } submittedRequest = false; }
private void AnalyseResponseElements(AnalysedQuery aQuery) { string topIntent = aQuery.topScoringIntent.intent; Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { entityDic.Add(ed.type, ed.entity); } switch (aQuery.topScoringIntent.intent) { case "ChangeObjectColor": string targetColor = null; string color = null; Debug.Log("LUIS Intent ChangeObjectColor"); foreach (var pair in entityDic) { if (pair.Key == "target") { targetColor = pair.Value; } else if (pair.Key == "color") { color = pair.Value; } } Behaviours.instance.ChangeTargetColor(targetColor, color); break; case "ChangeObjectSize": string targetForSize = null; Debug.Log("LUIS Intent ChangeObjectSize"); foreach (var pair in entityDic) { if (pair.Key == "target") { targetForSize = pair.Value; } } if (entityDic.ContainsKey("upsize") == true) { Behaviours.instance.UpSizeTarget(targetForSize); } if (entityDic.ContainsKey("downsize") == true) { Behaviours.instance.DownSizeTarget(targetForSize); } break; default: Debug.Log("LUIS Intent unknown"); break; } }
private void AnalyseResponseElements(AnalysedQuery aQuery) { string topIntent = aQuery.topScoringIntent.intent; // Create a dictionary of entities associated with their type Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { entityDic.Add(ed.type, ed.entity); } // Depending on the topmost recognised intent, read the entities name switch (aQuery.topScoringIntent.intent) { case "ChangeObjectColor": string targetForColor = null; string color = null; foreach (var pair in entityDic) { if (pair.Key == "target") { targetForColor = pair.Value; } else if (pair.Key == "color") { color = pair.Value; } } Behaviours.instance.ChangeTargetColor(targetForColor, color); break; case "ChangeObjectSize": string targetForSize = null; foreach (var pair in entityDic) { if (pair.Key == "target") { targetForSize = pair.Value; } } if (entityDic.ContainsKey("upsize") == true) { Behaviours.instance.UpSizeTarget(targetForSize); } else if (entityDic.ContainsKey("downsize") == true) { Behaviours.instance.DownSizeTarget(targetForSize); } break; } }
public IEnumerator SubmitRequestToLuis(string text) { WWWForm form = new WWWForm(); string queryString; queryString = string.Concat(Uri.EscapeDataString(text)); Debug.Log("LUIS analysing string: " + text); using (UnityWebRequest www = UnityWebRequest.Get(luisEndpoint + queryString)) { www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); long responseCode = www.responseCode; string s = www.downloadHandler.text; try { DataContractSerializer serializer = new DataContractSerializer(typeof(string)); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { using (Stream stream = GenerateStreamFromString(www.downloadHandler.text)) { StreamReader reader = new StreamReader(stream); AnalysedQuery analysedQuery = new AnalysedQuery(); analysedQuery = JsonUtility.FromJson <AnalysedQuery>(www.downloadHandler.text); AnalyseResponseElements(analysedQuery); } } } catch (Exception ex) { Debug.Log("Luis Exception" + ex.Message); } yield return(null); } }
/// <summary> /// Call LUIS to submit a dictation result. /// </summary> public IEnumerator SubmitRequestToLuis(string dictationResult) { string queryString; queryString = string.Concat(Uri.EscapeDataString(dictationResult)); using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString)) { unityWebRequest.downloadHandler = new DownloadHandlerBuffer(); yield return(unityWebRequest.SendWebRequest()); long responseCode = unityWebRequest.responseCode; AnalysedQuery analysedQuery = JsonUtility.FromJson <AnalysedQuery>(unityWebRequest.downloadHandler.text); //analyse the elements of the response AnalyseResponseElements(analysedQuery); } MicrophoneManager.instance.StartCapturingAudio(); }
private void AnalyseResponseElements(AnalysedQuery aQuery) { //string topIntent = aQuery.topScoringIntent.intent; // Create a dictionary of entities associated with their type Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { if (!entityDic.ContainsKey(ed.type)) { entityDic.Add(ed.type, ed.entity); } } // Depending on the topmost recognised intent, read the entities name switch (aQuery.topScoringIntent.intent) { case "ChangeObjectState": string stateOfTarget = null; string state = null; foreach (var pair in entityDic) { if (pair.Key == "target") { stateOfTarget = pair.Value; } else if (pair.Key == "booleanState") { state = pair.Value; } } Luis_Handler.Instance.ChangeObjectState(stateOfTarget, state); break; } }
private void AnalyseResponseElements(AnalysedQuery aQuery) { if (aQuery == null || aQuery.topScoringIntent == null || aQuery.topScoringIntent.intent == null) { Debug.Log("LuisManager.AnalyseResponseElements no intent"); return; } string topIntent = aQuery.topScoringIntent.intent; Debug.Log("LuisManager.AnalyseResponseElements intent:" + topIntent); // Create a dictionary of entities associated with their type Dictionary <string, string> entityDic = new Dictionary <string, string>(); foreach (EntityData ed in aQuery.entities) { if (!entityDic.ContainsKey(ed.type)) { entityDic.Add(ed.type, ed.entity); } } // Depending on the topmost recognised intent, read the entities name switch (aQuery.topScoringIntent.intent) { case "ChangeObjectColorIntent": { string target = null; string color = null; foreach (var pair in entityDic) { switch (pair.Key) { case "PositionOne": case "PositionTwo": case "PositionThree": case "PositionFour": { target = pair.Key; break; } case "color": { color = pair.Value; break; } case "target": { //todo break; } } } Debug.Log(string.Format("LuisManager.AnalyseResponseElements target:{0}, color:{1}", target, color)); if (!string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(color)) { GameManager.instance.ChangeTargetColor(target, color); } break; } case "ChangeObjectColorShortcutIntent": { Debug.Log(string.Format("LuisManager.AnalyseResponseElements.ChangeObjectColorShortcutIntent ", null)); GameManager.instance.ChangeTargetColorShortcut("", "", "", ""); break; } case "GameStartIntent": { GameManager.instance.StartNewGame(); break; } case "SubmitAnswerIntent": { GameManager.instance.SubmitAnswer(); break; } } }