SrgsRule.Scope Property


Gets or sets whether a rule can be activated for recognition and when the rule can be referenced by other rules.

 property System::Speech::Recognition::SrgsGrammar::SrgsRuleScope Scope { System::Speech::Recognition::SrgsGrammar::SrgsRuleScope get(); void set(System::Speech::Recognition::SrgsGrammar::SrgsRuleScope value); };
public System.Speech.Recognition.SrgsGrammar.SrgsRuleScope Scope { get; set; }
member this.Scope : System.Speech.Recognition.SrgsGrammar.SrgsRuleScope with get, set
Public Property Scope As SrgsRuleScope

Property Value

A value the sets the scope for the rule.


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. It creates a public rule named WorldCupWinner and sets the scope of that rule to Public.

// 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;  

The created grammar has the following form.

<grammar version="1.0" xml:lang="en-US" xmlns="" root="WorldCupWinner">  
    <rule id="WorldCupWinner" scope="public">  
        <item> A nation that has won the world cup is </item>  
                <ruleref uri="#EuropeanNations" />  
                <ruleref uri="#SouthAmericanNations" />  
    <rule id="EuropeanNations">  
            <item> England< /item>  
            <item> France </item>  
            <item> Germany </item>  
            <item> Italy </item>  
    <rule id="SouthAmericanNations">  
            <item> Argentina </item>  
            <item> Brazil </item>  
            <item> Uruguay </item>  


The default value for scope is Private. A private rule can only be activated for recognition by a rule reference from the root rule in its containing grammar or from another rule that is referenced from the root rule. A private rule cannot be referenced by an external grammar, unless the private rule is declared as the root rule of its containing grammar.

If its scope is set to Public, an SrgsRule object can be activated for recognition by a reference from a SrgsRuleRef object in the containing grammar or from a rule in an external grammar.

Applies to

See also