SemanticResultValue.ToGrammarBuilder Metoda
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Zwraca wystąpienie GrammarBuilder konstrukcji z bieżącego SemanticResultValue 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
Zwraca wystąpienie GrammarBuilder konstrukcji z bieżącego SemanticResultValue wystąpienia.
Przykłady
Poniższy przykład tworzy Grammar obiekty, które obsługują polecenia w celu zmiany koloru tła.
Choices Obiekt (colorChoice) zawierający listę opcji kolorów tła jest wypełniany przy użyciu Add(GrammarBuilder[]) metody z GrammarBuilder wystąpieniami uzyskanymi z ToGrammarBuilder() metody na SemanticResultValue obiektach utworzonych na podstawie ciągów kolorów.
Metoda A GrammarBuilder jest następnie uzyskiwana przez wywołanie ToGrammarBuilder()SemanticResultKey wystąpienia, które będzie używane do określania klucza opcji semantycznych w wystąpieniu colorChoice .
private Grammar CreateGrammarBuilderRGBSemantics()
{
// Create a set of choices, each a lookup from a color name to RBG.
// Choices constructors do not take a SemanticResultValue parameter, so
// cast SemanticResultValue to GrammarBuilder.
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))
{
// Use implicit conversion of SemanticResultValue to GrammarBuilder.
SemanticResultValue colorValue =
new SemanticResultValue(colorName, Color.FromName(colorName).ToArgb());
colorChoice.Add(colorValue.ToGrammarBuilder());
}
SemanticResultKey choiceKey = new SemanticResultKey("rgb", colorChoice);
GrammarBuilder choiceBuilder = choiceKey.ToGrammarBuilder();
// Create two intermediate grammars with an 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 final grammar, which recognizes either intermediate grammar.
Grammar grammar = new Grammar(new Choices(new GrammarBuilder[] { makeBackgroundBuilder, configureBackgroundBuilder }));
grammar.Name = "Set Background Color";
return grammar;
}
Uwagi
Użycie elementu ToGrammarBuilder jest równoważne użyciu konstruktora GrammarBuilder , który przyjmuje SemanticResultValue jako argument (GrammarBuilder(SemanticResultValue)).