Share via


SrgsRule.Scope Property

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

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

Syntax

'Declaration

Property Value

An SrgsRuleScope value.

Remarks

The default value for scope is Private. The rule is visible only within its containing grammar. A private rule can be referenced by an external grammar if the rule is declared as the root rule of its containing grammar.

If the scope is set to Public, the rule can be referenced by an external grammar (in a SrgsRuleRef element in the grammar making the reference). A public rule can always be activated for recognition.

Example

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.

public void WorldSoccerWinners ()
{
  SrgsDocument srgsGrammar = new SrgsDocument ();
  SrgsRule rootRule = new SrgsRule ("WorldCupWinner");

  rootRule.Scope = SrgsRuleScope.Public;

  // Add the introduction
  rootRule.Elements.Add (new SrgsItem ("A nation that has won the world cup is"));

  // Create the rootRule for the European nations
  SrgsOneOf oneOfEurope = new SrgsOneOf (new SrgsItem ("England"), new SrgsItem ("France"), new SrgsItem ("Germany"), new SrgsItem ("Italy"));
  SrgsRule ruleEurope = new SrgsRule ("EuropeanNations", oneOfEurope);

  // Create the rootRule for the South American nations
  SrgsOneOf oneOfSAmerica = new SrgsOneOf (new SrgsItem ("Argentina"), new SrgsItem ("Brazil"), new SrgsItem ("Uruguay"));
  SrgsRule ruleSAmerica = new SrgsRule ("SouthAmericanNations", oneOfSAmerica);

  // Add both rules to root list through a 'one of' list
  rootRule.Elements.Add (new SrgsOneOf (new SrgsItem (new SrgsRuleRef (ruleEurope)), new SrgsItem (new SrgsRuleRef (ruleSAmerica))));

  // Add all the rules to the grammar
  srgsGrammar.Rules.Add (rootRule, ruleEurope, ruleSAmerica);
  srgsGrammar.Root = rootRule;
}

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

SrgsRule Class
SrgsRule Members
Microsoft.Speech.Recognition.SrgsGrammar Namespace

Other Resources

Speech Recognition Grammar Specification Version 1.0