SrgsRuleRef Constructor (Uri)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

Initializes a new instance of the SrgsRuleRef class and specifies the location of the external grammar file to reference.

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	uri As Uri _
)
Visual Basic (Usage)
Dim uri As Uri

Dim instance As New SrgsRuleRef(uri)
C#
public SrgsRuleRef(
	Uri uri
)

Parameters

uri
Type: System..::..Uri

The location of a grammar file outside the containing grammar.

Exceptions

ExceptionCondition
ArgumentNullException

uri is nullNothingnullptrunita null reference (Nothing in Visual Basic).

Remarks

This constructor creates a rule reference to an external grammar file. The URI may also include the identifier of a rule to reference, for example http://www.contoso.com/ExternalGrammar.grxml#targetRule. If the uri parameter does not specify a rule identifier, the rule reference points to the root rule of the target grammar. To create a rule reference to an SrgsRule object within the same grammar, use any of the following constructors:

Examples

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.

 Copy imageCopy Code
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));

  SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag ("$.Location = $$");

  rule.Elements.Add(ruleref);
  rule.Elements.Add(tag);
  grammar.Rules.Add(rule);
  grammar.Root = rule;
  return grammar;
}
NoteNote

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.

See Also