SrgsRule.Add(SrgsElement) Método

Definición

Agrega SrgsElement a un objeto SrgsRule.

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)

Parámetros

element
SrgsElement

Un objeto que hereda de SrgsElement y especifica qué se puede reconocer.

Excepciones

element es null.

Ejemplos

En el ejemplo siguiente se crea una gramática que reconoce la frase "Una nación que ha ganado la Copa Mundial" seguida del nombre de un país que ha ganado la Copa Mundial. Después de crear el SrgsRule objeto winnerRule y darle el identificador WorldCupWinnerde cadena , el ejemplo usa el Add método para anexar la cadena "Una nación que ha ganado la Copa Mundial" a la regla. A continuación, en el ejemplo se crean dos reglas adicionales y ruleEuroperuleSAmerica. De nuevo con el Add método , el ejemplo anexa un SrgsOneOf objeto a la WorldCupWinner regla que contiene referencias de regla a ruleEurope y 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;

Comentarios

Las adiciones típicas a un SrgsRule objeto incluyen SrgsItem, SrgsOneOf, SrgsRuleRefy SrgsToken objetos que especifican lo que los hablantes pueden decir. Un elemento de regla válido debe contener al menos un fragmento de texto reconocible o una referencia de regla. Consulte Creación de gramáticas mediante SrgsGrammar para obtener más información.

Un SrgsRule objeto también puede contener SrgsNameValueTag objetos y SrgsSemanticInterpretationTag que agregan valores semánticos y claves semánticas a la regla. El motor de reconocimiento de voz devolverá la información semántica, así como la frase reconocida, cuando reconoce la frase. Consulte Marcado de interpretación semántica para obtener más información.

Se aplica a

Consulte también