/***** 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 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; }
private Choices CreateSampleChoices() { var val1 = new SemanticResultValue("калькулятор", "calc"); var val2 = new SemanticResultValue("проводник", "explorer"); var val3 = new SemanticResultValue("блокнот", "notepad"); var val4 = new SemanticResultValue("пэйнт", "mspaint"); var va15 = new SemanticResultValue("командную строку", "cmd"); var va16 = new SemanticResultValue("яндекс", "https://yandex.ru"); var va17 = new SemanticResultValue("гугл", "www.google.ru"); var va18 = new SemanticResultValue("вконтакте", "https://vk.com/"); var va19 = new SemanticResultValue("однокласники", "https://ok.ru"); var va20 = new SemanticResultValue("ютуп", "www.youtube.com"); var va21 = new SemanticResultValue("ворд", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Word 2010.lnk"); var va22 = new SemanticResultValue("эксэль", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Excel 2010.lnk"); var va23 = new SemanticResultValue("поврпоинт", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft PowerPoint 2010.lnk"); var va24 = new SemanticResultValue("эксес", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Access 2010.lnk"); var va25 = new SemanticResultValue("подключение к удаленному рабочему столу", "mstsc"); var va26 = new SemanticResultValue("проигрыватель", "wmplayer"); var va27 = new SemanticResultValue("таблицу символов", "charmap"); var va28 = new SemanticResultValue("экранную лупу", "Magnify"); var va29 = new SemanticResultValue("диспетчер задач", "Taskmgr"); var va30 = new SemanticResultValue("редактор реестра", "regedit"); var va31 = new SemanticResultValue("визуальную студию", "devenv"); var va32 = new SemanticResultValue("матрицу", @"C:\Users\Acer\Desktop\Матрица\матрица.bat"); var va33 = new SemanticResultValue("доту", @"steam://rungameid/570"); return(new Choices(val1, val2, val3, val4, va15, va16, va17, va18, va19, va20, va21, va22, va23, va24, va25, va26, va27, va28, va29, va30, va31, va32, va33)); }
/* * This method is to construct the new grammar from the current endpoint, and load it into SR. */ public void GenerateAndLoadOnGoingGrammars(string[] list, int beginIndex) { UnloadOnGoingGrammar(); int maxchoice = MAX_WORDS_IN_SPEECH; if (list.Length - beginIndex < MAX_WORDS_IN_SPEECH) { maxchoice = list.Length - beginIndex; } for (int i = beginIndex; i < list.Length && i < beginIndex + MAX_WORDS_IN_SPEECH; i++) { string ea = ""; for (int k = beginIndex; k <= i; k++) { ea += list[k] + " "; } ea = ea.TrimEnd(); SemanticResultValue temp = new SemanticResultValue(ea, beginIndex); GrammarBuilder gb = new GrammarBuilder(new SemanticResultKey("startIndex", temp)); Grammar storyGrammar = new Grammar(gb); recEngine.LoadGrammarAsync(storyGrammar); onGoingGrammars.Add(storyGrammar); } enableSR(true); }
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 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 static void loadGrammar(Elite.MessageBus messageBus) { SpeechRecognitionEngine recognitionEngine = messageBus.recognitionEngine; recognitionEngine.SetInputToDefaultAudioDevice(); recognitionEngine.InitialSilenceTimeout = TimeSpan.FromSeconds(5); recognitionEngine.EndSilenceTimeout = TimeSpan.FromSeconds(1.5); recognitionEngine.BabbleTimeout = TimeSpan.FromSeconds(5); DateTime startTime = DateTime.Now; Debug.Write("Begin loading star system grammar"); bool grammarLoaded = true; int counter = 0; try { GrammarBuilder gb = new GrammarBuilder(); gb.Culture = messageBus.recognitionEngineLang; Choices systemChoice = new Choices(); foreach (string system in messageBus.systemIndex["systems"].Keys) { List <string> alternates = alternatePhonetics(system); foreach (string alternate in alternates) { counter += 1; GrammarBuilder systemBuilder = new GrammarBuilder(alternate); systemBuilder.Culture = messageBus.recognitionEngineLang; SemanticResultValue systemSemantic = new SemanticResultValue(systemBuilder, system); systemChoice.Add(new GrammarBuilder(systemSemantic)); } } gb.Append(systemChoice); Grammar grammar = new Grammar(gb); grammar.Name = "populated"; recognitionEngine.LoadGrammar(grammar); Debug.Write("Star system recognition engine rules loaded: " + counter); } catch (Exception ex) { Debug.Write(ex.ToString()); grammarLoaded = false; Debug.Write("Error: Unable to load grammar"); Announcements.errorAnnouncement(messageBus, "Unable to load star system recognition engine"); } if (grammarLoaded) { DateTime endTime = DateTime.Now; TimeSpan loadTime = endTime - startTime; Debug.Write("Finished loading star system grammar. Load time: " + loadTime.Seconds.ToString() + " seconds"); Debug.Write("Recognition Engine - Audio Level: " + recognitionEngine.AudioLevel.ToString()); Debug.Write("Recognition Engine - Audio Format: " + recognitionEngine.AudioFormat.ToString()); Debug.Write("Recognition Engine - Grammars Loaded: " + recognitionEngine.Grammars.Count.ToString()); Debug.Write("Recognition Engine - Recognizer Information: " + recognitionEngine.RecognizerInfo.Name.ToString()); Announcements.engineAnnouncement(messageBus); } messageBus.grammarLoaded = grammarLoaded; }
private Choices CreateSampleChoices() { var val1 = new SemanticResultValue("калькулятор", "calc"); var val2 = new SemanticResultValue("проводник", "explorer"); var val3 = new SemanticResultValue("блокнот", "notepad"); var val4 = new SemanticResultValue("пэйнт", "mspaint"); var val5 = new SemanticResultValue("дэмопример", "ConsoleApplication1.exe"); return(new Choices(val1, val2, val3, val4, val5)); }
/* * This method will create the grammar from the given list of text and annotation, and activiate it on the fly. * This is happening in runtime, while the SR is running; it might downgrade the performance if the list increased. */ public void GenerateAndLoadGrammars(string[] listText, string[] annotations) { String timeStamp = GetTimestamp(DateTime.Now); Debug.WriteLine("Before load grammar time:" + timeStamp); for (int i = 0; i < listText.Length; i++) { if (i == 0 || (i > 0 && (listText[i - 1].Contains("?") || listText[i - 1].Contains(".") || listText[i - 1].Contains("!")))) { for (int j = i; j < listText.Length && j < i + MAX_WORDS_IN_SPEECH; j++) { string ea = ""; List <string> anno = new List <string>(); for (int k = i; k <= j; k++) { ea += listText[k] + " "; if (!anno.Contains(annotations[k])) { anno.Add(annotations[k]); } } string annotate = ""; foreach (string ann in anno) { annotate += ann + ";"; } ea = ea.TrimEnd(); SemanticResultValue temp = new SemanticResultValue(ea, i); GrammarBuilder gb = new GrammarBuilder(new SemanticResultKey("startIndex", temp)); SemanticResultValue ano = new SemanticResultValue(annotate); gb.Append(new SemanticResultKey("annotation", ano)); //gb.Append(temp); Grammar storyGrammar = new Grammar(gb); //storyGrammar.Name = i + ":" + j; recEngine.LoadGrammarAsync(storyGrammar); currentStoryGrammars.Add(storyGrammar); //choose.Add(gb); allDefaultStartIndexes.Add(i); } } } String after = GetTimestamp(DateTime.Now); Debug.WriteLine("after load grammar time:" + after); }
private Choices VoiceController() { var com1 = new SemanticResultValue("калькулятор", "calc"); var com2 = new SemanticResultValue("Вижуал Студио", @"D:\Microsoft Visual Studio 2017\Common7\IDE\devenv.exe"); var com3 = new SemanticResultValue("Гугл", @"C:\Program Files (x86)\Google\Chrome\chrome.exe"); var com4 = new SemanticResultValue("Телеграмм", @"D:\Telegram Desktop\Telegram.exe"); var com5 = new SemanticResultValue("диспетчер задач", "Taskmgr"); var com6 = new SemanticResultValue("Кью тэ", @"D:\Qt\Tools\QtCreator\bin\qtcreator.exe"); var com7 = new SemanticResultValue("юнити", @"D:\Установочные компоненты для Unity\Editor\Unity.exe"); var com8 = new SemanticResultValue("Андроид Студио", @"D:\Android Studio\bin\studio.exe"); var com9 = new SemanticResultValue("командную строку", "cmd"); var com10 = new SemanticResultValue("редактор реестра", "regedit"); return(new Choices(com1, com2, com3, com4, com5, com6, com7, com8, com9, com10)); }
/// <summary> /// Создание грамматики для распознавания речи /// </summary> /// <param name="semanticResult"></param> /// <returns></returns> private Choices CreateSample(List <Tuple <string, string> > semanticResult) { var grammarBuilders = new GrammarBuilder[semanticResult.Count]; int index = 0; foreach (var currentSemantic in semanticResult) { grammarBuilders[index] = new SemanticResultValue(currentSemantic.Item1, currentSemantic.Item2); index++; } return(new Choices(grammarBuilders)); }
public static GrammarBuilder enableProfile(List <String> profileNames) { GrammarBuilder gb = new GrammarBuilder(); Choices profileChoices = new Choices(); SemanticResultValue semval = new SemanticResultValue("semval_ENABLEPROFILE", "Enable Profile"); gb.Append(new SemanticResultKey("semkey_METACONTROLNAME", semval)); foreach (String profile in profileNames) { profileChoices.Add(new SemanticResultValue("semval_" + profile.ToUpper(), profile)); } gb.Append(new SemanticResultKey("semkey_PARAMETER1", profileChoices)); //////////////////NOT DONE YET }
//----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- #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()); }
static private Choices CreatePhraseValuePairChoices(string[] command, string[] value) { Choices c = new Choices(); if (command.Length != value.Length) { throw new Exception("MainGrammar.CreatePhraseValuePair(): arguments have different lengths (must be the same)"); } else { SemanticResultValue[] outArray = new SemanticResultValue[command.Length]; for (int i = 0; i < command.Length; i++) { c.Add(new SemanticResultValue(command[i], value[i])); } } return(c); }
private static GrammarBuilder createMetaControlGB(String metaControlName, params object[] parameters) { GrammarBuilder gb = new GrammarBuilder(); SemanticResultValue controlName_val = new SemanticResultValue(/*phrase*/ metaControlName, /*value*/ metaControlName); List <object> paramVal = new List <object>(); // Should be a SemanticResultValue OR Choices (with SemanticResultValues in it) for (int i = 0; i < parameters.Length; i++) { if (parameters[i] is String) { paramVal.Add(new SemanticResultValue(/*phrase*/ (String)parameters[i], /*value*/ parameters[i])); } else if (parameters[i] is List <String> ) { Choices theseChoices = new Choices(); foreach (String str in (List <String>)parameters[i]) { theseChoices.Add(new SemanticResultValue(/*phrase*/ str, /*value*/ str)); ///////// if there is an error, check here } paramVal.Add(theseChoices); } else { throw new ArgumentException("createMetaControl() should only take Strings or lists of Strings as parameters (beyond the first argument which must be a string)"); } } gb.Append(new SemanticResultKey("METACONTROLNAME", controlName_val)); for (int i = 0; i < paramVal.Count; i++) { if (paramVal[i] is Choices) { gb.Append(new SemanticResultKey("PARAMETER" + (i + 1).ToString(), (Choices)paramVal[i])); } else if (paramVal[i] is SemanticResultValue) { gb.Append(new SemanticResultKey("PARAMETER" + (i + 1).ToString(), (SemanticResultValue)paramVal[i])); } } return(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); }
/// <summary> /// Builds a grammar object from a dictionary of text-to-meaning mappings. /// </summary> /// <param name="dictionary">The dictionary with the mappings</param> /// <returns>The constructed grammar object</returns> public static Grammar BuildDictionaryGrammar(Dictionary <string, string> dictionary) { if (dictionary.Count == 0) { return(null); } Choices choices = new Choices(); foreach (KeyValuePair <string, string> entry in dictionary) { if (string.IsNullOrEmpty(entry.Key) && string.IsNullOrEmpty(entry.Value)) { continue; } SemanticResultValue phraseToSemanticsMapping = new SemanticResultValue(entry.Key, entry.Value); choices.Add(new GrammarBuilder(phraseToSemanticsMapping)); } return(new Grammar(new GrammarBuilder(choices))); }
/***** 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 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); }
/** * 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 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; }
public void addCommentToLocation(string streamOfComment, string latitude , string longitude) { SpeechAudioFormatInfo audioType = new SpeechAudioFormatInfo(1000,AudioBitsPerSample.Sixteen,AudioChannel.Mono); SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo="); byte[] streamString; Locations location = new Locations(); byte[] buffer = new byte[10]; MemoryStream stream = new MemoryStream(); using (SpeechRecognitionEngine speechRecongnizeEngine = new SpeechRecognitionEngine()) { location.latitude = Convert.ToDouble(latitude); location.longitude = Convert.ToDouble(longitude); locationsServices.addLocations(location); streamString = serializer.Deserialize<byte[]>(streamOfComment); buffer = new byte[streamString.Count()]; stream.Write(buffer, 0, buffer.Length); // Add a handler for the LoadGrammarCompleted event. speechRecongnizeEngine.LoadGrammarCompleted += new EventHandler<LoadGrammarCompletedEventArgs>(speechRecongnizeEngine_LoadGrammarCompleted); // Add a handler for the SpeechRecognized event. speechRecongnizeEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(speechRecongnizeEngine_SpeechRecognized); speechRecongnizeEngine.LoadGrammar(new DictationGrammar()); speechRecongnizeEngine.SetInputToAudioStream(stream, audioType); speechRecongnizeEngine.RecognizeAsync(RecognizeMode.Multiple); } using (SpeechRecognizer recognizer = new SpeechRecognizer()) { // Create SemanticResultValue objects that contain cities and airport codes. SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD"); SemanticResultValue boston = new SemanticResultValue("Boston", "BOS"); SemanticResultValue miami = new SemanticResultValue("Miami", "MIA"); SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW"); // Create a Choices object and add the SemanticResultValue objects, using // implicit conversion from SemanticResultValue to GrammarBuilder Choices cities = new Choices(); cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas })); // Build the phrase and add SemanticResultKeys. GrammarBuilder chooseCities = new GrammarBuilder(); chooseCities.Append("I want to fly from"); chooseCities.Append(new SemanticResultKey("origin", cities)); chooseCities.Append("to"); chooseCities.Append(new SemanticResultKey("destination", cities)); // Build a Grammar object from the GrammarBuilder. Grammar bookFlight = new Grammar(chooseCities); bookFlight.Name = "Book Flight"; // Add a handler for the LoadGrammarCompleted event. recognizer.LoadGrammarCompleted += new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted); // Add a handler for the SpeechRecognized event. recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized); // Attach event handlers for recognition events. recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>( SpeechRecognizedHandler); recognizer.EmulateRecognizeCompleted += new EventHandler<EmulateRecognizeCompletedEventArgs>( EmulateRecognizeCompletedHandler); // Load the grammar object to the recognizer. recognizer.LoadGrammarAsync(bookFlight); } }
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; }
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 helpCommand() { Choices commands = new Choices(); SemanticResultValue commandSRV; commandSRV = new SemanticResultValue("Help", (int)CommandTypes.Help); commands.Add(commandSRV); commandSRV = new SemanticResultValue("Help me", (int)CommandTypes.Help); commands.Add(commandSRV); commandSRV = new SemanticResultValue("What do I do", (int)CommandTypes.Help); commands.Add(commandSRV); commandSRV = new SemanticResultValue("I don't know what to say", (int)CommandTypes.Help); commands.Add(commandSRV); commandSRV = new SemanticResultValue("I do not know what to say", (int)CommandTypes.Help); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(commandSemKey); return finalCommand; }
/// <summary> /// Creates a grammar for all the recognized commands and values. /// </summary> /// <returns>A grammar for the EESpeak application</returns> private Grammar CreateGrammar() { // Exit grammar GrammarBuilder exitGrammar = new GrammarBuilder(new Choices(exitStrings)); // Enable speech GrammarBuilder enableSpeechGrammar = new GrammarBuilder(enableSpeechCommand); // Disable speech GrammarBuilder disableSpeechGrammar = new GrammarBuilder(disableSpeechCommand); // Metric Prefixes GrammarBuilder toggleMetricPrefixGrammar = new GrammarBuilder(new Choices(toggleMetricPrefixes)); // 4-band lookup // Create color band semantics Choices resistorColorChoices = new Choices(); GrammarBuilder resistorColorValues = new GrammarBuilder(); foreach (string s in resistorColors) { SemanticResultValue temp = new SemanticResultValue(s, s); resistorColorChoices.Add(temp); resistorColorValues.Append(temp); } GrammarBuilder fourBandGrammar = new GrammarBuilder(new Choices(fourBandStrings)); fourBandGrammar.Append(new SemanticResultKey("first_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("second_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("third_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("fourth_band", resistorColorChoices)); // 5-band lookup GrammarBuilder fiveBandGrammar = new GrammarBuilder(new Choices(fiveBandStrings)); fiveBandGrammar.Append(new SemanticResultKey("first_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("second_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("third_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("fourth_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("fifth_band", resistorColorChoices)); // EIA (2 digits, one letter) lookup // Create EIA semantics Choices eiaNumberChoices = new Choices(); GrammarBuilder eiaNumberValues = new GrammarBuilder(); for (int i = 0; i < eiaNumbers.Length; i++) { SemanticResultValue temp = new SemanticResultValue(eiaNumbers[i], i); eiaNumberChoices.Add(temp); eiaNumberValues.Append(temp); } Choices eiaLetterChoices = new Choices(); GrammarBuilder eiaLetterValues = new GrammarBuilder(); foreach (string s in eiaLetters) { SemanticResultValue temp = new SemanticResultValue(s, s); eiaLetterChoices.Add(temp); eiaLetterValues.Append(temp); } Choices eiaPhonemeChoices = new Choices(); GrammarBuilder eiaLetterPhonemes = new GrammarBuilder(); foreach (string s in eiaPhonemes) { SemanticResultValue temp = new SemanticResultValue(s, s); eiaPhonemeChoices.Add(temp); eiaLetterPhonemes.Append(temp); } GrammarBuilder eiaGrammar = new GrammarBuilder(new Choices(eiaCommandStrings)); eiaGrammar.Append(new SemanticResultKey("first_number", eiaNumberChoices)); eiaGrammar.Append(new SemanticResultKey("second_number", eiaNumberChoices)); eiaGrammar.Append(new SemanticResultKey("letter", new Choices(eiaLetterChoices, eiaPhonemeChoices))); // SMD lookup // Final grammar Choices commandChoices = new Choices(new GrammarBuilder[] { exitGrammar, toggleMetricPrefixGrammar, enableSpeechGrammar, disableSpeechGrammar, fourBandGrammar, fiveBandGrammar, eiaGrammar }); Grammar appGrammar = new Grammar((GrammarBuilder)commandChoices); appGrammar.Name = "commands"; return(appGrammar); }
/// <summary> /// Creates a grammar for all the recognized commands and values. /// </summary> /// <returns>A grammar for the EESpeak application</returns> private Grammar CreateGrammar() { // Exit grammar GrammarBuilder exitGrammar = new GrammarBuilder(new Choices(exitStrings)); // Enable speech GrammarBuilder enableSpeechGrammar = new GrammarBuilder(enableSpeechCommand); // Disable speech GrammarBuilder disableSpeechGrammar = new GrammarBuilder(disableSpeechCommand); // Metric Prefixes GrammarBuilder toggleMetricPrefixGrammar = new GrammarBuilder(new Choices(toggleMetricPrefixes)); // 4-band lookup // Create color band semantics Choices resistorColorChoices = new Choices(); GrammarBuilder resistorColorValues = new GrammarBuilder(); foreach (string s in resistorColors) { SemanticResultValue temp = new SemanticResultValue(s, s); resistorColorChoices.Add(temp); resistorColorValues.Append(temp); } GrammarBuilder fourBandGrammar = new GrammarBuilder(new Choices(fourBandStrings)); fourBandGrammar.Append(new SemanticResultKey("first_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("second_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("third_band", resistorColorChoices)); fourBandGrammar.Append(new SemanticResultKey("fourth_band", resistorColorChoices)); // 5-band lookup GrammarBuilder fiveBandGrammar = new GrammarBuilder(new Choices(fiveBandStrings)); fiveBandGrammar.Append(new SemanticResultKey("first_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("second_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("third_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("fourth_band", resistorColorChoices)); fiveBandGrammar.Append(new SemanticResultKey("fifth_band", resistorColorChoices)); // EIA (2 digits, one letter) lookup // Create EIA semantics Choices eiaNumberChoices = new Choices(); GrammarBuilder eiaNumberValues = new GrammarBuilder(); for (int i = 0; i < eiaNumbers.Length; i++) { SemanticResultValue temp = new SemanticResultValue(eiaNumbers[i], i); eiaNumberChoices.Add(temp); eiaNumberValues.Append(temp); } Choices eiaLetterChoices = new Choices(); GrammarBuilder eiaLetterValues = new GrammarBuilder(); foreach (string s in eiaLetters) { SemanticResultValue temp = new SemanticResultValue(s, s); eiaLetterChoices.Add(temp); eiaLetterValues.Append(temp); } Choices eiaPhonemeChoices = new Choices(); GrammarBuilder eiaLetterPhonemes = new GrammarBuilder(); foreach (string s in eiaPhonemes) { SemanticResultValue temp = new SemanticResultValue(s, s); eiaPhonemeChoices.Add(temp); eiaLetterPhonemes.Append(temp); } GrammarBuilder eiaGrammar = new GrammarBuilder(new Choices(eiaCommandStrings)); eiaGrammar.Append(new SemanticResultKey("first_number", eiaNumberChoices)); eiaGrammar.Append(new SemanticResultKey("second_number", eiaNumberChoices)); eiaGrammar.Append(new SemanticResultKey("letter", new Choices(eiaLetterChoices, eiaPhonemeChoices))); // SMD lookup // Final grammar Choices commandChoices = new Choices(new GrammarBuilder[] { exitGrammar, toggleMetricPrefixGrammar, enableSpeechGrammar, disableSpeechGrammar, fourBandGrammar, fiveBandGrammar, eiaGrammar }); Grammar appGrammar = new Grammar((GrammarBuilder)commandChoices); appGrammar.Name = "commands"; return appGrammar; }
private GrammarBuilder moveCommand() { Choices commands = new Choices(); SemanticResultValue commandSRV; commandSRV = new SemanticResultValue("move", (int)CommandTypes.Move); commands.Add(commandSRV); commandSRV = new SemanticResultValue("switch", (int)CommandTypes.Move); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); Choices preps = new Choices("to", "in"); // 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(preps, 0, 1); finalCommand.Append(this.semester, 0, 1); return finalCommand; }
private Grammar CreateGrammarBuilderDollDressSemantics(params int[] info) { //synth.Speak("Creando ahora la gramática"); Choices partesAbajoChoice = new Choices(); Choices partesArribaChoice = new Choices(); Choices parteEnteraChoice = new Choices(); Choices zapatosChoice = new Choices(); Choices musicaChoice = new Choices(); // Partes de abajo SemanticResultValue choiceResultValue = new SemanticResultValue("Falda", "Falda"); GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue); partesAbajoChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Pantalones", "Pantalones"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesAbajoChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Pantalones cortos", "Pantalones cortos"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesAbajoChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("parte de abajo", "Parte de abajo"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesAbajoChoice.Add(resultValueBuilder); // Fin partes de abajo // Partes de arriba choiceResultValue = new SemanticResultValue("Camiseta", "Ca" + "miseta"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Chaqueta", "Chaqueta"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Abrigo", "Abrigo"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Blusa", "Blusa"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Jersey", "Jersey"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("parte de arriba", "Parte de arriba"); resultValueBuilder = new GrammarBuilder(choiceResultValue); partesArribaChoice.Add(resultValueBuilder); // Fin partes de arriba // Partes entera choiceResultValue = new SemanticResultValue("Vestido", "Vestido"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Vestido playero", "Playero"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Disfraz festivo", "Disfraz navideño"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Disfraz de pirata", "Disfraz de pirata"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Bañador", "Bañador"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Bikini", "Bikini"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("atuendo", "Atuendo"); resultValueBuilder = new GrammarBuilder(choiceResultValue); parteEnteraChoice.Add(resultValueBuilder); // Fin partes enteras // Zapatos choiceResultValue = new SemanticResultValue("Zapatos", "Zapatos"); resultValueBuilder = new GrammarBuilder(choiceResultValue); zapatosChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Botas", "Botas"); resultValueBuilder = new GrammarBuilder(choiceResultValue); zapatosChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Sandalias", "Sandalias"); resultValueBuilder = new GrammarBuilder(choiceResultValue); zapatosChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("calzado", "Calzado"); resultValueBuilder = new GrammarBuilder(choiceResultValue); zapatosChoice.Add(resultValueBuilder); // Fin zapatos // Música choiceResultValue = new SemanticResultValue("Música", "musica"); resultValueBuilder = new GrammarBuilder(choiceResultValue); musicaChoice.Add(resultValueBuilder); /* choiceResultValue = new SemanticResultValue("Villancico", "villancico"); * resultValueBuilder = new GrammarBuilder(choiceResultValue); * musicaChoice.Add(resultValueBuilder);*/ // Fin música //Creación de palabras claves SemanticResultKey choiceResultKeyArriba = new SemanticResultKey("partesArriba", partesArribaChoice); SemanticResultKey choiceResultKeyAbajo = new SemanticResultKey("partesAbajo", partesAbajoChoice); SemanticResultKey choiceResultKeyZapatos = new SemanticResultKey("zapatos", zapatosChoice); SemanticResultKey choiceResultKeyEntero = new SemanticResultKey("parteEntera", parteEnteraChoice); SemanticResultKey choiceResultKeyMusica = new SemanticResultKey("musica", musicaChoice); //Creación de grammarbuilder GrammarBuilder partesArriba = new GrammarBuilder(choiceResultKeyArriba); GrammarBuilder partesAbajo = new GrammarBuilder(choiceResultKeyAbajo); GrammarBuilder zapatos = new GrammarBuilder(choiceResultKeyZapatos); GrammarBuilder partesEnteras = new GrammarBuilder(choiceResultKeyEntero); GrammarBuilder musica = new GrammarBuilder(choiceResultKeyMusica); Choices opcionesRopa = new Choices(new GrammarBuilder[] { partesArriba, partesAbajo, zapatos, partesEnteras }); //Opciones de lugares para ir Choices lugaresChoice = new Choices(); choiceResultValue = new SemanticResultValue("Pasear", "parque"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Playa", "playa"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Barco", "barco"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Casa por navidad", "casa"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Cine", "cine"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Clase", "clase"); resultValueBuilder = new GrammarBuilder(choiceResultValue); lugaresChoice.Add(resultValueBuilder); SemanticResultKey choiceResultKeyLugares = new SemanticResultKey("Lugares", lugaresChoice); GrammarBuilder lugares = new GrammarBuilder(choiceResultKeyLugares); //Opciones de sexo Choices sexoChoice = new Choices(); choiceResultValue = new SemanticResultValue("Chico", "Chico"); resultValueBuilder = new GrammarBuilder(choiceResultValue); sexoChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Chica", "Chica"); resultValueBuilder = new GrammarBuilder(choiceResultValue); sexoChoice.Add(resultValueBuilder); choiceResultValue = new SemanticResultValue("Sexo", "Sexo"); resultValueBuilder = new GrammarBuilder(choiceResultValue); sexoChoice.Add(resultValueBuilder); SemanticResultKey choiceResultKeySexo = new SemanticResultKey("Sexo", sexoChoice); GrammarBuilder sexo = new GrammarBuilder(choiceResultKeySexo); //FRASES GrammarBuilder poner = "Poner"; GrammarBuilder cambiar = "Cambiar"; Choices ponerAlternativa = new Choices(poner, cambiar); SemanticResultKey choiceResultKeyPoner = new SemanticResultKey("Poner", ponerAlternativa); GrammarBuilder ponerFrase = new GrammarBuilder(choiceResultKeyPoner); ponerFrase.Append(opcionesRopa); GrammarBuilder quitar = "Quitar"; GrammarBuilder quitarFrase = new GrammarBuilder(new SemanticResultKey("Quitar", new Choices(quitar))); quitarFrase.Append(opcionesRopa); GrammarBuilder apagar = "Apagar"; Choices apagarAlternativa = new Choices(quitar, apagar); SemanticResultKey choiceResultKeyQuitar = new SemanticResultKey("Apagar", apagarAlternativa); GrammarBuilder apagarFrase = new GrammarBuilder(choiceResultKeyQuitar); apagarFrase.Append(musica); GrammarBuilder encender = "Encender"; Choices encenderAlternativa = new Choices(poner, encender); SemanticResultKey choiceResultKeyEncender = new SemanticResultKey("Encender", encenderAlternativa); GrammarBuilder encenderFrase = new GrammarBuilder(choiceResultKeyEncender); encenderFrase.Append(musica); GrammarBuilder cambiarA = "Cambiar a"; GrammarBuilder cambiarDe = "Cambiar de"; Choices cambiarDeAlternativa = new Choices(cambiarA, cambiarDe); SemanticResultKey choiceResultKeyCambiar = new SemanticResultKey("Cambiar", cambiarDeAlternativa); GrammarBuilder cambiarFrase = new GrammarBuilder(choiceResultKeyCambiar); cambiarFrase.Append(sexo); GrammarBuilder fondoFrase = new GrammarBuilder("Ir a"); fondoFrase.Append(lugares); Choices opcionesFrase = new Choices(new GrammarBuilder[] { ponerFrase, quitarFrase, apagarFrase, encenderFrase, fondoFrase, cambiarFrase }); Grammar grammar = new Grammar((GrammarBuilder)opcionesFrase); grammar.Name = "Poner/Cambiar"; return(grammar); //Grammar grammar = new Grammar("so.xml.txt"); }
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; }
private Choices buildCourseGrammar() { SemanticResultKey anaphora = new SemanticResultKey(Slots.CourseAnaphora.ToString(), new SemanticResultValue("it", "it")); //Class: a class, this class, that class, that other class Choices deptChoices = new Choices(); SemanticResultValue deptsRV; for (int i = 0; i < this.depts.Count; i++) { deptsRV = new SemanticResultValue(this.depts[i].Abv, this.depts[i].Abv); //deptsRV = new SemanticResultValue(String.Join(".", this.depts[i].Abv.ToCharArray()), this.depts[i].Abv); deptChoices.Add(deptsRV); deptsRV = new SemanticResultValue(this.depts[i].Name, this.depts[i].Abv); deptChoices.Add(deptsRV); } SemanticResultKey deptSemKey = new SemanticResultKey(Slots.Department.ToString(), deptChoices); //Class: a class, this class, that class, that other class Choices classNumbers = new Choices(); foreach (var numbersRV in classList.Select(c => c.Number).Distinct().Select(n => new SemanticResultValue(n.ToString(), n))) { classNumbers.Add(numbersRV); } SemanticResultKey numbersSemKey = new SemanticResultKey(Slots.Number.ToString(), classNumbers); GrammarBuilder course = new GrammarBuilder(); course.Append(deptSemKey); course.Append(numbersSemKey); Choices courseNameChoices = new Choices(); foreach (Course c in CourseCatalog.Instance.Courses) { courseNameChoices.Add(new SemanticResultValue(c.Name, c.ToString())); } SemanticResultKey courseNameKey = new SemanticResultKey(Slots.CourseName.ToString(), courseNameChoices); GrammarBuilder courseGrammar = new GrammarBuilder(); Choices courseOrAnaphora = new Choices(); courseOrAnaphora.Add(course); courseOrAnaphora.Add(anaphora); courseOrAnaphora.Add(courseNameKey); return courseOrAnaphora; }
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; }
/// <summary> /// Constructor for voice recognition /// </summary> /// <param name="kinectSensor"></param> /// <param name="mainWindow"></param> public VoiceRecognition(KinectSensor kinectSensor, MainWindow mainWindow) { this.kinectSensor = kinectSensor; this.mainWindow = mainWindow; // Grab the audio stream IReadOnlyList <AudioBeam> audioBeamList = kinectSensor.AudioSource.AudioBeams; Stream audioStream = audioBeamList[0].OpenInputStream(); // Create the convert stream convertStream = new KinectAudioStream(audioStream); RecognizerInfo recognizerInfo = TryGetKinectRecognizer(); if (recognizerInfo != null) { speechEngine = new SpeechRecognitionEngine(recognizerInfo.Id); Choices indices = new Choices(); GrammarBuilder indexValues = new GrammarBuilder { Culture = recognizerInfo.Culture }; GrammarBuilder imageNavigationSpeech = new GrammarBuilder(); for (int i = 0; i < 78; i++) { SemanticResultValue index = new SemanticResultValue(IntToWord.IntegerToWritten(i + 1), i + 1); indices.Add(index); indexValues.Append(index); } indexValues.Append(indices); imageNavigationSpeech.Append("go to image"); imageNavigationSpeech.Append(new SemanticResultKey("imageNumber", indices)); Grammar imageNavigationGrammar = new Grammar(imageNavigationSpeech); imageNavigationGrammar.Name = "ImageNavigation"; speechEngine.LoadGrammar(imageNavigationGrammar); // Create a grammar from grammar definition XML file. using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar))) { Grammar XMLGrammar = new Grammar(memoryStream); XMLGrammar.Name = "XMLGrammar"; speechEngine.LoadGrammar(XMLGrammar); } speechEngine.SpeechRecognized += SpeechRecognized; speechEngine.SpeechRecognitionRejected += SpeechRejected; // let the convertStream know speech is going active convertStream.SpeechActive = true; // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model. // This will prevent recognition accuracy from degrading over time. speechEngine.UpdateRecognizerSetting("AdaptationOn", 0); speechEngine.SetInputToAudioStream(this.convertStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); speechEngine.RecognizeAsync(RecognizeMode.Multiple); } }
private void CreateSpeechGrammars() { // Create SemanticResultValue objects that contain activator possibilities SemanticResultValue okayGeorge = new SemanticResultValue("Okay George", "Start Listening"); SemanticResultValue georgeListen = new SemanticResultValue("George Listen", "Start Listening"); SemanticResultValue stopListening = new SemanticResultValue("Stop Listening", "Stop Listening"); // Create Activator 'choices' Choices choicesActivator = new Choices(); choicesActivator.Add(new Choices(new GrammarBuilder[] { okayGeorge, georgeListen, stopListening })); // Build the phrase and add 'choices' GrammarBuilder grammarActivator = new GrammarBuilder(); grammarActivator.Append(new SemanticResultKey("activator", choicesActivator)); // Build a Grammar object from the GrammarBuilder. ActivateGrammar = new Grammar(grammarActivator); // Create SemanticResultValue objects that contain Navigation possibilities SemanticResultValue go = new SemanticResultValue("Go", "Navigate"); SemanticResultValue goTo = new SemanticResultValue("Go to", "Navigate"); SemanticResultValue navigateTo = new SemanticResultValue("Navigate to", "Navigate"); SemanticResultValue menuShop = new SemanticResultValue("Shop", "Shop"); SemanticResultValue menuAccount = new SemanticResultValue("Account", "Account"); SemanticResultValue menuWish_list = new SemanticResultValue("Wish list", "Wishlist"); SemanticResultValue menuWishlist = new SemanticResultValue("Wishlist", "Wishlist"); SemanticResultValue menuSearch = new SemanticResultValue("Search", "Search"); SemanticResultValue menuHome = new SemanticResultValue("Home", "Home"); // Create Navigator 'Choices' Choices choicesNavigatorActivate = new Choices(); choicesNavigatorActivate.Add(new Choices(new GrammarBuilder[] { go, goTo, navigateTo })); Choices choicesNavigation = new Choices(); choicesNavigation.Add(new Choices(new GrammarBuilder[] { menuShop, menuAccount, menuWish_list, menuWishlist, menuSearch, menuHome })); // build the phrasing GrammarBuilder grammarNavigation = new GrammarBuilder(); grammarNavigation.Append(new SemanticResultKey("activator", choicesNavigatorActivate)); grammarNavigation.Append(new SemanticResultKey("where", choicesNavigation)); NavigateGrammar = new Grammar(grammarNavigation); // Create SemanticResultValue objects that contain search possibilities SemanticResultValue search = new SemanticResultValue("Search", "Search"); SemanticResultValue searchFor = new SemanticResultValue("Search for", "Search"); SemanticResultValue searchIn = new SemanticResultValue("Search in", "Search"); // Create SemanticResultValue objects that contain category possibilities SemanticResultValue woman = new SemanticResultValue("woman", "womens"); SemanticResultValue women = new SemanticResultValue("women", "womens"); SemanticResultValue womens = new SemanticResultValue("womens", "womens"); SemanticResultValue female = new SemanticResultValue("female", "womens"); SemanticResultValue male = new SemanticResultValue("male", "mens"); SemanticResultValue man = new SemanticResultValue("man", "mens"); SemanticResultValue men = new SemanticResultValue("men", "mens"); SemanticResultValue mens = new SemanticResultValue("mens", "mens"); // Create Search Choices choicesSearch = new Choices(); choicesSearch.Add(new Choices(new GrammarBuilder[] { search, searchFor, searchIn })); //Create Categories Choices choicesCategories = new Choices(); choicesCategories.Add(new Choices(new GrammarBuilder[] { woman, women, womens, female, male, man, men, mens })); // build category search GrammarBuilder grammarSearchCategories = new GrammarBuilder(); grammarSearchCategories.Append(new SemanticResultKey("activator", choicesSearch)); grammarSearchCategories.Append(new SemanticResultKey("category", choicesCategories)); SearchCatGrammar = new Grammar(grammarSearchCategories); List <SemanticResultValue> arraySubCatValue = new List <SemanticResultValue>(); foreach (Models.Category category in Collector.Categories) { foreach (Models.SubCategory subCategory in category.SubCategories) { arraySubCatValue.Add(new SemanticResultValue(subCategory.Title.Replace("&", "and"), subCategory.Title)); } } Choices choicesSubCategories = new Choices(); foreach (SemanticResultValue semValue in arraySubCatValue) { choicesSubCategories.Add(new Choices(new GrammarBuilder(semValue))); } GrammarBuilder grammarSubCat = new GrammarBuilder(); grammarSubCat.Append(new SemanticResultKey("activator", choicesSearch)); grammarSubCat.Append(new SemanticResultKey("category", choicesCategories)); grammarSubCat.Append(new SemanticResultKey("subcategory", choicesSubCategories)); SearchSubCatGrammar = new Grammar(grammarSubCat); // Create SemanticResultValue objects that contain wishlist possibilities SemanticResultValue addToWishlist = new SemanticResultValue("Add to the wishlist", "Add to Wishlist"); SemanticResultValue addToWishlist2 = new SemanticResultValue("Add to my wishlist", "Add to Wishlist"); SemanticResultValue removeFromWishlist = new SemanticResultValue("Remove from my wishlist", "Remove from Wishlist"); SemanticResultValue add = new SemanticResultValue("add", "Add to Wishlist"); SemanticResultValue remove = new SemanticResultValue("remove", "Remove from Wishlist"); SemanticResultValue removeFromWishlist2 = new SemanticResultValue("Remove from the wishlist", "Remove from Wishlist"); // Create Activator 'choices' Choices choicesWishlist = new Choices(); choicesWishlist.Add(new Choices(new GrammarBuilder[] { addToWishlist, addToWishlist2, removeFromWishlist, removeFromWishlist2 })); // Build the phrase and add 'choices' GrammarBuilder grammarWishlist = new GrammarBuilder(); grammarWishlist.Append(new SemanticResultKey("activator", choicesWishlist)); // Build a Grammar object from the GrammarBuilder. WishListGrammar = new Grammar(grammarWishlist); IsListening = false; }
private GrammarBuilder buildSemesterGrammar() { Choices prepositions = new Choices("to", "to my", "to the", "in", "in the"); // semesters Choices semestersChoices = new Choices(); SemanticResultValue semestersRV; semestersRV = new SemanticResultValue("spring", "spring"); semestersChoices.Add(semestersRV); semestersRV = new SemanticResultValue("fall", "fall"); semestersChoices.Add(semestersRV); SemanticResultKey semesterSemKey = new SemanticResultKey(Slots.Semester.ToString(), semestersChoices); GrammarBuilder semester = new GrammarBuilder(); semester.Append(prepositions, 0, 1); semester.Append(semesterSemKey); semester.Append("schedule", 0, 1); // "2013" OR "of 2013" Choices yearPrep = new Choices("of", "to", "from", "in"); // year Choices years = new Choices(); SemanticResultValue yearRV; //int currentYear = 2012; for (int year = 2000; year < 2020; year++) { yearRV = new SemanticResultValue(year.ToString(), year.ToString()); years.Add(yearRV); } SemanticResultKey yearSemKey = new SemanticResultKey(Slots.Year.ToString(), years); GrammarBuilder yearGrammar = new GrammarBuilder(); yearGrammar.Append(yearPrep, 0, 1); yearGrammar.Append(yearSemKey); yearGrammar.Append("schedule", 0, 1); GrammarBuilder semesterYear = new GrammarBuilder(); semesterYear.Append(semester, 0, 1); semesterYear.Append(yearGrammar, 0, 1); return semesterYear; }
private GrammarBuilder errorCommand() { Choices commands = new Choices(); SemanticResultValue commandSRV; //commandSRV = new SemanticResultValue("no", (int)CommandTypes.Undo); //commands.Add(commandSRV); commandSRV = new SemanticResultValue("undo", (int)CommandTypes.Undo); commands.Add(commandSRV); SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands); // put the whole command together GrammarBuilder finalCommand = new GrammarBuilder(); finalCommand.Append(commandSemKey); return finalCommand; }
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; }
private GrammarBuilder buildCourseGrammarNested() { //Class: a class, this class, that class, that other class Choices deptChoices = new Choices(); SemanticResultValue deptsRV; for (int i = 0; i < this.depts.Count; i++) { Department dept = depts[i]; Choices classNumbers = new Choices(); foreach (var numbersRV in classList.Where(c => c.DeptAbv == dept.Abv).Select(c => c.Number).Distinct().Select(n => new SemanticResultValue(n.ToString(), n))) { classNumbers.Add(numbersRV); } deptsRV = new SemanticResultValue(dept.Abv, dept.Abv); GrammarBuilder deptsGmr = deptsRV.ToGrammarBuilder(); deptsGmr.Append(classNumbers); deptChoices.Add(deptsGmr); deptsRV = new SemanticResultValue(dept.Name, dept.Abv); deptsGmr = deptsRV.ToGrammarBuilder(); deptsGmr.Append(classNumbers); deptChoices.Add(deptsGmr); } SemanticResultKey deptSemKey = new SemanticResultKey(Slots.Department.ToString(), deptChoices); GrammarBuilder course = new GrammarBuilder(); course.Append(deptChoices.ToGrammarBuilder()); return course; }