/// <summary> /// Create Grammars for the contact names of customer's contact list /// </summary> private void Code_PrepareGrammar(object sender, EventArgs e) { SrgsOneOf oneOf = new SrgsOneOf(); foreach (var contact in contacts) { SrgsItem item = new SrgsItem(contact.Value.DisplayName); SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag("$._value = \"" + contact.Key + "\";"); SrgsItem nameItem = new SrgsItem(); nameItem.Add(item); nameItem.Add(tag); oneOf.Add(nameItem); } SrgsRule nameRule = new SrgsRule("name"); nameRule.Scope = SrgsRuleScope.Public; nameRule.Elements.Add(oneOf); SrgsDocument grammarDoc = new SrgsDocument(); grammarDoc.Rules.Add(nameRule); grammarDoc.Root = nameRule; speechGrammar.Add(new Grammar(grammarDoc)); }
/// <summary> /// Creates a grammar for main menu options. /// </summary> /// <returns></returns> private Grammar SetupGrammar() { var options = this.MainMenuConfiguration.Options; SrgsOneOf oneOf = new SrgsOneOf(); foreach (var option in options) { SrgsItem item = new SrgsItem(option.Index.ToString(CultureInfo.InvariantCulture)); SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag("$._value = \"" + option.DtmfCode + "\";"); SrgsItem digitItem = new SrgsItem(); digitItem.Add(item); digitItem.Add(tag); oneOf.Add(digitItem); } SrgsRule digitRule = new SrgsRule("digit"); digitRule.Scope = SrgsRuleScope.Public; digitRule.Elements.Add(oneOf); SrgsDocument grammarDoc = new SrgsDocument(); grammarDoc.Mode = SrgsGrammarMode.Dtmf; grammarDoc.Rules.Add(digitRule); grammarDoc.Root = digitRule; return(new Grammar(grammarDoc)); }
/// <summary> /// Parse tag /// </summary> private ISemanticTag ParseSemanticTag(SrgsSemanticInterpretationTag srgsTag, IElement parent) { ISemanticTag tag = _parser.CreateSemanticTag(parent); tag.Content(parent, srgsTag.Script, 0); tag.PostParse(parent); return(tag); }
/// <summary> /// Create Grammar of a given skill from the config file. /// </summary> /// <param name="skill"></param> /// <returns></returns> private Grammar[] CreateSkillGrammar(Skill skill) { Grammar[] grammars = new Grammar[2]; SrgsItem[] srgsSkillValues = new SrgsItem[skill.Values.Count]; SrgsItem[] srgsDtmfSkillValues = new SrgsItem[skill.Values.Count]; //iterate over skill values. for (int i = 0; i < skill.Values.Count; i++) { //set the recognition result equal to the category name. SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag( "$._value = \"" + skill.Values[i] + "\";" ); //one-of element to allow the user to enter the category name, or a number //representing the one-based position in the list of the category. SrgsOneOf categoryOneOf = new SrgsOneOf(); //match the category name. categoryOneOf.Add(new SrgsItem(skill.Values[i])); //match the one-based index of the category in the list. categoryOneOf.Add(new SrgsItem((i + 1).ToString())); //wrap it all up with an item tag srgsSkillValues[i] = new SrgsItem(categoryOneOf); srgsSkillValues[i].Add(tag); srgsDtmfSkillValues[i] = new SrgsItem(i + 1); srgsDtmfSkillValues[i].Add(tag); } //one-of that wraps the list of items containing the category one-of elements. SrgsOneOf oneOf = new SrgsOneOf(srgsSkillValues); //root rule element. SrgsRule categoryRule = new SrgsRule(skill.Name.Replace(" ", ""), oneOf); categoryRule.Scope = SrgsRuleScope.Public; SrgsOneOf dtmfOneOf = new SrgsOneOf(srgsDtmfSkillValues); SrgsDocument grammarDoc = new SrgsDocument(); //add and set the root rule grammarDoc.Rules.Add(categoryRule); grammarDoc.Root = categoryRule; //create the grammar object. Grammar grammar = new Grammar(grammarDoc); grammars[0] = grammar; SrgsDocument dtmfGrammarDoc = new SrgsDocument(); dtmfGrammarDoc.Mode = SrgsGrammarMode.Dtmf; dtmfGrammarDoc.Rules.Add(categoryRule); dtmfGrammarDoc.Root = categoryRule; Grammar dtmfGrammar = new Grammar(dtmfGrammarDoc); grammars[1] = dtmfGrammar; return(grammars); }