Compartilhar via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

SrgsDocument.Rules Property

Gets the collection of rules that are currently defined for the SrgsDocument class.

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

Syntax

'Declaration
Public ReadOnly Property Rules As SrgsRulesCollection
    Get
'Usage
Dim instance As SrgsDocument
Dim value As SrgsRulesCollection

value = instance.Rules
public SrgsRulesCollection Rules { get; }

Property Value

Type: Microsoft.Speech.Recognition.SrgsGrammar.SrgsRulesCollection
Returns the rules defined for the SrgsDocument object.

Remarks

You can add SrgsRule objects to the SrgsRulesCollection by using the Add method on the Rules property. If you initialize an SrgsDocument object and specify an SrgsRule object as the argument, the SrgsRule is automatically added to the SrgsRulesCollection for the SrgsDocument.

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, rootRule is made the root rule for the grammar of SrgsDocument.

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("Argentine"), 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;

See Also

Reference

SrgsDocument Class

SrgsDocument Members

Microsoft.Speech.Recognition.SrgsGrammar Namespace

SrgsRulesCollection