SemanticResultKey.ToGrammarBuilder Metoda

Definicja

Zwraca wystąpienie skonstruowane GrammarBuilder z bieżącego SemanticResultKey wystąpienia.

public:
 System::Speech::Recognition::GrammarBuilder ^ ToGrammarBuilder();
public System.Speech.Recognition.GrammarBuilder ToGrammarBuilder ();
member this.ToGrammarBuilder : unit -> System.Speech.Recognition.GrammarBuilder
Public Function ToGrammarBuilder () As GrammarBuilder

Zwraca

GrammarBuilder

Wystąpienie skonstruowane GrammarBuilder z bieżącego SemanticResultKey wystąpienia.

Przykłady

Poniższy przykład tworzy Grammar obiekt, który obsługuje polecenia, aby zmienić kolor tła.

Choices Obiekt (colorChoice) zawierający listę opcji kolorów tła jest wypełniony przy użyciu Add(GrammarBuilder[]) metody z wystąpieniamiGrammarBuilder. Wystąpienia GrammarBuilder są uzyskiwane za pośrednictwem ToGrammarBuilder() metody na SemanticResultValue obiektach utworzonych na podstawie ciągów kolorów.

Element A GrammarBuilder jest następnie uzyskiwany przez wywołanie ToGrammarBuilder() SemanticResultKey wystąpienia, które będzie używane do określania klucza opcji semantycznych w programie colorChoice.

private Grammar CreateGrammarBuilderRGBSemantics()   
{  

  // Create a set of choices, each a lookup from a color name to RGB.  
  // Choices constructors do not take SemanticResultValue parameters, so cast   
  // the SemanticResultValue to GrammarBuilder.  
  Choices colorChoice = new Choices();  
  foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))   
  {  
    SemanticResultValue colorValue=new SemanticResultValue(colorName, Color.FromName(colorName).ToArgb());  

    // Use implicit conversion of SemanticResultValue to GrammarBuilder.  
    colorChoice.Add(colorValue.ToGrammarBuilder());      
  }  
  SemanticResultKey choiceKey = new SemanticResultKey("rgb", colorChoice);  
  GrammarBuilder choiceBuilder = choiceKey.ToGrammarBuilder();  

  // Create two intermediate grammars with introductory phrase and the color choice.  
  GrammarBuilder makeBackgroundBuilder = "Make background";  
  makeBackgroundBuilder.Append(choiceBuilder);  

  GrammarBuilder configureBackgroundBuilder = new GrammarBuilder("Configure background as");  
  configureBackgroundBuilder.Append((new SemanticResultKey("rgb", colorChoice)).ToGrammarBuilder());  

  // Create the Grammar object, which recognizes either intermediate grammar.  
  Grammar grammar = new Grammar(new Choices(new GrammarBuilder[] {makeBackgroundBuilder, configureBackgroundBuilder}));  
  grammar.Name = "Make Background /Configure background as";  

  return grammar;  
}  

Uwagi

Użycie ToGrammarBuilder jest równoważne użyciu konstruktora GrammarBuilder , który przyjmuje SemanticResultKey jako argument (GrammarBuilder(SemanticResultKey)).

Dotyczy