SemanticResultValue 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 SemanticResultValue 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| SemanticResultValue(Object) |
初始化該類別的新實例 SemanticResultValue 並指定語意值。 |
| SemanticResultValue(GrammarBuilder, Object) |
初始化該類別的新實例 SemanticResultValue ,並將語意值與 GrammarBuilder 物件關聯。 |
| SemanticResultValue(String, Object) |
初始化該類別的新實例 SemanticResultValue ,並將語意值與 String 物件關聯。 |
備註
建 SemanticResultValue 構子支援指定 Object 一個實例,其底層資料型態為 bool、 int、 float或 string。
建構子可以在兩種情況下建立實 SemanticResultValue 例:
SemanticResultValue在使用 a GrammarBuilder 來構造 Grammar。該
SemanticResultValue已經與字串值片語或 GrammarBuilder 物件相關聯。
SemanticResultValue(Object)
初始化該類別的新實例 SemanticResultValue 並指定語意值。
public:
SemanticResultValue(System::Object ^ value);
public SemanticResultValue(object value);
new System.Speech.Recognition.SemanticResultValue : obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (value As Object)
參數
- value
- Object
由 SemanticResultValue管理的值。 必須是類型 bool、 int、 float、 或 string。
範例
以下範例回傳 a Grammar ,該指令識別指令「Set/Change/Alter Foreground/Background ... [顏色列表]」。 SemanticResultValue SemanticResultKey而實例(與Choices物件GrammarBuilder結合)則用來定義可於識別時解析的語意。 解析後的語意將決定所請求的顏色,以及是否要修改前景或背景。
private Grammar FgBgColorGrammar()
{
Grammar grammar = null;
// Allow the command to begin with set, alter, change.
Choices introChoices = new Choices();
foreach (string introString in new string[] { "Change", "Set", "Alter" })
{
GrammarBuilder introGB = new GrammarBuilder(introString);
introChoices.Add(
new SemanticResultValue(introGB,
String.Format("Command: {0}", introString)));
}
GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);
// Define the arguments for the command to select foreground or background
// and to change their color as semantic values.
Choices fgOrbgChoice = new Choices();
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
fgOrbgChoice.Add(backgroundGB);
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));
SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))
{
// Use implicit conversion of SemanticResultValue to GrammarBuilder.
colorChoice.Add(
(GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));
}
// Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using
// semantic keys.
GrammarBuilder cmdArgs = new GrammarBuilder();
cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));
cmdArgs.AppendWildcard();
cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));
GrammarBuilder cmds =
GrammarBuilder.Add(
cmdIntro,
new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));
grammar = new Grammar(cmds);
grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";
return grammar;
}
備註
此構造子回傳的 A SemanticResultValue 並不與任何特定文法元素相關聯。 該關聯必須透過結合 的SemanticResultValueGrammarBuilder實例來明確表達。
例如,在下方的程式碼片段中,若 Grammar 使用此 GrammarBuilder 實例的建構者識別「背景」一詞,則在識別的語意中設定了 的 true 值。
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
適用於
SemanticResultValue(GrammarBuilder, Object)
初始化該類別的新實例 SemanticResultValue ,並將語意值與 GrammarBuilder 物件關聯。
public:
SemanticResultValue(System::Speech::Recognition::GrammarBuilder ^ builder, System::Object ^ value);
public SemanticResultValue(System.Speech.Recognition.GrammarBuilder builder, object value);
new System.Speech.Recognition.SemanticResultValue : System.Speech.Recognition.GrammarBuilder * obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (builder As GrammarBuilder, value As Object)
參數
- builder
- GrammarBuilder
一個用於識別的文法成分。
- value
- Object
由 SemanticResultValue管理的值。 必須是類型 bool、 int、 float、 或 string。
範例
以下範例回傳 a Grammar ,該指令識別指令「Set/Change/Alter Foreground/Background ... [顏色列表]」。 SemanticResultValue SemanticResultKey而實例(與Choices物件GrammarBuilder結合)則用來定義可於識別時解析的語意。 解析後的語意將決定所請求的顏色,以及是否要修改前景或背景。
private Grammar FgBgColorGrammar()
{
Grammar grammar = null;
// Allow the command to begin with set, alter, change.
Choices introChoices = new Choices();
foreach (string introString in new string[] { "Change", "Set", "Alter" })
{
GrammarBuilder introGB = new GrammarBuilder(introString);
introChoices.Add(
new SemanticResultValue(introGB,
String.Format("Command: {0}", introString)));
}
GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);
// Define the arguments for the command to select foreground or background
// and to change their color as semantic values.
Choices fgOrbgChoice = new Choices();
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
fgOrbgChoice.Add(backgroundGB);
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));
SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))
{
// Use implicit conversion of SemanticResultValue to GrammarBuilder.
colorChoice.Add(
(GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));
}
// Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using
// semantic keys.
GrammarBuilder cmdArgs = new GrammarBuilder();
cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));
cmdArgs.AppendWildcard();
cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));
GrammarBuilder cmds =
GrammarBuilder.Add(
cmdIntro,
new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));
grammar = new Grammar(cmds);
grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";
return grammar;
}
備註
若 指定的 GrammarBuilder 文法元素被用於識別邏輯, value 則 會被設定在已識別輸出的語意中。
在下方的程式碼片段中,若用 GrammarBuilder 實例(myGb)建構的識別邏輯使用 Choices 物件(myChoice)來識別輸入,則該值 true 會被加入已識別的語意中。
myGb.Append(new SemanticResultValue(myChoice, true);
由於 GrammarBuilder 支援隱 Choices含轉換 、 SemanticResultValue、 SemanticResultKey和 ,此建構子也能使用這些物件。
適用於
SemanticResultValue(String, Object)
初始化該類別的新實例 SemanticResultValue ,並將語意值與 String 物件關聯。
public:
SemanticResultValue(System::String ^ phrase, System::Object ^ value);
public SemanticResultValue(string phrase, object value);
new System.Speech.Recognition.SemanticResultValue : string * obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (phrase As String, value As Object)
參數
- phrase
- String
一個用來辨識的詞句。
- value
- Object
由 SemanticResultValue管理的值。 必須是類型 bool、 int、 float、 或 string。
範例
以下範例回傳 a Grammar ,該指令識別指令「Set/Change/Alter Foreground/Background ... [顏色列表]」。 SemanticResultValue SemanticResultKey而實例(與Choices物件GrammarBuilder結合)則用來定義可於識別時解析的語意。 解析後的語意將決定所請求的顏色,以及是否要修改前景或背景。
private Grammar FgBgColorGrammar()
{
Grammar grammar = null;
// Allow command to begin with set, alter, change.
Choices introChoices = new Choices();
foreach (string introString in new string[] { "Change", "Set", "Alter" })
{
GrammarBuilder introGB = new GrammarBuilder(introString);
introChoices.Add(
new SemanticResultValue(introGB,
String.Format("Command: {0}", introString)));
}
GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);
// Define the arguments for the command to select foreground or background
// and to change their color as semantic values.
Choices fgOrbgChoice = new Choices();
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
fgOrbgChoice.Add(backgroundGB);
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));
SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))
{
// Use implicit conversion of SemanticResultValue to GrammarBuilder.
colorChoice.Add(
(GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));
}
// Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using
// semantic keys.
GrammarBuilder cmdArgs = new GrammarBuilder();
cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));
cmdArgs.AppendWildcard();
cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));
GrammarBuilder cmds =
GrammarBuilder.Add(cmdIntro,
new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));
grammar = new Grammar(cmds);
grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";
return grammar;
}
備註
若 指定的 phrase 字串用於識別邏輯, value 則 會設定在已識別輸出的語意中。
在以下程式碼片段中,若以 GrammarBuilder 實例myGb()建構的識別邏輯使用字串「my mortgage」來識別輸入,該值 true 將被加入已識別的語意中。
myGb.Append(new SemanticResultValue("my mortgage", true);