SemanticResultKey.ToGrammarBuilder 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回從目前 GrammarBuilder 執行個體建構的 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
傳回
從目前 SemanticResultKey
執行個體建構的 GrammarBuilder 執行個體。
範例
下列範例會建立 一個 Grammar 物件,該物件支援變更背景色彩的命令。
物件 Choices (colorChoice
) 包含背景色彩選項清單的物件會使用 Add(GrammarBuilder[]) 具有 實例的方法 GrammarBuilder 填滿。 實例 GrammarBuilder 是透過 ToGrammarBuilder() 從色彩字串建立之 物件的 方法 SemanticResultValue 取得。
GrammarBuilder接著,藉由在 實例上 SemanticResultKey 呼叫 ToGrammarBuilder() 來取得 ,這個實例會用來索引中的 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;
}
備註
的用法 ToGrammarBuilder 相當於使用 GrammarBuilder 採用 作為引數的建構 SemanticResultKey 函式 (GrammarBuilder(SemanticResultKey)) 。