SrgsOneOf.Add(SrgsItem) Methode

Definition

Fügt eine SrgsItem, die ein Wort oder einen Ausdruck enthält, der Liste von Alternativen hinzu.

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

Parameter

item
SrgsItem

Das Element, das der Liste von Alternativen hinzugefügt werden soll.

Ausnahmen

item ist null.

Beispiele

Im folgenden Beispiel wird eine Grammatik erstellt, die den Ausdruck "Eine Nation, die die Weltmeisterschaft gewonnen hat" erkennt, gefolgt vom Namen eines Landes/einer Region, die die Weltmeisterschaft gewonnen hat. Im Beispiel wird das SrgsOneOf -Objekt verwendet, um Listen mit zulässigen Landes-/Regionsnamen aus einem Array von SrgsItem Objekten zu erstellen. Mithilfe der Add -Methode fügt das Beispiel eine SrgsItem an, die die Zeichenfolge "Italy" an das SrgsOneOf -Objekt oneOfEuropeenthält.

public void WorldSoccerWinners ()
{

  // 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")});
  oneOfEurope.Add(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;
}

Gilt für:

Weitere Informationen