Compartilhar via


SrgsRule.Add(SrgsElement) Método

Definição

Adiciona um SrgsElement a um SrgsRule objeto.

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

Um objeto que herda SrgsElement e especifica o que pode ser reconhecido.

Exceções

element é null.

Exemplos

O exemplo a seguir cria uma gramática que reconhece a frase "Uma nação que ganhou a Copa do Mundo é" seguida pelo nome de um país que ganhou a Copa do Mundo. Depois de criar o SrgsRule objeto winnerRule e dar-lhe o identificador WorldCupWinnerde cadeia de caracteres, o exemplo usa o Add método para acrescentar a cadeia de caracteres "Uma nação que ganhou a Copa do Mundo é" à regra. Em seguida, ruleEurope o exemplo cria duas regras adicionais e ruleSAmerica. Novamente usando o Add método, o exemplo acrescenta um SrgsOneOf objeto à WorldCupWinner regra que contém referências de regra a ruleEurope e 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;

Comentários

As adições típicas a um SrgsRule objeto incluem SrgsItem, SrgsOneOfe SrgsRuleRefSrgsToken objetos que especificam o que os alto-falantes podem dizer. Um elemento de regra válido deve conter pelo menos uma parte do texto reconhecível ou uma referência de regra.

Um SrgsRule objeto também pode conter SrgsNameValueTag e SrgsSemanticInterpretationTag objetos que adicionam valores semânticos e chaves semânticas à regra. O mecanismo de reconhecimento de fala retornará as informações semânticas, bem como a frase reconhecida, quando reconhecer a frase.

Aplica-se a