SrgsDocument Constructor

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Initializes a new instance of the SrgsDocument class.

Namespace:  Microsoft.Speech.Recognition.SrgsGrammar
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

Visual Basic (Declaration)
Public Sub New
Visual Basic (Usage)
Dim instance As New SrgsDocument()
C#
public SrgsDocument()

Remarks

This constructor creates an empty SrgsDocument instance. To build a grammar within an empty SrgsDocument instance, add instances of classes that represent SRGS elements, such as SrgsRule, SrgsRuleRef, SrgsOneOf, and SrgsItem.

Examples

The following example creates an SrgsDocument object and then creates a public rule named rootRule. It then creates an SrgsItem that consists of the string "A nation that has won the world cup is:", and adds this item to the Elements property of the rule. The example then creates two more rules (ruleEurope and ruleSAmerica), each of which is an SrgsOneOf object that contains three SrgsItem objects. After that, another SrgsOneOf object is created that contains SrgsRuleRef objects that refer to ruleEurope and ruleSAmerica. The new SrgsOneOf object is then added to the Elements property of rootRule. After this, all three rules (rootRule, ruleEurope, and ruleSAmerica) are added to the Rules property of SrgsDocument. Finally, the three rules are compiled into a binary representation of the grammar.

C# Copy imageCopy Code
SrgsDocument document = new SrgsDocument();

SrgsRule rootRule = new SrgsRule("WorldCupWinner");
rootRule.Scope = SrgsRuleScope.Public;

rootRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));
SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy"));
SrgsRule ruleEurope = new SrgsRule("EuropeanNations", oneOfEurope);

SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay"));
SrgsRule ruleSAmerica = new SrgsRule("SouthAmericanNations", oneOfSAmerica);

rootRule.Elements.Add(new SrgsOneOf(new SrgsItem(new SrgsRuleRef(ruleEurope)), new SrgsItem(new SrgsRuleRef(ruleSAmerica))));

document.Rules.Add(rootRule, ruleEurope, ruleSAmerica);
document.Root = rootRule;

String fileName = Path.GetTempFileName();
FileStream stream = new FileStream(fileName, FileMode.Create);

SrgsGrammarCompiler.Compile(document, stream);
stream.Close();
lil

See Also