SrgsRule Constructor (String)
Initializes a new instance of the SrgsRule class with the given identifier.
Namespace: Microsoft.Speech.Recognition.SrgsGrammar
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Parameters
- id
A string that is the identifier of the rule. The identifier must be unique within a given grammar.
Exceptions
Exception type | Condition |
---|---|
ArgumentNullException | id is null. |
ArgumentOutOfRangeException | id is empty. |
FormatException | id is not a proper rule identifier. |
Remarks
The SrgsRule(string) constructor initializes the Id property.
The SrgsRule(string) constructor throws FormatException in the following circumstances:
id is not a valid XML name, as defined in Extensible Markup Language (XML) 1.0 (Second Edition)—see http://www.w3.org/TR/2000/REC-xml-20001006. To paraphrase this definition, a valid XML name must begin with a letter, an underscore ('_'), or a colon (':') and can be followed by zero or more NameChar characters (also defined in the XML specification).
id is "NULL" or "VOID" or "GARBAGE".
id contains at least one invalid rule ID character. These characters are: '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<', '>', '[', ']', '{', '}', '\\', ' ', '\t', '\r', and '\n'.
Example
The following example creates an inline grammar with a single SrgsRule element named rule1 containing a rule whose identifier is rootRule and adds an SrgsOneOf element to the Elements property of the SrgsRule element. The SrgsOneOf element consists of SrgsItem elements containing alternatives to be recognized by the rule.
/// <summary>
/// Create an inline grammar
/// </summary>
/// <param name="mode">recognition mode: dtmf or voice</param>
protected void CreateInlineGrammar(SrgsGrammarMode mode)
{
SrgsDocument grammar1 = new SrgsDocument();
grammar1.Culture = Thread.CurrentThread.CurrentUICulture;
grammar1.Mode = mode;
//rule name is language independent
SrgsRule rule1 = new SrgsRule("rootRule");
grammar1.Rules.Add(rule1);
grammar1.Root = rule1;
ResourceInfo resources = TaskletHost.Resources;
SrgsOneOf ListOfAlternatives = new SrgsOneOf();
rule1.Elements.Add(ListOfAlternatives);
if (resources.GrammarTexts != null)
{
foreach (string alternative in resources.GrammarTexts)
{
ListOfAlternatives.Add(new SrgsItem(alternative));
}
}
inlineGrammar = new Grammar(grammar1);
}
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