Share via


SrgsRuleRef Constructor (SrgsRule)

Initializes a new instance of the SrgsRuleRef class, specifying the rule to reference.

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

Syntax

'Declaration
Public Sub New ( _
    rule As SrgsRule _
)
public SrgsRuleRef (
    SrgsRule rule
)
public:
SrgsRuleRef (
    SrgsRule^ rule
)
public SrgsRuleRef (
    SrgsRule rule
)
public function SrgsRuleRef (
    rule : SrgsRule
)

Parameters

  • rule
    The identifier of the SrgsRule element to reference.

Exceptions

Exception type Condition
ArgumentNullException

rule is null.

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. It then creates two SrgsRule elements using arrays of SrgsOneOf elements. Next,it adds an SrgsOneOf element to the root rule, WorldCupWinner, and adds two alternative SrgsItem elements, each of which is an SrgsRuleRef object. One object is a reference to the rule EuropeanNations, and the other is a reference to the rule SouthAmericanNations.

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'
  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;
}

The created grammar has the following form.

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

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

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