SemanticResultKey.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 SemanticResultKey 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 oluşan bir örneğiSemanticResultKey.
Örnekler
Aşağıdaki örnek, arka plan rengini değiştirmek için komutları destekleyen bir Grammar nesne oluşturur.
Choices Arka plan renkleri için seçeneklerin listesini içeren bir nesne (colorChoice), yöntemi örneklerle Add(GrammarBuilder[]) birlikte kullanılarak GrammarBuilder doldurulur. ÖrneklerGrammarBuilder, renk dizelerinden oluşturulan nesneler üzerinde ToGrammarBuilder() yöntemiyle SemanticResultValue elde edilir.
GrammarBuilder Daha sonra bir örnekte çağrılarak ToGrammarBuilder()SemanticResultKey A elde edilir ve bu, içindeki colorChoiceanlamsal seçimlerin anahtarını oluşturmak için kullanılır.
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;
}
Açıklamalar
kullanımıToGrammarBuilder, bir bağımsız değişken (GrammarBuilder) olarak alan SemanticResultKey oluşturucunun GrammarBuilder(SemanticResultKey) kullanılmasıyla eşdeğerdir.