Export (0) Print
Expand All

SrgsRule.Add Method

Adds an SrgsElement to an SrgsRule object.

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

public void Add(
	SrgsElement element
)

Parameters

element
Type: System.Speech.Recognition.SrgsGrammar.SrgsElement

An object that inherits from SrgsElement and specifies what can be recognized.

ExceptionCondition
ArgumentNullException

element is null.

Typical additions to an SrgsRule object include SrgsItem, SrgsOneOf, SrgsRuleRef, and SrgsToken objects that specify what speakers can say. A valid rule element must contain at least one piece of recognizable text or one rule reference. See Create Grammars Using SrgsGrammar for more information.

An SrgsRule object may also contain SrgsNameValueTag and SrgsSemanticInterpretationTag objects that add semantic values and semantic keys to the rule. The speech recognition engine will return the semantic information, as well as the recognized phrase, when it recognizes the phrase. See Semantic Interpretation Markup for more information.

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. After creating the SrgsRule object winnerRule and giving it the string identifier WorldCupWinner, the example uses the Add method to append the string "A nation that has won the World Cup is" to the rule. The example then creates two additional rules, ruleEurope and ruleSAmerica. Again using the Add method, the example appends an SrgsOneOf object to the WorldCupWinner rule that contains rule references to ruleEurope and ruleSAmerica.

// Create an SrgsDocument, create a new rule
// and set its scope to public.
SrgsDocument document = new SrgsDocument();
SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
winnerRule.Scope = SrgsRuleScope.Public;

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

// Create the rule for the European nations.
SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

// Create the rule for the South American nations.
SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

// Add references to winnerRule for ruleEurope and ruleSAmerica.
winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

// Add all the rules to the document and make winnerRule 
// the root rule of the document.
document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
document.Root = winnerRule;

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft