Adds an SrgsElement to an SrgsRule object.
Namespace:
Microsoft.Speech.Recognition.SrgsGrammar
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub Add ( _ element As SrgsElement _ ) |
Visual Basic (Usage) |
---|
Dim instance As SrgsRule Dim element As SrgsElement instance.Add(element) |
C# |
---|
public void Add( SrgsElement element ) |
Parameters
- element
- Type: Microsoft.Speech.Recognition.SrgsGrammar..::..SrgsElement
An object that inherits from SrgsElement and specifies what can be recognized.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | element is nullNothingnullptrunita null reference (Nothing in Visual Basic). |
Remarks
Typical additions to an SrgsRule object include SrgsItem, SrgsOneOf, SrgsRuleRef, and SrgsToken objects that specify what speakers can say. A valid rule element must contain at least one piece of recognizable text or one rule reference. See Create Grammars Using SrgsGrammar (Microsoft.Speech) for more information.
An SrgsRule object may also contain SrgsSemanticInterpretationTag objects that add semantic values and semantic keys to the rule. The speech recognition engine will return the semantic information, as well as the recognized phrase, when it recognizes the phrase. See Semantic Interpretation Markup (Microsoft.Speech) for more information.
Examples
The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country that has won the World Cup. After creating the SrgsRule object winnerRule and giving it the string identifier WorldCupWinner, the example uses the Add(SrgsElement) method to append the string "A nation that has won the World Cup is" to the rule. The example then creates two additional rules, ruleEurope and ruleSAmerica. Again using the Add(SrgsElement) method, the example appends an SrgsOneOf object to the WorldCupWinner rule that contains rule references to ruleEurope and ruleSAmerica.
Copy Code | |
---|---|
// Create an SrgsDocument, create a new rule // and set its scope to public. SrgsDocument document = new SrgsDocument(); SrgsRule winnerRule = new SrgsRule("WorldCupWinner"); winnerRule.Scope = SrgsRuleScope.Public; // Add the introduction. winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: ")); // Create the rule for the European nations. SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")}); SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope})); // Create the rule for the South American nations. SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay")}); SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica})); // Add references to winnerRule for ruleEurope and ruleSAmerica. winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))})); // Add all the rules to the document and make winnerRule // the root rule of the document. document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica}); document.Root = winnerRule; |