Condividi tramite


SrgsRule.Add(SrgsElement) Metodo

Definizione

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 SrgsRulewinnerRule e aver specificato l'identificatore WorldCupWinnerdi 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 aggiuntive e ruleEuroperuleSAmerica. Anche in questo caso usando il Add metodo , nell'esempio viene aggiunto un SrgsOneOf oggetto alla WorldCupWinner 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 SrgsItemoggetti , SrgsOneOf, SrgsRuleRefe SrgsToken che specificano gli altoparlanti che possono pronunciare. Un elemento di regola valido deve contenere almeno una parte di testo riconoscibile o un riferimento a una regola. Per altre informazioni, vedere Creare grammatiche usando SrgsGrammar .

Un SrgsRule oggetto può anche contenere SrgsNameValueTag oggetti e SrgsSemanticInterpretationTag 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