SrgsRuleRef Constructor (Uri)
Initializes a new instance of the SrgsRuleRef class, specifying the Uniform Resource Identifier (URI) of the grammar to reference.
Namespace: Microsoft.Speech.Recognition.SrgsGrammar
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Public Sub New ( _
uri As Uri _
)
public SrgsRuleRef (
Uri uri
)
public:
SrgsRuleRef (
Uri^ uri
)
public SrgsRuleRef (
Uri uri
)
public function SrgsRuleRef (
uri : Uri
)
Parameters
- uri
The URI of the rule to reference.
Exceptions
Exception type | Condition |
---|---|
ArgumentNullException | uri is null. |
Remarks
The syntax for uri will vary, depending on whether it references a rule in the same grammar or in an external grammar. For more information, see Uri.
Example
The following example creates a grammar for an application that returns information about bus shuttle service. The first method, GrammarUrlForRoute, takes a string that specifies a route and appends it to a string specifying the location of a grammar. This specifies a particular rule in that grammar. The method returns a Uri for that rule.
The second method, CreateGrammarForRoute, creates an SrgsDocument element named grammar with a rule reference specified by the Uri passed to it by GrammarUrlForRoute. Note that the variable named _route is a member of an enclosing class.
private Uri GrammarUrlForRoute(string route)
{
return new Uri("http://localhost/MyBus/MyBusLocations.grxml#LocationsForRoute" + route);
}
private SrgsDocument CreateGrammarForRoute()
{
SrgsDocument grammar = new SrgsDocument();
grammar.Mode = SrgsGrammarMode.Voice;
SrgsRule rule = new SrgsRule("LocationsForRoute" + _route);
SrgsRuleRef ruleref = new SrgsRuleRef(GrammarUrlForRoute(_route));
SrgsTag tag = new SrgsTag("$.Location = $$");
rule.Elements.Add(ruleref);
rule.Elements.Add(tag);
grammar.Rules.Add(rule);
grammar.Root = rule;
return grammar;
}
Note
The variable named _route is undeclared and undefined in the preceding sample. It should be declared as a string and contain the route number for a particular bus route before the preceding sample is compiled and run.
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