Initializes a new instance of the SrgsDocument class and specifies an SrgsRule object to be the root rule of the grammar.
Namespace:
Microsoft.Speech.Recognition.SrgsGrammar
Assembly:
Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub New ( _ grammarRootRule As SrgsRule _ ) |
Visual Basic (Usage) |
---|
Dim grammarRootRule As SrgsRule Dim instance As New SrgsDocument(grammarRootRule) |
C# |
---|
public SrgsDocument( SrgsRule grammarRootRule ) |
Parameters
- grammarRootRule
- Type: Microsoft.Speech.Recognition.SrgsGrammar..::..SrgsRule
The root rule in the SrgsDocument object.
Exceptions
Exception | Condition |
---|---|
SystemArgumentNullException | The value of grammarRootRule is nullNothingnullptrunita null reference (Nothing in Visual Basic). |
Remarks
This constructor adds the specified rule to the SrgsRulesCollection of the SrgsDocument object and sets it as the Root rule for the grammar.
Examples
The following example creates two rules (chooseCities and destCities) for choosing origin and destination cities for a flight. The example initializes the SrgsDocument instance using the chooseCities rule as an argument. The example writes the contents of the rules collection and the name of the root rule to the console.
C# | Copy Code |
---|---|
// Create a rule that contains a list of destination cities. SrgsRule destCities = new SrgsRule("Destination"); SrgsOneOf toCities = new SrgsOneOf(new string[] { "New York", "Seattle", "Denver" }); destCities.Add(toCities); // Create a list of origin cities and supporting phrases. SrgsOneOf fromCities = new SrgsOneOf(new SrgsItem[] { new SrgsItem("Dallas"), new SrgsItem("Miami"), new SrgsItem("Chicago") }); SrgsItem intro = new SrgsItem("I want to fly from"); SrgsItem to = new SrgsItem("to"); // Create the root rule of the grammar, and assemble the components. SrgsRule chooseCities = new SrgsRule("Trip"); chooseCities.Add(intro); chooseCities.Add(fromCities); chooseCities.Add(to); chooseCities.Add(new SrgsRuleRef(destCities)); // Create the SrgsDocument and specify the root rule to add. SrgsDocument bookFlight = new SrgsDocument(chooseCities); // Add the rule for the destination cities to the document's rule collection. bookFlight.Rules.Add(new SrgsRule[] { destCities }); // Display the contents of the Rules collection and the name of the root rule. foreach (SrgsRule rule in bookFlight.Rules) { Console.WriteLine("Rule " + rule.Id + " is in the rules collection"); } Console.WriteLine("Root Rule " + bookFlight.Root.Id); // Create a Grammar object and load it to the recognizer. Grammar g = new Grammar(bookFlight); g.Name = ("City Chooser"); recognizer.LoadGrammarAsync(g); |