public string doSomething(O_NLP.RootObject _o_NLP) { // Bind to the wit.ai NLP response class o_NLP = _o_NLP; conf = (o_NLP.outcomes[0].confidence * 100); state = o_NLP.outcomes[0].entities.on_off[0].value; if (state.Equals("on")) { Console.WriteLine("lampada accesa"); } else { Console.WriteLine("lampada spenta!"); } string sentence = ""; sentence += "Hello! I'm " + conf.ToString() + "% sure you set up lights."; return(sentence); }
private string ElaborateResponse(string nlp_text) { Console.WriteLine("\n" + nlp_text); // If the audio file doesn't contain anything, or wit.ai doesn't understand it, a code 400 will be returned if (nlp_text.Contains("The remote server returned an error: (400) Bad Request")) { throw new Exception("The remote server returned an error: (400) Bad Request"); //return "Sorry, didn't get that. Could you please repeat yourself?"; } oNLP = Post_NLP_Processing.ParseData(nlp_text); // This codeblock dynamically casts the intent to the corresponding class // Check README.txt in Vitals.Brain Assembly objAssembly; objAssembly = Assembly.GetExecutingAssembly(); Type classType = objAssembly.GetType("WitaiUnity." + oNLP.outcomes[0].intent); object obj = Activator.CreateInstance(classType); MethodInfo mi = classType.GetMethod("doSomething"); object[] parameters = new object[1]; parameters[0] = oNLP; mi = classType.GetMethod("doSomething"); string sentence = ""; sentence = (string)mi.Invoke(obj, parameters); // Show what was deducted from the sentence //nlp_text += "\n\n"+sentence; return(sentence); }