SemanticResultValue.ToGrammarBuilder Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Geçerli GrammarBuilder örnekten SemanticResultValue yapılan bir örneğini döndürür.
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
Döndürülenler
Geçerli GrammarBuilder örnekten SemanticResultValue yapılan bir örneğini döndürür.
Örnekler
Aşağıdaki örnek, arka plan rengini değiştirmek için komutları destekleyen nesneler oluşturur Grammar .
Choices Arka plan renkleri seçeneklerinin listesini içeren bir nesne (colorChoice) yöntemi kullanılarak, renk dizelerinden oluşturulan nesnelerde Add(GrammarBuilder[]) yönteminden GrammarBuilder alınan örneklerle ToGrammarBuilder() doldurulurSemanticResultValue.
GrammarBuilder Daha sonra bir örnekte çağrılarak ToGrammarBuilder()SemanticResultKey A elde edilir ve bu örnekteki anlamsal seçimlerin colorChoice anahtarı için kullanılır.
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;
}
Açıklamalar
kullanımıToGrammarBuilder, bağımsız değişken (GrammarBuilder) olarak alan SemanticResultValue oluşturucunun GrammarBuilder(SemanticResultValue) kullanılmasıyla eşdeğerdir.