Jagamisviis:


SrgsRule.Add(SrgsElement) Method

Definition

Adds an SrgsElement to an SrgsRule object.

public:
 void Add(System::Speech::Recognition::SrgsGrammar::SrgsElement ^ element);
public void Add (System.Speech.Recognition.SrgsGrammar.SrgsElement element);
member this.Add : System.Speech.Recognition.SrgsGrammar.SrgsElement -> unit
Public Sub Add (element As SrgsElement)

Parameters

element
SrgsElement

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

Exceptions

element is null.

Examples

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;

Remarks

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.

Applies to

See also