SemanticResultKey.ToGrammarBuilder Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un'istanza di GrammarBuilder costruita dall'istanza corrente SemanticResultKey .
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
Valori restituiti
Istanza di GrammarBuilder costruita dall'istanza corrente SemanticResultKey .
Esempio
Nell'esempio seguente viene creato un Grammar oggetto che supporta i comandi per modificare il colore di sfondo.
Un Choices oggetto (colorChoice) contenente l'elenco di opzioni per i colori di sfondo viene riempito usando il Add(GrammarBuilder[]) metodo con GrammarBuilder le istanze di . Le GrammarBuilder istanze vengono ottenute tramite il ToGrammarBuilder() metodo sugli SemanticResultValue oggetti creati da stringhe di colore.
Un GrammarBuilder oggetto viene quindi ottenuto chiamando ToGrammarBuilder() su un'istanza SemanticResultKey di , che verrà usata per la chiave delle scelte semantiche in 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;
}
Commenti
L'uso di ToGrammarBuilder è equivalente all'uso del GrammarBuilder costruttore che accetta SemanticResultKey come argomento (GrammarBuilder(SemanticResultKey)).