SrgsRule.Add(SrgsElement) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Aggiunge un elemento SrgsElement a un oggetto 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)
Parametri
- element
- SrgsElement
Oggetto che eredita da SrgsElement e specifica che cosa può essere riconosciuto.
Eccezioni
element
è null
.
Esempio
Nell'esempio seguente viene creata una grammatica che riconosce la frase "Una nazione che ha vinto la Coppa del Mondo" seguita dal nome di un paese che ha vinto la Coppa del Mondo. Dopo aver creato l'oggetto winnerRule
e assegnandolo all'identificatore SrgsRuleWorldCupWinner
di stringa , l'esempio usa il Add metodo per aggiungere la stringa "Una nazione che ha vinto la Coppa del Mondo è" alla regola. L'esempio crea quindi due regole ruleEurope
aggiuntive e ruleSAmerica
. Di nuovo usando il metodo, nell'esempio AddWorldCupWinner
viene aggiunto un SrgsOneOf oggetto alla regola che contiene riferimenti alle regole 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;
Commenti
Le aggiunte tipiche a un SrgsRule oggetto includono SrgsItem, , SrgsOneOfSrgsRuleRefe SrgsToken oggetti che specificano quali altoparlanti possono dire. Un elemento regola valido deve contenere almeno un pezzo di testo riconoscibile o un riferimento a una regola. Per altre informazioni, vedere Creare grammatica usando SrgsGrammar .
Un SrgsRule oggetto può anche contenere SrgsNameValueTag e SrgsSemanticInterpretationTag oggetti che aggiungono valori semantici e chiavi semantiche alla regola. Il motore di riconoscimento vocale restituirà le informazioni semantiche, nonché la frase riconosciuta, quando riconosce la frase. Per altre informazioni, vedere Markup di interpretazione semantica .
Si applica a
Vedi anche
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per