public IntroGrammar() { Choices majors = new Choices(); majors.Add(new SemanticResultValue("Computer Science", "CSC")); SemanticResultKey majorKey = new SemanticResultKey(Slots.Major.ToString(), majors); Choices years = new Choices(); for (int i = 2001; i < 2020; i++) { years.Add(new SemanticResultValue(i.ToString(), i)); } SemanticResultKey year = new SemanticResultKey(Slots.GradYear.ToString(), years); Choices yesOrNo = new Choices(); yesOrNo.Add(new SemanticResultValue("yes", "yes")); yesOrNo.Add(new SemanticResultValue("yeah", "yes")); yesOrNo.Add(new SemanticResultValue("yep", "yes")); yesOrNo.Add(new SemanticResultValue("no", "no")); yesOrNo.Add(new SemanticResultValue("nope", "no")); SemanticResultKey yesNo = new SemanticResultKey(Slots.YesNo.ToString(), yesOrNo); Choices options = new Choices(); options.Add(majorKey); options.Add(year); options.Add(yesNo); GrammarBuilder builder = new GrammarBuilder(); builder.Append(options); grammar = new Grammar(builder); }
public ChoiceAction(string language, string key, Action <SemanticValue> action) { if (NUMBERS == null) { NUMBERS = ConfigurationManager.AppSettings[language + "_numbers"].Split('|'); } Key = key; Action = action; string vocabulary = ConfigurationManager.AppSettings[language + "_" + key]; if (string.IsNullOrWhiteSpace(vocabulary)) { return; } GrammarBuilder grammarBuilder = new GrammarBuilder(); if (vocabulary.Contains("|")) { Choices choices = new Choices(); foreach (string choice in vocabulary.Split('|')) { choices.Add(CreateSubGrammarWithWildcard(choice)); } grammarBuilder.Append(choices); } else { grammarBuilder.Append(CreateSubGrammarWithWildcard(vocabulary)); } SemanticResultKey = new SemanticResultKey(key, grammarBuilder); }
private GrammarBuilder addCommand() { //<pleasantries> <command> <CLASS> <prep> <Time><year> //Pleasantries: I'd like to, please, I want to, would you //Command: Add, Remove //Class: a class, this class, that class, that other class //When: to Spring 2012 Choices commands = new Choices(); SemanticResultValue commandSRV; commandSRV = new SemanticResultValue("add", (int)CommandTypes.Add); commands.Add(commandSRV); commandSRV = new SemanticResultValue("take", (int)CommandTypes.Add); commands.Add(commandSRV); commandSRV = new SemanticResultValue("put", (int)CommandTypes.Add); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(commandSemKey); finalCommand.Append(this.course, 0, 1); finalCommand.Append(this.semester, 0, 1); return finalCommand; }
private Grammar BrightnessGrammar() { // Change/Set Brightness to Choices var choices = new Choices(); for (var i = -255; i <= 255; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); choices.Add(resultValueBuilder); } GrammarBuilder changeGrammar = "Change"; GrammarBuilder setGrammar = "Set"; GrammarBuilder brightnessGrammar = "Brightness"; GrammarBuilder toGrammar = "To"; SemanticResultKey resultKey = new SemanticResultKey("brightness", choices); GrammarBuilder resultContrast = new GrammarBuilder(resultKey); Choices alternatives = new Choices(changeGrammar, setGrammar); GrammarBuilder result = new GrammarBuilder(alternatives); result.Append(brightnessGrammar); result.Append(toGrammar); result.Append(resultContrast); Grammar grammar = new Grammar(result); grammar.Name = "Set Brightness"; return grammar; }
public Grammar CreateGrammar(string[] phrases) { Grammar g; Choices choices = new Choices(phrases); GrammarBuilder beforeBuilder = new GrammarBuilder(); beforeBuilder.AppendWildcard(); SemanticResultKey beforeKey = new SemanticResultKey("beforeKey", beforeBuilder); GrammarBuilder afterBuilder = new GrammarBuilder(); afterBuilder.AppendWildcard(); SemanticResultKey afterKey = new SemanticResultKey("afterKey", afterBuilder); GrammarBuilder builder = new GrammarBuilder(); builder.Culture = RecognitionEngine.RecognizerInfo.Culture; builder.Append(beforeBuilder); builder.Append(choices); builder.Append(afterBuilder); g = new Grammar(builder); return(g); }
public static SpeechRecognitionEngine Load_User_Grammar(SpeechRecognitionEngine oRecognizer) { //User List <string> userList = new List <string>(); DataSet dsResults = new DataSet(); try { //Load all users dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE base_type='PERSON'"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { userList.Add(dsResults.Tables[0].Rows[i][0].ToString()); } } catch (Exception ex) { throw new Exception("API.Grammar User Grammar 1: " + ex.Message, ex); } Choices userChoices = new Choices(userList.ToArray()); Choices tempChoices = new Choices(new string[] { "this is", "I am" }); try { GrammarBuilder builder = new GrammarBuilder(tempChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", userChoices); builder.Append(srk); Grammar gram = new Grammar(builder); gram.Name = "This is [OBJECT]"; oRecognizer.LoadGrammar(gram); } catch (Exception ex) { throw new Exception("API.Grammar User Grammar 2: " + ex.Message, ex); } return(oRecognizer); }
/***** Mostrar/leer hora *****/ private Grammar CreateGrammarBuilderTimeSemantics2(params int[] info) { //synth.Speak("Creando ahora la gramática"); Choices timeChoice = new Choices(); SemanticResultValue choiceResultValue = new SemanticResultValue("hora", "time"); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); timeChoice.Add(resultValueBuilder); SemanticResultKey choiceResultKey = new SemanticResultKey("time", timeChoice); GrammarBuilder time = new GrammarBuilder(choiceResultKey); GrammarBuilder mostrar = "Mostrar"; GrammarBuilder leer = "Leer"; Choices dos_alternativas = new Choices(mostrar, leer); GrammarBuilder frase = new GrammarBuilder(dos_alternativas); frase.Append(time); Grammar grammar = new Grammar(frase); grammar.Name = "Mostrar/Leer hora"; //Grammar grammar = new Grammar("so.xml.txt"); return(grammar); }
private Grammar LoadGrammar() { GrammarBuilder frasesGrammarBuilder = new GrammarBuilder(); Choices frasesChoice = new Choices(); // Abrir programa Choices abrirChoices = new Choices(); GrammarBuilder abrirGrammarBuilder = new GrammarBuilder("Abre el"); SemanticResultValue explorerSemanticValue = new SemanticResultValue("explorador de archivos", "start explorer.exe"); GrammarBuilder explorerBuilder = new GrammarBuilder(explorerSemanticValue); SemanticResultValue notepadSemanticValue = new SemanticResultValue("bloc de notas", "start notepad.exe"); GrammarBuilder notepadBuilder = new GrammarBuilder(notepadSemanticValue); SemanticResultValue chromeSemanticValue = new SemanticResultValue("navegador", "start https://www.upv.es"); GrammarBuilder chromeBuilder = new GrammarBuilder(chromeSemanticValue); abrirChoices.Add(explorerBuilder, notepadBuilder, chromeBuilder); SemanticResultKey semanticResultKey = new SemanticResultKey(ABRIR, abrirChoices); abrirGrammarBuilder.Append(semanticResultKey); // --- // Cuéntame un chiste GrammarBuilder chisteGrammarBuilder = new GrammarBuilder("Cuéntame un chiste"); // --- // Curiosidad GrammarBuilder curiosidadGrammarBuilder = new GrammarBuilder("Dime un dato curioso"); // --- // Descansa GrammarBuilder descansaGrammarBuilder = new GrammarBuilder("Descansa"); // --- SemanticResultValue abrirResultValue = new SemanticResultValue(abrirGrammarBuilder, ABRIR); SemanticResultValue chisteResultValue = new SemanticResultValue(chisteGrammarBuilder, CHISTE); SemanticResultValue curiosidadResultValue = new SemanticResultValue(curiosidadGrammarBuilder, CURIOSIDAD); SemanticResultValue descansaResultValue = new SemanticResultValue(descansaGrammarBuilder, DESCANSAR); frasesChoice.Add(abrirResultValue, chisteResultValue, curiosidadResultValue, descansaResultValue); SemanticResultKey frasesResultKey = new SemanticResultKey("frase", frasesChoice); frasesGrammarBuilder.Append(frasesResultKey); return(new Grammar(frasesGrammarBuilder)); }
public void CreateGrammar() { // 1[what] 2[is today's, is tomorrow's, is the] 3[is today, is tomorrow] 4[time, day, date] 5[is it] var one = new Choices(); one.Add(new SemanticResultValue("what", "what")); var sOne = new SemanticResultKey("one", one); var two = new Choices(); two.Add(new SemanticResultValue("is today's", "is today")); two.Add(new SemanticResultValue("is tomorrow's", "is tomorrow")); two.Add(new SemanticResultValue("is the", "is the")); var sTwo = new SemanticResultKey("two", two); var three = new Choices(); three.Add(new SemanticResultValue("is today", "is today")); three.Add(new SemanticResultValue("is tomorrow", "is tomorrow")); three.Add(new SemanticResultValue("was yesterday", "was yesterday")); var sThree = new SemanticResultKey("three", three); var four = new Choices(); four.Add(new SemanticResultValue("time", "time")); four.Add(new SemanticResultValue("day", "day")); four.Add(new SemanticResultValue("date", "day")); var sFour = new SemanticResultKey("three", four); var five = new Choices(); five.Add(new SemanticResultValue("is it", "is it")); var sFive = new SemanticResultKey("four", five); // what (time, day, date) is it var gOne = new GrammarBuilder(); gOne.Append(sOne); gOne.Append(sFour); gOne.Append(sFive); // what (is today's, is the) (time, day, date) var gTwo = new GrammarBuilder(); gTwo.Append(sOne); gTwo.Append(sTwo); gTwo.Append(sFour); // what (is today, is tomorrow) var gThree = new GrammarBuilder(); gThree.Append(sOne); gThree.Append(sThree); var perm = new Choices(); perm.Add(gOne); perm.Add(gTwo); perm.Add(gThree); var b = new GrammarBuilder(); b.Append(perm, 0, 1); Grammar = new Grammar(b); }
/// <summary> /// <see cref="Choices"/> extension method that adds the Current Temperature command. /// </summary> /// <param name="commandCatalogue"> The command catalogue choices. </param> /// <returns> The catalogue with the added command. </returns> public static Choices AddCurrentTemperatureCommand(this Choices commandCatalogue) { GrammarBuilder currentTemperatureCommand = new GrammarBuilder(VoiceCommands.CurrentTemperatureCommand); SemanticResultKey currentTemperatureMapping = new SemanticResultKey("CurrentTemperature", currentTemperatureCommand); commandCatalogue.Add(currentTemperatureMapping); return(commandCatalogue); }
/// <summary> <see cref="Choices"/> extension method that adds the Power Off command. </summary> /// <param name="commandCatalogue"> The command catalogue choices. </param> /// <returns> The catalogue with the added command. </returns> public static Choices AddPowerOffCommand(this Choices commandCatalogue) { GrammarBuilder powerOffAirConditionerCommand = new GrammarBuilder(VoiceCommands.PowerOffCommand); SemanticResultKey powerOffCommandMapping = new SemanticResultKey("PowerOff", powerOffAirConditionerCommand); commandCatalogue.Add(powerOffCommandMapping); return(commandCatalogue); }
/// <summary> /// <see cref="Choices"/> extension method that adds the Change Room Temperature command. /// </summary> /// <param name="commandCatalogue"> The command catalogue. </param> /// <returns> The catalogue with the added command. </returns> public static Choices AddChangeTemperatureCommand(this Choices commandCatalogue) { GrammarBuilder changeRoomTemperatureCommand = new GrammarBuilder(VoiceCommands.ChangeTemperatureCommand); changeRoomTemperatureCommand.Append(TargetTempMapping); changeRoomTemperatureCommand.Append(VoiceCommands.DegreesKeyWord); SemanticResultKey changeRoomTemperatureCommandMapping = new SemanticResultKey("ChangeRoomTemp", changeRoomTemperatureCommand); commandCatalogue.Add(changeRoomTemperatureCommandMapping); return(commandCatalogue); }
public Grammar GetGrammar() { var gBuilder = new GrammarBuilder(); var volume = new GrammarBuilder(); volume.AppendDictation(); var volumeKey = new SemanticResultKey("Volume", volume); gBuilder.Append("Volume"); gBuilder += volumeKey; return(new Grammar(gBuilder)); }
public Grammar GetGrammar() { GrammarBuilder gBuilder = new GrammarBuilder(); var video = new GrammarBuilder(); video.AppendDictation(); var videoKey = new SemanticResultKey("Video", video); gBuilder.Append("Play"); gBuilder += videoKey; gBuilder.Append("from youtube"); return(new Grammar(gBuilder)); }
//----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- private GrammarBuilder ConstructGrammarBuilder(string szStorageKey, params GrammarBuilder[] aGrammers) { Choices choice = new Choices(); foreach (GrammarBuilder builder in aGrammers) { //SemanticResultValue rsltValue = new SemanticResultValue(grammarBuilder); choice.Add(builder); } SemanticResultKey rsltKey = new SemanticResultKey(szStorageKey, choice.ToGrammarBuilder()); return(rsltKey.ToGrammarBuilder()); }
//----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- #region Private Methods private GrammarBuilder ConstructGrammarBuilder(string szStorageKey, params KeyValue[] aGrammers) { Choices choice = new Choices(); foreach (KeyValue keyValue in aGrammers) { GrammarBuilder grammarBuilder = new GrammarBuilder(keyValue.Key); SemanticResultValue rsltValue = new SemanticResultValue(grammarBuilder, keyValue.Value); choice.Add(rsltValue.ToGrammarBuilder()); } SemanticResultKey rsltKey = new SemanticResultKey(szStorageKey, choice.ToGrammarBuilder()); return(rsltKey.ToGrammarBuilder()); }
/// <summary> <see cref="Choices"/> extension method that adds the Cool Room command. </summary> /// <param name="commandCatalogue"> The command catalogue choices. </param> /// <returns> The catalogue with the added command. </returns> public static Choices AddCoolRoomCommand(this Choices commandCatalogue) { Choices coolRoomChoices = new Choices( VoiceCommands.CoolRoom, VoiceCommands.CoolRoom2, VoiceCommands.CoolRoom3); GrammarBuilder coolRoomCommand = new GrammarBuilder(coolRoomChoices); coolRoomCommand.Append(TargetTempMapping); coolRoomCommand.Append(VoiceCommands.DegreesKeyWord); SemanticResultKey coolRoomCommandMapping = new SemanticResultKey("CoolRoom", coolRoomCommand); commandCatalogue.Add(coolRoomCommandMapping); return(commandCatalogue); }
private static void buildGrammar() { if (grammar == null) { grammar = new GrammarBuilder(); Choices commands = new Choices(); commands.Add(new SemanticResultValue("search", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("search for", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("find", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("I want to take", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("I want to take a", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("I want to take a class on", (int)CommandTypes.Search)); commands.Add(new SemanticResultValue("What", (int)CommandTypes.Search)); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together Choices keywordChoices = new Choices(); foreach (string keyword in KeyWords) { keywordChoices.Add(new SemanticResultValue(keyword, keyword)); } SemanticResultKey keywordSemKey = new SemanticResultKey(Slots.KeyWords.ToString(), keywordChoices); //SemanticResultKey keyword2SemKey = new SemanticResultKey(Slots.KeyWords2.ToString(), keywordChoices); Choices suffix = new Choices(); suffix.Add("classes"); suffix.Add("class"); suffix.Add("course"); suffix.Add("courses"); Choices suffix2 = new Choices(); suffix2.Add("can I take"); suffix2.Add("are there"); grammar.Append(commandSemKey); grammar.Append(keywordSemKey); //grammar.Append(keyword2SemKey,0,1); grammar.Append(suffix, 0, 1); grammar.Append(suffix2, 0, 1); } }
public Guid AddWildcardGrammar(string semanticKey, string[] keywords) { Choices choices = new Choices(keywords); GrammarBuilder wilcardGrammarBuilder = new GrammarBuilder(); wilcardGrammarBuilder.Append(choices); wilcardGrammarBuilder.AppendWildcard(); SemanticResultKey semanticResultKey = new SemanticResultKey(semanticKey, choices); var id = Guid.NewGuid(); Grammar grammar = new Grammar(wilcardGrammarBuilder); grammar.Name = id.ToString(); _recognizer.LoadGrammar(grammar); _wildcards.Add(id, new Wildcard() { WilcardKey = semanticKey, Keywords = keywords, Grammar = grammar }); return(id); }
private Grammar GetGrammar() { Choices commandtype = new Choices(); commandtype.Add("create"); commandtype.Add("public"); commandtype.Add("interface"); commandtype.Add("class"); SemanticResultKey srkComtype = new SemanticResultKey("comtype", commandtype.ToGrammarBuilder()); GrammarBuilder gb = new GrammarBuilder(); gb.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"); gb.Append(srkComtype); gb.AppendDictation(); return(new Grammar(gb)); }
/***** Poner/Establecer fondo "color" (rojo, verde, azul) *****/ private Grammar CreateGrammarBuilderRGBSemantics2(params int[] info) { //synth.Speak("Creando ahora la gramática"); Choices colorChoice = new Choices(); SemanticResultValue choiceResultValue = new SemanticResultValue("Rojo", Color.FromName("Red").ToArgb()); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); colorChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Azul", Color.FromName("Blue").ToArgb()); resultValueBuilder = new GrammarBuilder(choiceResultValue); colorChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Verde", Color.FromName("Green").ToArgb()); resultValueBuilder = new GrammarBuilder(choiceResultValue); colorChoice.Add(resultValueBuilder); SemanticResultKey choiceResultKey = new SemanticResultKey("rgb", colorChoice); GrammarBuilder colores = new GrammarBuilder(choiceResultKey); GrammarBuilder poner = "Poner"; GrammarBuilder establecer = "Establecer"; GrammarBuilder fondo = "fondo"; Choices dos_alternativas = new Choices(poner, establecer); GrammarBuilder frase = new GrammarBuilder(dos_alternativas); frase.Append(fondo); frase.Append(colores); Grammar grammar = new Grammar(frase); grammar.Name = "Poner/Establecer fondo"; //Grammar grammar = new Grammar("so.xml.txt"); return(grammar); }
/***** Escribir "texto" *****/ private Grammar CreateGrammarBuilderTextSemantics2(params int[] info) { GrammarBuilder escribir = "Escribir"; GrammarBuilder texto = "texto"; SemanticResultKey choiceResultKey = new SemanticResultKey("escribir", escribir); Choices una_alternativa = new Choices(escribir); GrammarBuilder frase = new GrammarBuilder(una_alternativa); frase.Append(escribir); frase.Append(texto); Grammar grammar = new Grammar(frase); grammar.Name = "Escribir texto"; //Grammar grammar = new Grammar("so.xml.txt"); return(grammar); }
public Grammar getGrammar() { Choices setChoices = new Choices("I'd like to set an alarm for", "Set alarm for", "Set Alarm Clock", "Set Alarm"); GrammarBuilder morningChoices = new Choices("am", "in the morning"); morningChoices.Append(new SemanticResultValue(true)); GrammarBuilder eveningChoices = new Choices("pm", "tonight", "at night"); eveningChoices.Append(new SemanticResultValue(false)); Choices amOrPm = new Choices(morningChoices, eveningChoices); SemanticResultKey amOrPmKey = new SemanticResultKey("AmPm", amOrPm); Choices hours = new Choices("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"); Choices minutes = new Choices("10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "o'clock", " "); GrammarBuilder thisGB = new GrammarBuilder(); thisGB.Append(setChoices); thisGB.Append(new SemanticResultKey("Hours", hours)); thisGB.Append(new SemanticResultKey("Minutes", minutes)); thisGB.Append(amOrPmKey); Grammar thisGrammar = new Grammar(thisGB); // Set the Grammar name thisGrammar.Name = _grammarName; return thisGrammar; }
public Guid AddSemanticRecognition(string semanticKey, string[] keywords) { if (keywords == null) { return(_AddAnything(semanticKey)); } if (keywords.Length == 1 && keywords[0].Trim().Equals(string.Empty)) { return(default(Guid)); } Choices choices = new Choices(keywords); SemanticResultKey semanticResultKey = new SemanticResultKey(semanticKey, choices); GrammarBuilder grammarBuilder = semanticResultKey.ToGrammarBuilder(); Grammar grammar = new Grammar(grammarBuilder); var id = Guid.NewGuid(); grammar.Name = id.ToString(); grammar.Enabled = false; grammar.Priority = 120; _recognizer.LoadGrammar(grammar); semantics.Add(id, grammar); return(id); }
/***** Ocultar hora/texto *****/ private Grammar CreateGrammarBuilderRemoveSemantics2(params int[] info) { //synth.Speak("Creando ahora la gramática"); Choices removeChoice = new Choices(); SemanticResultValue choiceResultValue = new SemanticResultValue("hora", "time"); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); removeChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("texto", "text"); resultValueBuilder = new GrammarBuilder(choiceResultValue); removeChoice.Add(resultValueBuilder); SemanticResultKey choiceResultKey = new SemanticResultKey("remove", removeChoice); GrammarBuilder remove = new GrammarBuilder(choiceResultKey); GrammarBuilder ocultar = "Ocultar"; GrammarBuilder hora = "hora"; GrammarBuilder texto = "texto"; Choices dos_alternativas = new Choices(hora, texto); GrammarBuilder frase = new GrammarBuilder(dos_alternativas); frase.Append(ocultar); frase.Append(remove); Grammar grammar = new Grammar(frase); grammar.Name = "Ocultar hora/texto"; //Grammar grammar = new Grammar("so.xml.txt"); return(grammar); }
public static SpeechRecognitionEngine Load_Direct_Grammar(SpeechRecognitionEngine oRecognizer) { List <string> grammerList = new List <string>(); DataSet dsResults = new DataSet(); Choices myChoices = new Choices(); try { //Load all unique patterns with no place-holders into a single grammer, our main one. dsResults = OSAESql.RunSQL("SELECT `match` FROM osae_pattern_match WHERE UPPER(`match`) NOT LIKE '%[OBJECT]%' AND UPPER(`match`) NOT LIKE '%[STATE]%' AND UPPER(`match`) NOT LIKE '%[PRONOUN]%' ORDER BY `match`"); //grammerList.Add(gWakePhrase); //grammerList.Add(gSleepPhrase); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string sTemp = dsResults.Tables[0].Rows[i][0].ToString(); if (!string.IsNullOrEmpty(sTemp)) { SemanticResultKey srk = new SemanticResultKey(sTemp, sTemp); myChoices.Add(srk); } } } catch (Exception ex) { throw new Exception("API.Grammar Direct Grammar 1: " + ex.Message, ex); } try { GrammarBuilder builder = new GrammarBuilder(myChoices); Grammar gram = new Grammar(builder); gram.Name = "Direct Match"; oRecognizer.LoadGrammar(gram); } catch (Exception ex) { throw new Exception("API.Grammar Direct Grammar 2: " + ex.Message, ex); } return(oRecognizer); }
public static SpeechRecognitionEngine Load_Direct_Grammar(SpeechRecognitionEngine oRecognizer) { List<string> grammerList = new List<string>(); DataSet dsResults = new DataSet(); Choices myChoices = new Choices(); try { //Load all unique patterns with no place-holders into a single grammer, our main one. dsResults = OSAESql.RunSQL("SELECT `match` FROM osae_pattern_match WHERE UPPER(`match`) NOT LIKE '%[OBJECT]%' AND UPPER(`match`) NOT LIKE '%[STATE]%' AND UPPER(`match`) NOT LIKE '%[PRONOUN]%' ORDER BY `match`"); //grammerList.Add(gWakePhrase); //grammerList.Add(gSleepPhrase); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string sTemp = dsResults.Tables[0].Rows[i][0].ToString(); if (!string.IsNullOrEmpty(sTemp)) { SemanticResultKey srk = new SemanticResultKey(sTemp, sTemp); myChoices.Add(srk); } } } catch (Exception ex) { throw new Exception("API.Grammar Direct Grammar 1: " + ex.Message, ex); } try { GrammarBuilder builder = new GrammarBuilder(myChoices); Grammar gram = new Grammar(builder); gram.Name = "Direct Match"; oRecognizer.LoadGrammar(gram); } catch (Exception ex) { throw new Exception("API.Grammar Direct Grammar 2: " + ex.Message, ex); } return oRecognizer; }
private static Grammar CreateGrammar(Settings.Object config) { var objectChoices = new Choices(); foreach (var word in config.Words) { objectChoices.Add(new SemanticResultValue(word, config.Name)); } var objectSemKey = new SemanticResultKey("object", objectChoices); var objectGrammar = new GrammarBuilder(); objectGrammar.Append(objectSemKey); var actionChoices = new Choices(); foreach (var action in config.Actions) { foreach (var word in action.Words) { actionChoices.Add(new SemanticResultValue(word, action.Name)); } } var actionSemKey = new SemanticResultKey("action", actionChoices); var actionGrammar = new GrammarBuilder(); actionGrammar.Append(actionSemKey); var wakeGrammar = new GrammarBuilder(); wakeGrammar.Append(new Choices(Settings.Instance.WakeWord)); objectGrammar.Append(actionGrammar); wakeGrammar.Append(objectGrammar); return(new Grammar(wakeGrammar)); }
private static Grammar specialGrammar() { Choices navigations = new Choices(new string[] { "chapter", "item", "bookmark" }); SemanticResultKey navigationKeys = new SemanticResultKey("navigation", navigations); Choices values = new Choices(); for (int i = 1; i <= 300; i++) { values.Add(i.ToString()); } SemanticResultKey valueKeys = new SemanticResultKey("values", values); // 2. navigation commands. GrammarBuilder navigationGrammarBuilder = new GrammarBuilder(); navigationGrammarBuilder.Append(navigationKeys); navigationGrammarBuilder.Append(valueKeys); navigationGrammarBuilder.Culture = CultureInfo.GetCultureInfo("en-US"); navigationGrammarBuilder.Append("go"); // Create a Grammar object from the GrammarBuilder. return(new Grammar(navigationGrammarBuilder)); }
private Grammar CropWidthAndHeigthGrammar() { // Change/Set Crop Width to X and Height to Y var choicesWidth = new Choices(); var choicesHeight = new Choices(); Console.WriteLine(LastImage().Width); Console.WriteLine(LastImage().Height); for (var i = 0; i <= LastImage().Width; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); choicesWidth.Add(resultValueBuilder); } for (var i = 0; i <= LastImage().Height; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); choicesHeight.Add(resultValueBuilder); } GrammarBuilder changeGrammar = "Change"; GrammarBuilder setGrammar = "Set"; GrammarBuilder cropGrammar = "Crop"; GrammarBuilder widthGrammar = "Width"; GrammarBuilder heightGrammar = "Height"; GrammarBuilder toGrammar = "To"; GrammarBuilder andGrammar = "And"; SemanticResultKey resultKeyWidth = new SemanticResultKey("crop_width", choicesWidth); GrammarBuilder resultCropWidth = new GrammarBuilder(resultKeyWidth); SemanticResultKey resultKeyHeight = new SemanticResultKey("crop_height", choicesHeight); GrammarBuilder resultCropHeight = new GrammarBuilder(resultKeyHeight); Choices alternatives = new Choices(changeGrammar, setGrammar); GrammarBuilder result = new GrammarBuilder(alternatives); result.Append(cropGrammar); result.Append(widthGrammar); result.Append(toGrammar); result.Append(resultCropWidth); result.Append(andGrammar); result.Append(heightGrammar); result.Append(toGrammar); result.Append(resultCropHeight); Grammar grammar = new Grammar(result); grammar.Name = "Set Crop Width And Height"; return grammar; }
private GrammarBuilder viewCommand() { Choices commands = new Choices(); commands.Add(new SemanticResultValue("view", (int)CommandTypes.View)); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); Choices preCommand = new Choices(); preCommand.Add("switch to"); Choices views = new Choices(); views.Add(new SemanticResultValue("semester", (int)Views.Semester)); views.Add(new SemanticResultValue("requirements", (int)Views.Requirements)); SemanticResultKey viewSemKey = new SemanticResultKey(Slots.ViewName.ToString(), views); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(preCommand, 0, 1); finalCommand.Append(viewSemKey); finalCommand.Append(commandSemKey); return finalCommand; }
/** * Grammar creation */ private Grammar CreateGrammarBuilderSemantics(object p) { //1. Close application GrammarBuilder close = "Cierra"; GrammarBuilder close1 = "Cerrar"; GrammarBuilder exit = "Salir de"; Choices closeCh = new Choices(close, exit); GrammarBuilder application = "la aplicacion"; GrammarBuilder closeApplication = new GrammarBuilder(closeCh); closeApplication.Append(application); //2. Select topics GrammarBuilder want = "Quiero"; GrammarBuilder give = "Dame"; Choices wantCh = new Choices(want, give); GrammarBuilder issues = "Cuestiones de"; GrammarBuilder questions = "Preguntas de"; Choices questionsCh = new Choices(issues, questions); SemanticResultValue semanticResultValue = new SemanticResultValue("animales", "animales"); GrammarBuilder resultValueBuilder = new GrammarBuilder(semanticResultValue); Choices topicsCh = new Choices(); topicsCh.Add(resultValueBuilder); semanticResultValue = new SemanticResultValue("colores", "colores"); resultValueBuilder = new GrammarBuilder(semanticResultValue); topicsCh.Add(resultValueBuilder); SemanticResultKey semanticResultKey = new SemanticResultKey("topic1", topicsCh); GrammarBuilder topics = new GrammarBuilder(semanticResultKey); GrammarBuilder wantQuestions = wantCh; wantQuestions.Append(questionsCh); wantQuestions.Append(topics); //3. Select topic extended GrammarBuilder wantQuestionsExtended = wantCh; wantQuestionsExtended.Append(questionsCh); wantQuestionsExtended.Append(topics); wantQuestionsExtended.Append("y"); semanticResultKey = new SemanticResultKey("topic2", topicsCh); topics = new GrammarBuilder(semanticResultKey); wantQuestionsExtended.Append(topics); Choices select = new Choices(wantQuestions, wantQuestionsExtended); //4. Begin again GrammarBuilder beginAgain = "Empezar de nuevo"; //5. Need help GrammarBuilder needHelp = "Necesito ayuda"; //Answers //6. Multiple answers GrammarBuilder animalsColorsAnswers = new GrammarBuilder("Este animal es un"); Choices animalsCh = new Choices(); for (int i = 0; i < animalsList.Length; i++) { semanticResultValue = new SemanticResultValue(animalsList[i], animalsList[i]); resultValueBuilder = new GrammarBuilder(semanticResultValue); animalsCh.Add(resultValueBuilder); } semanticResultKey = new SemanticResultKey("animals", animalsCh); GrammarBuilder animals = new GrammarBuilder(semanticResultKey); animalsColorsAnswers.Append(animals); animalsColorsAnswers.Append(new GrammarBuilder("de color")); Choices colorsCh = new Choices(); for (int i = 0; i < colorsList.Length; i++) { semanticResultValue = new SemanticResultValue(colorsList[i], colorsList[i]); resultValueBuilder = new GrammarBuilder(semanticResultValue); colorsCh.Add(resultValueBuilder); } semanticResultKey = new SemanticResultKey("colors", colorsCh); GrammarBuilder colors = new GrammarBuilder(semanticResultKey); animalsColorsAnswers.Append(colors); //7. Animals answer GrammarBuilder animalsAnswers = "Este animal es un"; animalsAnswers.Append(animals); //8. Colors answer GrammarBuilder colorsAnswers = "Este color es el"; colorsAnswers.Append(colors); //9. Next Question Choices nextQuestion = new Choices("pregunta siguiente", "siguiente pregunta"); //10. Increase and decrease difficulty GrammarBuilder increaseDifficulty = "aumentar dificultad"; GrammarBuilder decreaseDifficulty = "disminuir dificultad"; Choices difficulty = new Choices(increaseDifficulty, decreaseDifficulty); Choices choices = new Choices(beginAgain, needHelp, closeApplication, select, nextQuestion, animalsAnswers, colorsAnswers, animalsColorsAnswers, difficulty); Grammar grammar = new Grammar(choices); //Grammar name grammar.Name = "Questions"; return(grammar); }
private static Grammar specialGrammar() { Choices navigations = new Choices(new string[] { "chapter", "verse","bookmark" }); SemanticResultKey navigationKeys = new SemanticResultKey("navigation", navigations); Choices values = new Choices(); for (int i = 1; i <= 286; i++) values.Add(i.ToString()); SemanticResultKey valueKeys = new SemanticResultKey("values", values); // 2. navigation commands. GrammarBuilder navigationGrammarBuilder = new GrammarBuilder(); navigationGrammarBuilder.Append(navigationKeys); navigationGrammarBuilder.Append(valueKeys); navigationGrammarBuilder.Culture = CultureInfo.GetCultureInfo("en-US"); navigationGrammarBuilder.Append("go"); // Create a Grammar object from the GrammarBuilder. return new Grammar(navigationGrammarBuilder); }
public void CreateGrammar() { // 1[what's, what is, how's, how is] 2[the weather] 3[today, tomorrow, on (day of week) right now, currently, outside] var one = new Choices(); one.Add(new SemanticResultValue("what's", "what")); one.Add(new SemanticResultValue("what is", "what")); one.Add(new SemanticResultValue("how's", "what")); one.Add(new SemanticResultValue("how is", "what")); var sOne = new SemanticResultKey("one", one); var two = new Choices(); two.Add(new SemanticResultValue("the weather", "the weather")); var sTwo = new SemanticResultKey("two", two); var three = new Choices(); three.Add(new SemanticResultValue("today", "today")); three.Add(new SemanticResultValue("tomorrow", "tomorrow")); three.Add(new SemanticResultValue("right now", "right now")); three.Add(new SemanticResultValue("currently", "currently")); three.Add(new SemanticResultValue("outside", "outside")); var sThree = new SemanticResultKey("three", three); var four = new Choices(); four.Add(new SemanticResultValue("on", "on")); four.Add(new SemanticResultValue("for", "for")); var sFour = new SemanticResultKey("four", four); var five = new Choices(); five.Add(new SemanticResultValue("sunday", "sunday")); five.Add(new SemanticResultValue("monday", "monday")); five.Add(new SemanticResultValue("tuesday", "tuesday")); five.Add(new SemanticResultValue("wednesday", "wednesday")); five.Add(new SemanticResultValue("thursday", "thursday")); five.Add(new SemanticResultValue("friday", "friday")); five.Add(new SemanticResultValue("saturday", "saturday")); var sFive = new SemanticResultKey("five", five); // (what's, how's) the weather (today, tomorrow) var gOne = new GrammarBuilder(); gOne.Append(sOne); gOne.Append(sTwo); gOne.Append(sThree); // (what's, how's) the weather var gTwo = new GrammarBuilder(); gTwo.Append(sOne); gTwo.Append(sTwo); // (what's, how's) the weather (for, on) (sunday, monday, tuesday, ...) var gThree = new GrammarBuilder(); gThree.Append(sOne); gThree.Append(sTwo); gThree.Append(sFour); gThree.Append(sFive); var perm = new Choices(); perm.Add(gOne); perm.Add(gTwo); perm.Add(gThree); var b = new GrammarBuilder(); b.Append(perm, 0, 1); Grammar = new Grammar(b); }
private Grammar InvertGrammar() { // Invert Image GrammarBuilder invert = "Invert"; GrammarBuilder image = "Image"; Choices commands = new Choices(invert); SemanticResultKey resultKey = new SemanticResultKey("invert", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(image); Grammar grammar = new Grammar(result); grammar.Name = "Invert Image"; return grammar; }
/* GRAMMARS */ private Grammar InitCropGrammar() { // Init Crop GrammarBuilder init = "Init"; GrammarBuilder crop = "Crop"; Choices commands = new Choices(init); SemanticResultKey resultKey = new SemanticResultKey("init_crop", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(crop); Grammar grammar = new Grammar(result); grammar.Name = "Init Crop"; return grammar; }
public static SpeechRecognitionEngine Load_User_Grammar(SpeechRecognitionEngine oRecognizer) { //User List<string> userList = new List<string>(); DataSet dsResults = new DataSet(); try { //Load all users dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE base_type='PERSON'"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { userList.Add(dsResults.Tables[0].Rows[i][0].ToString()); } } catch (Exception ex) {throw new Exception("API.Grammar User Grammar 1: " + ex.Message, ex);} Choices userChoices = new Choices(userList.ToArray()); Choices tempChoices = new Choices(new string[] { "this is", "I am" }); try { GrammarBuilder builder = new GrammarBuilder(tempChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", userChoices); builder.Append(srk); Grammar gram = new Grammar(builder); gram.Name = "This is [OBJECT]"; oRecognizer.LoadGrammar(gram); } catch (Exception ex) { throw new Exception("API.Grammar User Grammar 2: " + ex.Message, ex); } return oRecognizer; }
public static SpeechRecognitionEngine Load_OSA_Grammar(SpeechRecognitionEngine oRecognizer) { oRecognizer = Load_Object_State_Grammar(oRecognizer); Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" }); DataSet dsResults = new DataSet(); #region Build a List of all Objects List <string> objectFullList = new List <string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); if (!string.IsNullOrEmpty(grammer)) { objectFullList.Add(grammer); } } Choices objectFullChoices = new Choices(objectFullList.ToArray()); #endregion #region Build a List of all Possessive Objects List <string> objectPossessiveList = new List <string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') AS object_name FROM osae_v_object_list_full"); //dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object ORDER BY object_name"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); if (!string.IsNullOrEmpty(grammer)) { objectPossessiveList.Add(grammer); } } Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray()); #endregion #region Build a List of all Containers List <string> containerList = new List <string>(); //Get All containers dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE container=1"); foreach (DataRow dr in dsResults.Tables[0].Rows) { containerList.Add(dr[0].ToString()); } Choices containerChoices = new Choices(containerList.ToArray()); #endregion #region Build a List of all Object Types List <string> objectTypeList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion #region What is [OBJECT]'s [PROPERTY] //What is OBJECT's PROPERTY //What is NP OBJECT's PROPERTY //What is my PROPERTY //What is your PROPERTY GrammarBuilder gbWhatIsMyProperty = new GrammarBuilder("What is"); SemanticResultKey srk = new SemanticResultKey("PARAM1", "my"); gbWhatIsMyProperty.Append(srk); GrammarBuilder gbWhatIsYourProperty = new GrammarBuilder("What is"); srk = new SemanticResultKey("PARAM1", "your"); gbWhatIsYourProperty.Append(srk); foreach (string ot in objectTypeList) { GrammarBuilder gbWhatIsObjectProperty = new GrammarBuilder("What is"); GrammarBuilder gbWhatIsNPObjectProperty = new GrammarBuilder("What is"); gbWhatIsNPObjectProperty.Append(nounPrecedentChoices); List <string> objectList = new List <string>(); List <string> propertyList = new List <string>(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gbWhatIsObjectProperty.Append(srk); gbWhatIsNPObjectProperty.Append(srk); //Now the the appropriate properties dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND (property_datatype != 'Object Type' OR property_object_type != 'PERSON')"); foreach (DataRow dr in dsResults.Tables[0].Rows) { propertyList.Add(dr[0].ToString()); } if (propertyList.Count > 0) { Choices propertyChoices = new Choices(propertyList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); if (ot == "PERSON") { gbWhatIsMyProperty.Append(srk); Grammar gWhatIsMyProperty = new Grammar(gbWhatIsMyProperty); gWhatIsMyProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsMyProperty); } else if (ot == "SYSTEM") { gbWhatIsYourProperty.Append(srk); Grammar gWhatIsYourProperty = new Grammar(gbWhatIsYourProperty); gWhatIsYourProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsYourProperty); } gbWhatIsObjectProperty.Append(srk); Grammar gWhatIsObjectProperty = new Grammar(gbWhatIsObjectProperty); gWhatIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsObjectProperty); gbWhatIsNPObjectProperty.Append(srk); Grammar gWhatIsNPObjectProperty = new Grammar(gbWhatIsNPObjectProperty); gWhatIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsNPObjectProperty); } } } #endregion #region Who is [OBJECT]'s [PROPERTY] //Who is OBJECT's PROPERTY //Who is NP OBJECT's PROPERTY //Who is my PROPERTY //Who is your PROPERTY GrammarBuilder gbWhoIsMyProperty = new GrammarBuilder("Who is"); srk = new SemanticResultKey("PARAM1", "my"); gbWhoIsMyProperty.Append(srk); GrammarBuilder gbWhoIsYourProperty = new GrammarBuilder("Who is"); srk = new SemanticResultKey("PARAM1", "your"); gbWhoIsYourProperty.Append(srk); foreach (string ot in objectTypeList) { GrammarBuilder gbWhoIsObjectProperty = new GrammarBuilder("Who is"); GrammarBuilder gbWhoIsNPObjectProperty = new GrammarBuilder("Who is"); gbWhoIsNPObjectProperty.Append(nounPrecedentChoices); List <string> objectList = new List <string>(); List <string> propertyList = new List <string>(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gbWhoIsObjectProperty.Append(srk); gbWhoIsNPObjectProperty.Append(srk); //Now the the appropriate properties dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='Object Type' AND property_object_type='PERSON'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { propertyList.Add(dr[0].ToString()); } if (propertyList.Count > 0) { Choices propertyChoices = new Choices(propertyList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); if (ot == "PERSON") { gbWhoIsMyProperty.Append(srk); Grammar gWhoIsMyProperty = new Grammar(gbWhoIsMyProperty); gWhoIsMyProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsMyProperty); } else if (ot == "SYSTEM") { gbWhoIsYourProperty.Append(srk); Grammar gWhoIsYourProperty = new Grammar(gbWhoIsYourProperty); gWhoIsYourProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsYourProperty); } gbWhoIsObjectProperty.Append(srk); Grammar gWhoIsObjectProperty = new Grammar(gbWhoIsObjectProperty); gWhoIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsObjectProperty); gbWhoIsNPObjectProperty.Append(srk); Grammar gWhoIsNPObjectProperty = new Grammar(gbWhoIsNPObjectProperty); gWhoIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsNPObjectProperty); } } } #endregion #region [OBJECT]'s [PROPERTY] is [VALUE] //OBJECT's PROPERTY is [VALUE] foreach (string ot in objectTypeList) { List <string> objectList = new List <string>(); GrammarBuilder gbObjectPropertyIs = new GrammarBuilder(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gbObjectPropertyIs.Append(srk); //Now the the appropriate properties DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype"); foreach (DataRow drType in dsPropType.Tables[0].Rows) { List <string> propertyList = new List <string>(); DataSet dsPropName = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype"); foreach (DataRow drName in dsPropName.Tables[0].Rows) { propertyList.Add(drName["property_name"].ToString()); } Choices propertyChoices = new Choices(propertyList.ToArray()); if (drType["property_datatype"].ToString().ToUpper() == "STRING") { GrammarBuilder dictation = new GrammarBuilder(); dictation.AppendDictation(); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT") { srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE") { List <string> propertyOTList = new List <string>(); DataSet dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'"); foreach (DataRow drName in dsPropObjectType.Tables[0].Rows) { propertyOTList.Add(drName["object_name"].ToString()); } Choices propertyOTChoices = new Choices(propertyOTList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } } } } #endregion #region [OBJECT] [CONTAINER] // OBJECT is in CONTAINER // np OBJECT is in CONTAINER // OBJECT is in np CONTAINER // np OBJECT is in np CONTAINER // I am in CONTAINER // I am in np CONTAINER // You are in CONTAINER // You are in np CONTAINER // is OBJECT in CONTAINER // is np OBJECT is in CONTAINER // is OBJECT in np CONTAINER // is np OBJECT in np CONTAINER // am I in CONTAINER // am I in NP CONTAINER // are you in CONTAINER // are you in np CONTAINER // OBJECT is in CONTAINER GrammarBuilder gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); Grammar g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // np OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // I am in CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "I"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("am in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // I am in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "I"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("am in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // You are in CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "you"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("are in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // You are in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "you"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("are in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is OBJECT in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // am I in CONTAINER gb_GrammarBuilder = new GrammarBuilder("Am"); srk = new SemanticResultKey("PARAM1", "I"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // am I in NP CONTAINER gb_GrammarBuilder = new GrammarBuilder("Am"); srk = new SemanticResultKey("PARAM1", "I"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // are you in CONTAINER gb_GrammarBuilder = new GrammarBuilder("Are"); srk = new SemanticResultKey("PARAM1", "you"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // are you in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("Are"); srk = new SemanticResultKey("PARAM1", "you"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); #endregion #region [OBJECT] [OBJECT TYPE] // is OBJECT np OBJECT TYPE // is np OBJECT np OBJECT TYPE // am I np OBJECT TYPE // are you np OBJECT TYPE // is OBJECT np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // am I np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("am"); srk = new SemanticResultKey("PARAM1", "I"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // are you np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("are"); srk = new SemanticResultKey("PARAM1", "you"); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); #endregion #region Where/What is [OBJECT] //Where is OBJECT //Where is NP OBJECT //Where am I //Where are You //What is OBJECT //What is NP OBJECT //What am I //What are You //Where is OBJECT GrammarBuilder gb_Single = new GrammarBuilder("Where is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); Grammar g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where is NP OBJECT gb_Single = new GrammarBuilder("Where is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where am I gb_Single = new GrammarBuilder("Where am"); srk = new SemanticResultKey("PARAM1", "I"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where are you gb_Single = new GrammarBuilder("Where are"); srk = new SemanticResultKey("PARAM1", "you"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What is OBJECT gb_Single = new GrammarBuilder("What is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What is NP OBJECT gb_Single = new GrammarBuilder("What is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What am I gb_Single = new GrammarBuilder("What am"); srk = new SemanticResultKey("PARAM1", "I"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What are you gb_Single = new GrammarBuilder("What are"); srk = new SemanticResultKey("PARAM1", "you"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); #endregion #region Who is [PRONOUN] //Who am I //Who are you //Who am I gb_Single = new GrammarBuilder("Who am"); srk = new SemanticResultKey("PARAM1", "I"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Who is [PERSON]"; oRecognizer.LoadGrammar(g_Single); //Who are you gb_Single = new GrammarBuilder("Who are"); srk = new SemanticResultKey("PARAM1", "you"); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Who is [PERSON]"; oRecognizer.LoadGrammar(g_Single); #endregion return(oRecognizer); }
public static SpeechRecognitionEngine Load_Object_State_Grammar(SpeechRecognitionEngine oRecognizer) { DataSet dsResults = new DataSet(); Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" }); #region Build a List of all Object Types List <string> objectTypeList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion #region [Object] [State] // 1 Are you STATE // 2 Am I STATE // 3 Is OBJECT STATE? // 4 Is [NP] OBJECT STATE? // 5 You are STATE // 6 I am STATE // 7 OBJECT is STATE // 8 [NP] OBJECT is STATE GrammarBuilder gb1 = new GrammarBuilder("Are"); GrammarBuilder gb5 = new GrammarBuilder(); SemanticResultKey srk = new SemanticResultKey("PARAM1", "you"); gb1.Append(srk); gb5.Append(srk); GrammarBuilder gb2 = new GrammarBuilder("Am I"); GrammarBuilder gb6 = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "I"); gb2.Append(srk); gb6.Append(srk); //builder.Append(objectChoices); foreach (string ot in objectTypeList) { List <string> stateList = new List <string>(); GrammarBuilder gb3 = new GrammarBuilder("Is"); GrammarBuilder gb4 = new GrammarBuilder("Is"); gb4.Append(nounPrecedentChoices); GrammarBuilder gbNPObjectIsState = new GrammarBuilder(nounPrecedentChoices); //Get All objects of the current Object Type List <string> objectList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gb3.Append(srk); gb4.Append(srk); GrammarBuilder gbObjectIsState = new GrammarBuilder(srk); gbNPObjectIsState.Append(srk); gbObjectIsState.Append("is"); gbNPObjectIsState.Append("is"); //Now the the appropriate states dsResults = OSAESql.RunSQL("SELECT state_name FROM osae_v_object_type_state_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { stateList.Add(dr[0].ToString()); } if (stateList.Count > 0) { Choices stateChoices = new Choices(stateList.ToArray()); srk = new SemanticResultKey("PARAM2", stateChoices); if (ot == "PERSON") { gb2.Append(srk); Grammar gAmIState = new Grammar(gb2); gAmIState.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(gAmIState); } else if (ot == "SYSTEM") { gb1.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g1); gb5.Append(srk); Grammar g5 = new Grammar(gb5); g5.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g5); } gb3.Append(srk); Grammar gIsObjectState = new Grammar(gb3); gIsObjectState.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(gIsObjectState); gb4.Append(srk); Grammar gIsNPObjectState = new Grammar(gb4); gIsNPObjectState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gIsNPObjectState); gbObjectIsState.Append(srk); Grammar gObjectIsState = new Grammar(gbObjectIsState); gObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gObjectIsState); gbNPObjectIsState.Append(srk); Grammar gNPObjectIsState = new Grammar(gbNPObjectIsState); gNPObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gNPObjectIsState); } } } #endregion return(oRecognizer); }
public static Grammar buildGrammar(List <NasdaqStock> stockList) { GrammarBuilder choicesGrammarBuilder = new GrammarBuilder(); List <string> companyNames = new List <string>(); foreach (var stock in stockList) { companyNames.Add(stock.name); } Choices companyNameChoices = new Choices(); SemanticResultValue companyNameSRV; foreach (var stock in companyNames) { companyNameSRV = new SemanticResultValue(stock, stock); companyNameChoices.Add(companyNameSRV); } SemanticResultKey companyModifierSemantics = new SemanticResultKey("CompanyNameModifier", companyNameChoices); GrammarBuilder companyNameBuilder = new GrammarBuilder(); companyNameBuilder.Append(companyModifierSemantics); Choices companyModifierChoices = new Choices(); companyModifierChoices.Add(companyNameBuilder); GrammarBuilder companyModifierBuilder = new GrammarBuilder(companyModifierChoices); SemanticResultKey companyModifierSemantics2 = new SemanticResultKey("CompanyNameModifier2", companyNameChoices); GrammarBuilder companyNameBuilder2 = new GrammarBuilder(); companyNameBuilder2.Append(companyModifierSemantics2); Choices companyModifierChoices2 = new Choices(); companyModifierChoices2.Add(companyNameBuilder2); GrammarBuilder companyModifierBuilder2 = new GrammarBuilder(companyModifierChoices2); string[] myString = companyNames.ToArray(); Choices stockNameChoices = new Choices(myString); Choices displayChoices = new Choices(); SemanticResultValue displayChoicesSRV; displayChoicesSRV = new SemanticResultValue("tell me the", "tell me the"); displayChoices.Add(displayChoicesSRV); displayChoicesSRV = new SemanticResultValue("show me the", "show me the"); displayChoices.Add(displayChoicesSRV); SemanticResultKey displayChoicesSemantics = new SemanticResultKey("DisplayOption", displayChoicesSRV); GrammarBuilder displayGrammarBuilder = new GrammarBuilder(); displayGrammarBuilder.Append(displayChoicesSemantics); Choices displayPermutations = new Choices(); displayPermutations.Add(displayGrammarBuilder); GrammarBuilder displayPermutationGrammarBuilder = new GrammarBuilder(); displayGrammarBuilder.Append(displayPermutationGrammarBuilder); Choices modeChoices = new Choices("tell me the", "show me"); Choices modifierChoices = new Choices("bid of", "change of", "ask of", "close of"); #region modifiers //Graphmodifier 1 Choices graphModifierChoices = new Choices(); SemanticResultValue graphModifierSRV; graphModifierSRV = new SemanticResultValue("as a line graph the", "as a line graph the"); graphModifierChoices.Add(graphModifierSRV); graphModifierSRV = new SemanticResultValue("as a bar graph the", "as a bar graph the"); graphModifierChoices.Add(graphModifierSRV); SemanticResultKey graphModifierSemantics = new SemanticResultKey("GraphModifier1", graphModifierChoices); GrammarBuilder graphModifierGrammarBuilder = new GrammarBuilder(); graphModifierGrammarBuilder.Append(graphModifierSemantics); Choices graphModifierPermutations = new Choices(); graphModifierPermutations.Add(graphModifierGrammarBuilder); GrammarBuilder permutationList = new GrammarBuilder(); permutationList.Append(graphModifierPermutations); //end graph modifier 1 //month modifier Choices monthChoices = new Choices(); SemanticResultValue monthModifierSRV; monthModifierSRV = new SemanticResultValue("january", "january"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("february", "February"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("march", "march"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("april", "april"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("may", "may"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("june", "june"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("july", "july"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("august", "august"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("september", "september"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("october", "october"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("november", "november"); monthChoices.Add(monthModifierSRV); monthModifierSRV = new SemanticResultValue("december", "december"); monthChoices.Add(monthModifierSRV); SemanticResultKey monthModifierSemantics = new SemanticResultKey("monthModifier", monthChoices); GrammarBuilder monthModifierGrammar = new GrammarBuilder(); monthModifierGrammar.Append(monthModifierSemantics); Choices monthModifierPermutations = new Choices(); monthModifierPermutations.Add(monthModifierGrammar); GrammarBuilder monthModifierBuilder = new GrammarBuilder(); monthModifierBuilder.Append(monthModifierPermutations); //end month modifier //month 2 modifier Choices monthChoices2 = new Choices(); SemanticResultValue monthModifierSRV2; monthModifierSRV2 = new SemanticResultValue("january", "january"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("february", "February"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("march", "march"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("april", "april"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("may", "may"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("june", "june"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("july", "july"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("august", "august"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("september", "september"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("october", "october"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("november", "november"); monthChoices2.Add(monthModifierSRV2); monthModifierSRV2 = new SemanticResultValue("december", "december"); monthChoices2.Add(monthModifierSRV2); SemanticResultKey monthModifierSemantics2 = new SemanticResultKey("monthModifier2", monthChoices2); GrammarBuilder monthModifierGrammar2 = new GrammarBuilder(); monthModifierGrammar2.Append(monthModifierSemantics2); Choices monthModifierPermutations2 = new Choices(); monthModifierPermutations2.Add(monthModifierGrammar2); GrammarBuilder monthModifierBuilder2 = new GrammarBuilder(); monthModifierBuilder2.Append(monthModifierPermutations2); //end month modifier //year modifier SemanticResultValue yearModifierSRV; Choices yearChoices = new Choices(); for (var i = 2000; i <= 2017; i++) { yearModifierSRV = new SemanticResultValue(i.ToString(), i.ToString()); yearChoices.Add(yearModifierSRV); } SemanticResultKey yearModifierSemantics = new SemanticResultKey("yearModifier", yearChoices); GrammarBuilder yearModifierGrammar = new GrammarBuilder(); yearModifierGrammar.Append(yearModifierSemantics); Choices YearModifierPermutations = new Choices(); YearModifierPermutations.Add(yearModifierGrammar); GrammarBuilder YearModifierBuilder = new GrammarBuilder(); YearModifierBuilder.Append(YearModifierPermutations); //end year modifier //year2 modifier SemanticResultValue yearModifierSRV2; Choices yearChoices2 = new Choices(); for (var i = 2000; i <= 2017; i++) { yearModifierSRV2 = new SemanticResultValue(i.ToString(), i.ToString()); yearChoices2.Add(yearModifierSRV2); } SemanticResultKey yearModifierSemantics2 = new SemanticResultKey("yearModifier2", yearChoices2); GrammarBuilder yearModifierGrammar2 = new GrammarBuilder(); yearModifierGrammar2.Append(yearModifierSemantics2); Choices YearModifierPermutations2 = new Choices(); YearModifierPermutations2.Add(yearModifierGrammar2); GrammarBuilder YearModifierBuilder2 = new GrammarBuilder(); YearModifierBuilder2.Append(YearModifierPermutations2); //end year2 modifier #endregion //show me as a line graph the close of BancFirst Corporation and American Superconductor Corporation from January 2012 to January 2016 choicesGrammarBuilder.Append(new SemanticResultKey("Mode", modeChoices)); choicesGrammarBuilder.Append(permutationList, 0, 1); choicesGrammarBuilder.Append(new SemanticResultKey("Modifier", modifierChoices)); choicesGrammarBuilder.Append(companyModifierChoices); choicesGrammarBuilder.Append("and", 0, 1); choicesGrammarBuilder.Append("from", 0, 1); choicesGrammarBuilder.Append(monthModifierBuilder, 0, 1); choicesGrammarBuilder.Append(YearModifierBuilder, 0, 1); choicesGrammarBuilder.Append("to", 0, 1); choicesGrammarBuilder.Append(monthModifierBuilder2, 0, 1); choicesGrammarBuilder.Append(YearModifierBuilder2, 0, 1); Grammar choicesGrammar = new Grammar(choicesGrammarBuilder); return(choicesGrammar); }
private GrammarBuilder removeCommand() { Choices commands = new Choices(); SemanticResultValue commandSRV; commandSRV = new SemanticResultValue("remove", (int)CommandTypes.Remove); commands.Add(commandSRV); commandSRV = new SemanticResultValue("get rid of", (int)CommandTypes.Remove); commands.Add(commandSRV); commandSRV = new SemanticResultValue("take away", (int)CommandTypes.Remove); commands.Add(commandSRV); commandSRV = new SemanticResultValue("delete", (int)CommandTypes.Remove); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); //SemanticResultKey course1 = new SemanticResultKey(Slots.Course1.ToString(), this.course); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(commandSemKey); finalCommand.Append(this.course, 0, 1); finalCommand.Append(this.semester, 0, 1); return finalCommand; }
public static SpeechRecognitionEngine Load_Voice_Grammars(SpeechRecognitionEngine oRecognizer) { Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" }); Choices pronounChoices = new Choices(new string[] { "I", "you" }); Choices possPronounChoices = new Choices(new string[] { "my", "your" }); Choices IsChoices = new Choices(new string[] { "is", "am", "are" }); Choices WhatWhoChoices = new Choices(new string[] { "what is", "who is" }); DataSet dsResults = new DataSet(); #region Build a List of all Objects AND Possessive Objects List <string> objectFullList = new List <string>(); List <string> objectPossessiveList = new List <string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString(); if (!string.IsNullOrEmpty(grammer)) { objectFullList.Add(grammer); } if (!string.IsNullOrEmpty(possessivegrammer)) { objectPossessiveList.Add(possessivegrammer); } } Choices objectFullChoices = new Choices(objectFullList.ToArray()); Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray()); #endregion #region Build a List of all Containers List <string> containerList = new List <string>(); //Get All containers dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE container=1"); foreach (DataRow dr in dsResults.Tables[0].Rows) { containerList.Add(dr[0].ToString()); } Choices containerChoices = new Choices(containerList.ToArray()); #endregion #region Build a List of all Object Types List <string> objectTypeList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion //Choices are done, now write the grammars #region What is [OBJECT]'s [PROPERTY] //1 What/Who is my/your PROPERTY //2 What/Who is OBJECT's PROPERTY //3 What/Who is NP OBJECT's PROPERTY try { GrammarBuilder gb1 = new GrammarBuilder(WhatWhoChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", possPronounChoices); gb1.Append(srk); GrammarBuilder gb2 = new GrammarBuilder(WhatWhoChoices); GrammarBuilder gb3 = new GrammarBuilder(WhatWhoChoices); gb3.Append(nounPrecedentChoices); List <string> propertyList = new List <string>(); srk = new SemanticResultKey("PARAM1", objectPossessiveChoices); gb2.Append(srk); gb3.Append(srk); dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property"); foreach (DataRow dr in dsResults.Tables[0].Rows) { propertyList.Add(dr[0].ToString()); } Choices propertyChoices = new Choices(propertyList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); gb1.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(g1); gb2.Append(srk); Grammar g2 = new Grammar(gb2); g2.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(g2); gb3.Append(srk); Grammar g3 = new Grammar(gb3); g3.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(g3); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, What is: " + ex.Message, ex); } #endregion //Too slow #region [Object] [State] /* * // 1 Are you STATE * // 2 Am I STATE * // 3 Is OBJECT STATE? * // 4 Is [NP] OBJECT STATE? * * // 5 You are STATE * // 6 I am STATE * // 7 OBJECT is STATE * // 8 [NP] OBJECT is STATE * GrammarBuilder gb1 = new GrammarBuilder("Are"); * GrammarBuilder gb5 = new GrammarBuilder(); * srk = new SemanticResultKey("PARAM1", "you"); * gb1.Append(srk); * gb5.Append(srk); * * GrammarBuilder gb2 = new GrammarBuilder("Am"); * GrammarBuilder gb6 = new GrammarBuilder(); * srk = new SemanticResultKey("PARAM1", "I"); * gb2.Append(srk); * gb6.Append(srk); * * //builder.Append(objectChoices); * * foreach (string ot in objectTypeList) * { * List<string> stateList = new List<string>(); * GrammarBuilder gb3 = new GrammarBuilder("Is"); * GrammarBuilder gb4 = new GrammarBuilder("Is"); * gb4.Append(nounPrecedentChoices); * * GrammarBuilder gbNPObjectIsState = new GrammarBuilder(nounPrecedentChoices); * * //Get All objects of the current Object Type * List<string> objectList = new List<string>(); * dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); * foreach (DataRow dr in dsResults.Tables[0].Rows) * { * objectList.Add(dr[0].ToString()); * } * if (objectList.Count > 0) // Only bother with this object type if there are objects using it * { * Choices objectChoices = new Choices(objectList.ToArray()); * srk = new SemanticResultKey("PARAM1", objectChoices); * * gb3.Append(srk); * gb4.Append(srk); * GrammarBuilder gbObjectIsState = new GrammarBuilder(srk); * gbNPObjectIsState.Append(srk); * gbObjectIsState.Append("is"); * gbNPObjectIsState.Append("is"); * * //Now the the appropriate states * dsResults = OSAESql.RunSQL("SELECT state_label FROM osae_v_object_type_state_list_full WHERE object_type='" + ot + "'"); * foreach (DataRow dr in dsResults.Tables[0].Rows) * { * stateList.Add(dr[0].ToString()); * } * if (stateList.Count > 0) * { * Choices stateChoices = new Choices(stateList.ToArray()); * srk = new SemanticResultKey("PARAM2", stateChoices); * if (ot == "PERSON") * { * gb2.Append(srk); * Grammar gAmIState = new Grammar(gb2); * gAmIState.Name = "Is [OBJECT] [STATE]"; * oRecognizer.LoadGrammar(gAmIState); * * } * else if (ot == "SYSTEM") * { * gb1.Append(srk); * Grammar g1 = new Grammar(gb1); * g1.Name = "Is [OBJECT] [STATE]"; * oRecognizer.LoadGrammar(g1); * * gb5.Append(srk); * Grammar g5 = new Grammar(gb5); * g5.Name = "Is [OBJECT] [STATE]"; * oRecognizer.LoadGrammar(g5); * } * * gb3.Append(srk); * Grammar gIsObjectState = new Grammar(gb3); * gIsObjectState.Name = "Is [OBJECT] [STATE]"; * oRecognizer.LoadGrammar(gIsObjectState); * * gb4.Append(srk); * Grammar gIsNPObjectState = new Grammar(gb4); * gIsNPObjectState.Name = "[OBJECT] is [STATE]"; * oRecognizer.LoadGrammar(gIsNPObjectState); * * gbObjectIsState.Append(srk); * Grammar gObjectIsState = new Grammar(gbObjectIsState); * gObjectIsState.Name = "[OBJECT] is [STATE]"; * oRecognizer.LoadGrammar(gObjectIsState); * * gbNPObjectIsState.Append(srk); * Grammar gNPObjectIsState = new Grammar(gbNPObjectIsState); * gNPObjectIsState.Name = "[OBJECT] is [STATE]"; * oRecognizer.LoadGrammar(gNPObjectIsState); * } * } * } */ #endregion #region New [Object] [State] // 1 [Am I/Are you] STATE // 2 Is OBJECT STATE? // 3 Is [NP] OBJECT STATE? // 4 [I am/You are] STATE // 5 OBJECT is STATE // 6 [NP] OBJECT is STATE // 7 OBJECT STATE try { GrammarBuilder gb1 = new GrammarBuilder(IsChoices); GrammarBuilder gb4 = new GrammarBuilder(); SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices); gb1.Append(srk); gb4.Append(srk); List <string> stateList = new List <string>(); GrammarBuilder gb2 = new GrammarBuilder("Is"); GrammarBuilder gb3 = new GrammarBuilder("Is"); gb3.Append(nounPrecedentChoices); GrammarBuilder gb6 = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb2.Append(srk); gb3.Append(srk); GrammarBuilder gb5 = new GrammarBuilder(srk); gb6.Append(srk); gb5.Append("is"); gb6.Append("is"); GrammarBuilder gb7 = new GrammarBuilder(srk); //Now the the appropriate states dsResults = OSAESql.RunSQL("SELECT DISTINCT state_label FROM osae_v_object_type_state_list_full WHERE state_label IS NOT NULL"); foreach (DataRow dr in dsResults.Tables[0].Rows) { stateList.Add(dr[0].ToString()); } Choices stateChoices = new Choices(stateList.ToArray()); srk = new SemanticResultKey("PARAM2", stateChoices); gb1.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g1); gb2.Append(srk); Grammar g2 = new Grammar(gb2); g2.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g2); gb3.Append(srk); Grammar g3 = new Grammar(gb3); g3.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g3); gb4.Append(srk); Grammar g4 = new Grammar(gb4); g4.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g4); gb5.Append(srk); Grammar g5 = new Grammar(gb5); g5.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(g5); gb6.Append(srk); Grammar g6 = new Grammar(gb6); g6.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(g6); gb7.Append(srk); Grammar g7 = new Grammar(gb7); g7.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(g7); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, Object State: " + ex.Message, ex); } #endregion #region [Object] [Method] [Parameter] // 1 OBJECT STATE {PARAMETER} try { SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices); GrammarBuilder gb1 = new GrammarBuilder(srk); //Now the the appropriate method List <string> methodList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT method_label FROM osae_v_object_type_method_list_full WHERE method_label IS NOT NULL"); foreach (DataRow dr in dsResults.Tables[0].Rows) { methodList.Add(dr[0].ToString()); } Choices methodChoices = new Choices(methodList.ToArray()); srk = new SemanticResultKey("PARAM2", methodChoices); gb1.Append(srk); gb1.AppendDictation(); Grammar g1 = new Grammar(gb1); g1.Name = "[OBJECT] [METHOD] [PARAMETER]"; oRecognizer.LoadGrammar(g1); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, Object Method Parameter: " + ex.Message, ex); } #endregion #region [OBJECT] [CONTAINER] // 1 OBJECT is in CONTAINER // 2 np OBJECT is in CONTAINER // 3 OBJECT is in np CONTAINER // 4 np OBJECT is in np CONTAINER // 5 I am/You are in CONTAINER // 6 I am/You are in np CONTAINER // 7 is OBJECT in CONTAINER // 8 is np OBJECT in CONTAINER // 9 is OBJECT in np CONTAINER // 10 is np OBJECT in np CONTAINER // 11 am I/are you in CONTAINER // 12 am I/are you in NP CONTAINER // 1 OBJECT is in CONTAINER try { GrammarBuilder gb_GrammarBuilder = new GrammarBuilder(); SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); Grammar g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 2 np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 3 OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 4 np OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 5 [I am/You are] in CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(IsChoices); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 6 [I am/You are] am in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(IsChoices); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 7 is OBJECT in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 8 is np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 9 is OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 10 is np OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 11 [am I/are you] in CONTAINER gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // 12 [am I/are you] in NP CONTAINER gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, Object Container: " + ex.Message, ex); } #endregion #region [OBJECT] [OBJECT TYPE] // 1 is OBJECT np OBJECT TYPE // 2 is np OBJECT np OBJECT TYPE // 3 am I/are you np OBJECT TYPE // is OBJECT np OBJECT TYPE try { GrammarBuilder gb_GrammarBuilder = new GrammarBuilder("is"); SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); Grammar g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // [am I/are you] np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, Object ObjectType: " + ex.Message, ex); } #endregion #region Where/What is [OBJECT] //1 Where is OBJECT //2 Where is NP OBJECT //3 Where am I/You //4 What is OBJECT //5 What is NP OBJECT //6 What am I/You //Where is OBJECT try { GrammarBuilder gb_Single = new GrammarBuilder("Where is"); SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); Grammar g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where is NP OBJECT gb_Single = new GrammarBuilder("Where is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where am [I/you] gb_Single = new GrammarBuilder("Where"); gb_Single.Append(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What is OBJECT gb_Single = new GrammarBuilder("What is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); // What is NP OBJECT gb_Single = new GrammarBuilder("What is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); // What am [I/you] gb_Single = new GrammarBuilder("What"); gb_Single.Append(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, What Is Object:" + ex.Message, ex); } #endregion #region Who is [PRONOUN] //Who [am I/are you] try { GrammarBuilder gb_Single = new GrammarBuilder("Who"); gb_Single.Append(IsChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); Grammar g_Single = new Grammar(gb_Single); g_Single.Name = "Who is [PERSON]"; oRecognizer.LoadGrammar(g_Single); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, Who Is:" + ex.Message, ex); } #endregion #region How is [PRONOUN] //1. How [am I/are you] //2. How is OBJECT try { GrammarBuilder gb1 = new GrammarBuilder("How"); GrammarBuilder gb2 = new GrammarBuilder("How"); gb1.Append(IsChoices); gb2.Append(IsChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices); gb1.Append(srk); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb2.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "How is [OBJECT]"; oRecognizer.LoadGrammar(g1); Grammar g2 = new Grammar(gb2); g2.Name = "How is [OBJECT]"; oRecognizer.LoadGrammar(g2); } catch (Exception ex) { throw new Exception("API.Grammar Voice Grammar, How Is Object:" + ex.Message, ex); } #endregion return(oRecognizer); }
private GrammarBuilder saveLoadCommand() { Choices commands = new Choices(); commands.Add(new SemanticResultValue("save", (int)CommandTypes.Save)); commands.Add(new SemanticResultValue("load", (int)CommandTypes.Load)); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); Choices adjective = new Choices(); adjective.Add("this"); adjective.Add("my"); adjective.Add("the"); adjective.Add("a"); adjective.Add("it"); Choices objects = new Choices(); objects.Add("schedule"); objects.Add("file"); Choices finalPhrase = new Choices(); finalPhrase.Add("for later"); finalPhrase.Add("from a file"); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(commandSemKey); finalCommand.Append(adjective, 0, 1); finalCommand.Append(objects, 0, 1); finalCommand.Append(finalPhrase, 0, 1); return finalCommand; }
private Grammar FlipGrammar() { // Flip Image GrammarBuilder flip = "Flip"; GrammarBuilder image = "Image"; Choices commands = new Choices(flip); SemanticResultKey resultKey = new SemanticResultKey("flip", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(image); Grammar grammar = new Grammar(result); grammar.Name = "Flip Image"; return grammar; }
private Grammar GrayscaleGrammar() { // Change/Convert to grayscale GrammarBuilder changeGrammar = "Change"; GrammarBuilder convertGrammar = "Convert"; GrammarBuilder toGrammar = "To"; GrammarBuilder grayscaleGrammar = "Grayscale"; Choices alternatives = new Choices(changeGrammar, convertGrammar); Choices commands = new Choices(grayscaleGrammar); SemanticResultKey resultKey = new SemanticResultKey("grayscale", commands); GrammarBuilder resultGrayscale = new GrammarBuilder(resultKey); GrammarBuilder result = new GrammarBuilder(alternatives); result.Append(toGrammar); result.Append(resultGrayscale); Grammar grammar = new Grammar(result); grammar.Name = "Convert to Grayscale"; return grammar; }
public static SpeechRecognitionEngine Load_Voice_Grammars(SpeechRecognitionEngine oRecognizer) { Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" }); Choices pronounChoices = new Choices(new string[] { "I", "you" }); Choices possPronounChoices = new Choices(new string[] { "my", "your" }); Choices IsChoices = new Choices(new string[] { "is", "am", "are" }); Choices WhatWhoChoices = new Choices(new string[] { "what is", "who is" }); DataSet dsResults = new DataSet(); #region Build a List of all Objects AND Possessive Objects List<string> objectFullList = new List<string>(); List<string> objectPossessiveList = new List<string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString(); if (!string.IsNullOrEmpty(grammer)) objectFullList.Add(grammer); if (!string.IsNullOrEmpty(possessivegrammer)) objectPossessiveList.Add(possessivegrammer); } Choices objectFullChoices = new Choices(objectFullList.ToArray()); Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray()); #endregion #region Build a List of all Containers List<string> containerList = new List<string>(); //Get All containers dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE container=1"); foreach (DataRow dr in dsResults.Tables[0].Rows) { containerList.Add(dr[0].ToString()); } Choices containerChoices = new Choices(containerList.ToArray()); #endregion #region Build a List of all Object Types List<string> objectTypeList = new List<string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion //Choices are done, now write the grammars #region What is [OBJECT]'s [PROPERTY] //What/Who is OBJECT's PROPERTY //What/Who is NP OBJECT's PROPERTY //What/Who is my/your PROPERTY GrammarBuilder gbWhatIsMyProperty = new GrammarBuilder(WhatWhoChoices); SemanticResultKey srk = new SemanticResultKey("PARAM1", possPronounChoices); gbWhatIsMyProperty.Append(srk); GrammarBuilder gbWhatIsObjectProperty = new GrammarBuilder(WhatWhoChoices); GrammarBuilder gbWhatIsNPObjectProperty = new GrammarBuilder(WhatWhoChoices); gbWhatIsNPObjectProperty.Append(nounPrecedentChoices); List<string> propertyList = new List<string>(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gbWhatIsObjectProperty.Append(srk); gbWhatIsNPObjectProperty.Append(srk); dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property"); foreach (DataRow dr in dsResults.Tables[0].Rows) { propertyList.Add(dr[0].ToString()); } Choices propertyChoices = new Choices(propertyList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); gbWhatIsMyProperty.Append(srk); Grammar gWhatIsMyProperty = new Grammar(gbWhatIsMyProperty); gWhatIsMyProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsMyProperty); gbWhatIsObjectProperty.Append(srk); Grammar gWhatIsObjectProperty = new Grammar(gbWhatIsObjectProperty); gWhatIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsObjectProperty); gbWhatIsNPObjectProperty.Append(srk); Grammar gWhatIsNPObjectProperty = new Grammar(gbWhatIsNPObjectProperty); gWhatIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhatIsNPObjectProperty); #endregion #region OLD Merged with what...Who is [OBJECT]'s [PROPERTY] //Who is OBJECT's PROPERTY //Who is NP OBJECT's PROPERTY //Who is my PROPERTY //Who is your PROPERTY /* GrammarBuilder gbWhoIsMyProperty = new GrammarBuilder("Who is"); srk = new SemanticResultKey("PARAM1", "my"); gbWhoIsMyProperty.Append(srk); GrammarBuilder gbWhoIsYourProperty = new GrammarBuilder("Who is"); srk = new SemanticResultKey("PARAM1", "your"); gbWhoIsYourProperty.Append(srk); foreach (string ot in objectTypeList) { GrammarBuilder gbWhoIsObjectProperty = new GrammarBuilder("Who is"); GrammarBuilder gbWhoIsNPObjectProperty = new GrammarBuilder("Who is"); gbWhoIsNPObjectProperty.Append(nounPrecedentChoices); List<string> objectList = new List<string>(); List<string> propertyList = new List<string>(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gbWhoIsObjectProperty.Append(srk); gbWhoIsNPObjectProperty.Append(srk); //Now the the appropriate properties dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='Object Type' AND property_object_type='PERSON'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { propertyList.Add(dr[0].ToString()); } if (propertyList.Count > 0) { Choices propertyChoices = new Choices(propertyList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); if (ot == "PERSON") { gbWhoIsMyProperty.Append(srk); Grammar gWhoIsMyProperty = new Grammar(gbWhoIsMyProperty); gWhoIsMyProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsMyProperty); } else if (ot == "SYSTEM") { gbWhoIsYourProperty.Append(srk); Grammar gWhoIsYourProperty = new Grammar(gbWhoIsYourProperty); gWhoIsYourProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsYourProperty); } gbWhoIsObjectProperty.Append(srk); Grammar gWhoIsObjectProperty = new Grammar(gbWhoIsObjectProperty); gWhoIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsObjectProperty); gbWhoIsNPObjectProperty.Append(srk); Grammar gWhoIsNPObjectProperty = new Grammar(gbWhoIsNPObjectProperty); gWhoIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]"; oRecognizer.LoadGrammar(gWhoIsNPObjectProperty); } } } */ #endregion //Too slow #region [Object] [State] /* // 1 Are you STATE // 2 Am I STATE // 3 Is OBJECT STATE? // 4 Is [NP] OBJECT STATE? // 5 You are STATE // 6 I am STATE // 7 OBJECT is STATE // 8 [NP] OBJECT is STATE GrammarBuilder gb1 = new GrammarBuilder("Are"); GrammarBuilder gb5 = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "you"); gb1.Append(srk); gb5.Append(srk); GrammarBuilder gb2 = new GrammarBuilder("Am"); GrammarBuilder gb6 = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", "I"); gb2.Append(srk); gb6.Append(srk); //builder.Append(objectChoices); foreach (string ot in objectTypeList) { List<string> stateList = new List<string>(); GrammarBuilder gb3 = new GrammarBuilder("Is"); GrammarBuilder gb4 = new GrammarBuilder("Is"); gb4.Append(nounPrecedentChoices); GrammarBuilder gbNPObjectIsState = new GrammarBuilder(nounPrecedentChoices); //Get All objects of the current Object Type List<string> objectList = new List<string>(); dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); srk = new SemanticResultKey("PARAM1", objectChoices); gb3.Append(srk); gb4.Append(srk); GrammarBuilder gbObjectIsState = new GrammarBuilder(srk); gbNPObjectIsState.Append(srk); gbObjectIsState.Append("is"); gbNPObjectIsState.Append("is"); //Now the the appropriate states dsResults = OSAESql.RunSQL("SELECT state_label FROM osae_v_object_type_state_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { stateList.Add(dr[0].ToString()); } if (stateList.Count > 0) { Choices stateChoices = new Choices(stateList.ToArray()); srk = new SemanticResultKey("PARAM2", stateChoices); if (ot == "PERSON") { gb2.Append(srk); Grammar gAmIState = new Grammar(gb2); gAmIState.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(gAmIState); } else if (ot == "SYSTEM") { gb1.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g1); gb5.Append(srk); Grammar g5 = new Grammar(gb5); g5.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g5); } gb3.Append(srk); Grammar gIsObjectState = new Grammar(gb3); gIsObjectState.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(gIsObjectState); gb4.Append(srk); Grammar gIsNPObjectState = new Grammar(gb4); gIsNPObjectState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gIsNPObjectState); gbObjectIsState.Append(srk); Grammar gObjectIsState = new Grammar(gbObjectIsState); gObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gObjectIsState); gbNPObjectIsState.Append(srk); Grammar gNPObjectIsState = new Grammar(gbNPObjectIsState); gNPObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gNPObjectIsState); } } } */ #endregion #region New [Object] [State] // 1 [Am I/Are you] STATE // 3 Is OBJECT STATE? // 4 Is [NP] OBJECT STATE? // 5 [I am/You are] STATE // 7 OBJECT is STATE // 8 [NP] OBJECT is STATE GrammarBuilder gb1 = new GrammarBuilder(IsChoices); GrammarBuilder gb5 = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", pronounChoices); gb1.Append(srk); gb5.Append(srk); List<string> stateList = new List<string>(); GrammarBuilder gb3 = new GrammarBuilder("Is"); GrammarBuilder gb4 = new GrammarBuilder("Is"); gb4.Append(nounPrecedentChoices); GrammarBuilder gb8 = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb3.Append(srk); gb4.Append(srk); GrammarBuilder gb7 = new GrammarBuilder(srk); gb8.Append(srk); gb7.Append("is"); gb8.Append("is"); //Now the the appropriate states dsResults = OSAESql.RunSQL("SELECT DISTINCT state_label FROM osae_v_object_type_state_list_full"); foreach (DataRow dr in dsResults.Tables[0].Rows) { stateList.Add(dr[0].ToString()); } Choices stateChoices = new Choices(stateList.ToArray()); srk = new SemanticResultKey("PARAM2", stateChoices); gb1.Append(srk); Grammar g1 = new Grammar(gb1); g1.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g1); gb5.Append(srk); Grammar g5 = new Grammar(gb5); g5.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(g5); gb3.Append(srk); Grammar gIsObjectState = new Grammar(gb3); gIsObjectState.Name = "Is [OBJECT] [STATE]"; oRecognizer.LoadGrammar(gIsObjectState); gb4.Append(srk); Grammar gIsNPObjectState = new Grammar(gb4); gIsNPObjectState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gIsNPObjectState); gb7.Append(srk); Grammar gObjectIsState = new Grammar(gb7); gObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gObjectIsState); gb8.Append(srk); Grammar gNPObjectIsState = new Grammar(gb8); gNPObjectIsState.Name = "[OBJECT] is [STATE]"; oRecognizer.LoadGrammar(gNPObjectIsState); #endregion #region [OBJECT] [CONTAINER] // OBJECT is in CONTAINER // np OBJECT is in CONTAINER // OBJECT is in np CONTAINER // np OBJECT is in np CONTAINER // I am in CONTAINER // I am in np CONTAINER // You are in CONTAINER // You are in np CONTAINER // is OBJECT in CONTAINER // is np OBJECT is in CONTAINER // is OBJECT in np CONTAINER // is np OBJECT in np CONTAINER // am I in CONTAINER // am I in NP CONTAINER // are you in CONTAINER // are you in np CONTAINER // OBJECT is in CONTAINER GrammarBuilder gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); Grammar g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // np OBJECT is in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // [I am/You are] in CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(IsChoices); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // [I am/You are] am in np CONTAINER gb_GrammarBuilder = new GrammarBuilder(); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(IsChoices); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "[OBJECT] is in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is OBJECT in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT is in CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("is in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT in np CONTAINER gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // [am I/are you] in CONTAINER gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); // [am I/are you] in NP CONTAINER gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append("in"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", containerChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] in [CONTAINER]"; oRecognizer.LoadGrammar(g_Grammar); #endregion #region [OBJECT] [OBJECT TYPE] // is OBJECT np OBJECT TYPE // is np OBJECT np OBJECT TYPE // am I np OBJECT TYPE // are you np OBJECT TYPE // is OBJECT np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // is np OBJECT np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder("is"); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); // [am I/are you] np OBJECT TYPE gb_GrammarBuilder = new GrammarBuilder(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_GrammarBuilder.Append(srk); gb_GrammarBuilder.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM2", objectTypeChoices); gb_GrammarBuilder.Append(srk); g_Grammar = new Grammar(gb_GrammarBuilder); g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]"; oRecognizer.LoadGrammar(g_Grammar); #endregion #region Where/What is [OBJECT] //Where is OBJECT //Where is NP OBJECT //Where am I/You //What is OBJECT //What is NP OBJECT //What am I/You //Where is OBJECT GrammarBuilder gb_Single = new GrammarBuilder("Where is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); Grammar g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where is NP OBJECT gb_Single = new GrammarBuilder("Where is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //Where am [I/you] gb_Single = new GrammarBuilder("Where"); gb_Single.Append(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Where is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); //What is OBJECT gb_Single = new GrammarBuilder("What is"); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); // What is NP OBJECT gb_Single = new GrammarBuilder("What is"); gb_Single.Append(nounPrecedentChoices); srk = new SemanticResultKey("PARAM1", objectFullChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); // What am [I/you] gb_Single = new GrammarBuilder("What"); gb_Single.Append(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "What is [OBJECT]"; oRecognizer.LoadGrammar(g_Single); #endregion #region Who is [PRONOUN] //Who [am I/are you] gb_Single = new GrammarBuilder("Who"); gb_Single.Append(IsChoices); srk = new SemanticResultKey("PARAM1", pronounChoices); gb_Single.Append(srk); g_Single = new Grammar(gb_Single); g_Single.Name = "Who is [PERSON]"; oRecognizer.LoadGrammar(g_Single); #endregion return oRecognizer; }
private Grammar UndoGrammar() { // Undo Actions GrammarBuilder undo = "Undo"; GrammarBuilder action = "Action"; Choices commands = new Choices(undo); SemanticResultKey resultKey = new SemanticResultKey("undo", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(action); Grammar grammar = new Grammar(result); grammar.Name = "Undo Action"; return grammar; }
private Grammar ActionsGrammar() { // Actions Grammar var actions = new Choices(); string[] action_options = new string[] {"Show", "Switch" }; for (var i = 0; i < action_options.Length; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(action_options[i], action_options[i]); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); actions.Add(resultValueBuilder); } SemanticResultKey resultKeyActions = new SemanticResultKey("action", actions); GrammarBuilder actionsGrammar = new GrammarBuilder(resultKeyActions); // Commands Grammar var commands = new Choices(); string[] command_options = new string[] {"Color", "Depth", "Skeleton"}; for (var i = 0; i < command_options.Length; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(command_options[i], command_options[i]); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); commands.Add(resultValueBuilder); } SemanticResultKey resultKeyCommands = new SemanticResultKey("command", commands); GrammarBuilder commandsGrammar = new GrammarBuilder(resultKeyCommands); actionsGrammar.Append(commandsGrammar); Grammar grammar = new Grammar(actionsGrammar); grammar.Name = "Change the select box"; return grammar; }
private Grammar RotateGrammar() { // Rotate Image GrammarBuilder rotate = "Rotate"; Choices commands = new Choices(rotate); SemanticResultKey resultKey = new SemanticResultKey("rotate", commands); GrammarBuilder image = "Image"; Choices text = new Choices(image); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(text); Grammar grammar = new Grammar(result); grammar.Name = "Rotate Image"; return grammar; }
private GrammarBuilder semesterCommand() { //<pleasantries> <command> <Semester>? <Year>? Choices commands = new Choices(); commands.Add(new SemanticResultValue("set semester", (int)CommandTypes.SetSemester)); commands.Add(new SemanticResultValue("semester", (int)CommandTypes.SetSemester)); commands.Add(new SemanticResultValue("go to", (int)CommandTypes.SetSemester)); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(commandSemKey, 0, 1); finalCommand.Append(this.semester); return finalCommand; }
private Grammar ColorFilterGrammar() { // Add/Set Filter Choices GrammarBuilder addGrammar = "Add"; GrammarBuilder setGrammar = "Set"; GrammarBuilder filterGrammar = "Filter"; Choices colorChoice = new Choices(); foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) { SemanticResultValue choiceResultValue = new SemanticResultValue(colorName, Color.FromName(colorName).ToArgb()); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); colorChoice.Add(resultValueBuilder); } SemanticResultKey resultKey = new SemanticResultKey("colorFilter", colorChoice); GrammarBuilder resultContrast = new GrammarBuilder(resultKey); Choices alternatives = new Choices(addGrammar, setGrammar); GrammarBuilder result = new GrammarBuilder(alternatives); result.Append(filterGrammar); result.Append(resultContrast); Grammar grammar = new Grammar(result); grammar.Name = "Set Contrast"; return grammar; }
public static SpeechRecognitionEngine Load_Text_Only_Grammars(SpeechRecognitionEngine oRecognizer) { DataSet dsResults = new DataSet(); #region Build a List of all Objects AND Possessive Objects List<string> objectFullList = new List<string>(); List<string> objectPossessiveList = new List<string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString(); if (!string.IsNullOrEmpty(grammer)) objectFullList.Add(grammer); if (!string.IsNullOrEmpty(possessivegrammer)) objectPossessiveList.Add(possessivegrammer); } Choices objectFullChoices = new Choices(objectFullList.ToArray()); Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray()); #endregion #region Build a List of all Object Types List<string> objectTypeList = new List<string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion #region [OBJECT]'s [PROPERTY] is [VALUE] //OBJECT's PROPERTY is [VALUE] foreach (string ot in objectTypeList) { List<string> objectList = new List<string>(); GrammarBuilder gbObjectPropertyIs = new GrammarBuilder(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); SemanticResultKey srk = new SemanticResultKey("PARAM1", objectChoices); gbObjectPropertyIs.Append(srk); //Now the the appropriate properties DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype"); foreach (DataRow drType in dsPropType.Tables[0].Rows) { List<string> propertyList = new List<string>(); DataSet dsPropName = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype"); foreach (DataRow drName in dsPropName.Tables[0].Rows) { propertyList.Add(drName["property_name"].ToString()); } Choices propertyChoices = new Choices(propertyList.ToArray()); if (drType["property_datatype"].ToString().ToUpper() == "STRING") { GrammarBuilder dictation = new GrammarBuilder(); dictation.AppendDictation(); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT") { srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE") { List<string> propertyOTList = new List<string>(); DataSet dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'"); foreach (DataRow drName in dsPropObjectType.Tables[0].Rows) { propertyOTList.Add(drName["object_name"].ToString()); } Choices propertyOTChoices = new Choices(propertyOTList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } } } } #endregion return oRecognizer; }
private Grammar CropCancelGrammar() { // Cancel Crop GrammarBuilder cancel = "Cancel"; GrammarBuilder crop = "Crop"; Choices commands = new Choices(cancel); SemanticResultKey resultKey = new SemanticResultKey("cancel_crop", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(crop); Grammar grammar = new Grammar(result); grammar.Name = "Cancel Crop"; return grammar; }
private Grammar CropGrammar() { // Crop Image GrammarBuilder crop = "Crop"; GrammarBuilder image = "Image"; Choices commands = new Choices(crop); SemanticResultKey resultKey = new SemanticResultKey("crop", commands); GrammarBuilder result = new GrammarBuilder(resultKey); result.Append(image); Grammar grammar = new Grammar(result); grammar.Name = "Crop Image"; return grammar; }
private Grammar CropPositionGrammar() { // Change/Set Crop Position to X and Y var choicesX = new Choices(); var choicesY = new Choices(); for (var i = 0; i <= LastImage().Width; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); choicesX.Add(resultValueBuilder); } for (var i = 0; i <= LastImage().Height; i++) { SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); choicesY.Add(resultValueBuilder); } GrammarBuilder changeGrammar = "Change"; GrammarBuilder setGrammar = "Set"; GrammarBuilder cropGrammar = "Crop"; GrammarBuilder positionGrammar = "Position"; GrammarBuilder toGrammar = "To"; GrammarBuilder andGrammar = "And"; SemanticResultKey resultKeyX = new SemanticResultKey("crop_position_x", choicesX); GrammarBuilder resultCropX = new GrammarBuilder(resultKeyX); SemanticResultKey resultKeyY = new SemanticResultKey("crop_position_y", choicesY); GrammarBuilder resultCropY = new GrammarBuilder(resultKeyY); Choices alternatives = new Choices(changeGrammar, setGrammar); GrammarBuilder result = new GrammarBuilder(alternatives); result.Append(cropGrammar); result.Append(positionGrammar); result.Append(toGrammar); result.Append(resultCropX); result.Append(andGrammar); result.Append(resultCropY); Grammar grammar = new Grammar(result); grammar.Name = "Set Crop Position"; return grammar; }
/// <summary> /// Called by the constructor. Sets up the kinect audio source, the grammar and the speech engine. /// </summary> private void InitializeSpeech() { RecognizerInfo ri = InitializeKinectAudio(); // Create a set of menu options choices, create a SemanticResultKey and create a grammarBuilder Choices menuOptions = new Choices(new String[] { "new game", "load game", "options", "quit", "game 1", "game 2", "game 42", "game 666", "campaign", "zen mode", "score mode", "multiplayer", "volume", "difficulty", "screen brightness", "cancel" }); SemanticResultKey menuOptionsKey = new SemanticResultKey("menuOptions", menuOptions); GrammarBuilder menuGrammar = new GrammarBuilder(menuOptionsKey); // Create a set of command choices, create a SemanticResultKey and create a grammarBuilder Choices command = new Choices(new String[] { "kinect" }); SemanticResultKey commandKey = new SemanticResultKey("command", command); GrammarBuilder commandGrammar = new GrammarBuilder(commandKey); //By combining the grammar builders, the user always has to say the command before the menu options GrammarBuilder combinedGrammarBuilders = commandGrammar + menuGrammar; Grammar combinedGrammar = new Grammar(combinedGrammarBuilders); speechEngine = new SpeechRecognitionEngine(); speechEngine.LoadGrammar(combinedGrammar); Stream s = source.Start(); speechEngine.SetInputToAudioStream(s, new SpeechAudioFormatInfo( EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); speechEngine.RecognizeAsync(RecognizeMode.Multiple); Console.WriteLine("Speech engine running"); }
private GrammarBuilder bookmarkCommand() { Choices commands = new Choices(); SemanticResultValue commandSRV; commandSRV = new SemanticResultValue("bookmark", (int)CommandTypes.Bookmark); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(this.pleasantries, 0, 1); finalCommand.Append(commandSemKey); finalCommand.Append(this.course, 0, 1); return finalCommand; }
public static SpeechRecognitionEngine Load_Text_Only_Grammars(SpeechRecognitionEngine oRecognizer) { DataSet dsResults = new DataSet(); #region Build a List of all Objects AND Possessive Objects List <string> objectFullList = new List <string>(); List <string> objectPossessiveList = new List <string>(); //Get All objects dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full"); for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++) { string grammer = dsResults.Tables[0].Rows[i][0].ToString(); string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString(); if (!string.IsNullOrEmpty(grammer)) { objectFullList.Add(grammer); } if (!string.IsNullOrEmpty(possessivegrammer)) { objectPossessiveList.Add(possessivegrammer); } } Choices objectFullChoices = new Choices(objectFullList.ToArray()); Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray()); #endregion #region Build a List of all Object Types List <string> objectTypeList = new List <string>(); dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectTypeList.Add(dr[0].ToString()); } Choices objectTypeChoices = new Choices(objectTypeList.ToArray()); #endregion #region [OBJECT]'s [PROPERTY] is [VALUE] //OBJECT's PROPERTY is [VALUE] foreach (string ot in objectTypeList) { List <string> objectList = new List <string>(); GrammarBuilder gbObjectPropertyIs = new GrammarBuilder(); //Get All objects of the current Object Type dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'"); foreach (DataRow dr in dsResults.Tables[0].Rows) { objectList.Add(dr[0].ToString()); } if (objectList.Count > 0) // Only bother with this object type if there are objects using it { Choices objectChoices = new Choices(objectList.ToArray()); SemanticResultKey srk = new SemanticResultKey("PARAM1", objectChoices); gbObjectPropertyIs.Append(srk); //Now the the appropriate properties DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype"); foreach (DataRow drType in dsPropType.Tables[0].Rows) { List <string> propertyList = new List <string>(); DataSet dsPropName = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype"); foreach (DataRow drName in dsPropName.Tables[0].Rows) { propertyList.Add(drName["property_name"].ToString()); } Choices propertyChoices = new Choices(propertyList.ToArray()); if (drType["property_datatype"].ToString().ToUpper() == "STRING") { GrammarBuilder dictation = new GrammarBuilder(); dictation.AppendDictation(); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT") { srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE") { List <string> propertyOTList = new List <string>(); DataSet dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'"); foreach (DataRow drName in dsPropObjectType.Tables[0].Rows) { propertyOTList.Add(drName["object_name"].ToString()); } Choices propertyOTChoices = new Choices(propertyOTList.ToArray()); srk = new SemanticResultKey("PARAM2", propertyChoices); gbObjectPropertyIs.Append(srk); gbObjectPropertyIs.Append("is"); gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices)); Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs); gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]"; oRecognizer.LoadGrammar(gObjectPropertyIs); } } } } #endregion return(oRecognizer); }