SemanticResultValue.ToGrammarBuilder Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Zwraca wystąpienie GrammarBuilder skonstruowane 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 skonstruowane z bieżącego SemanticResultValue wystąpienia.
Przykłady
Poniższy przykład tworzy Grammar obiekty, które obsługują polecenia, aby zmienić kolor tła.
ChoicesObiekt ( colorChoice ) zawierający listę opcji kolorów tła jest wypełniany przy użyciu Add(GrammarBuilder[]) metody z GrammarBuilder wystąpieniami, które są uzyskiwane z ToGrammarBuilder() metody dla SemanticResultValue obiektów utworzonych na podstawie ciągów kolorów.
A GrammarBuilder następnie jest uzyskiwany przez wywołanie ToGrammarBuilder() na SemanticResultKey wystąpieniu, które zostanie użyte do wybrania semantycznych opcji w colorChoice wystąpieniu.
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 ToGrammarBuilder jest równoważne użyciu GrammarBuilder konstruktora, który przyjmuje SemanticResultValue jako argument ( GrammarBuilder(SemanticResultValue) ).