共用方式為


SemanticResultValue 建構函式

定義

初始化 SemanticResultValue 類別的新執行個體。

多載

SemanticResultValue(Object)

初始化 SemanticResultValue 類別的新執行個體,並指定語意值。

SemanticResultValue(GrammarBuilder, Object)

初始化 SemanticResultValue 類別的新執行個體,並且使語意值與 GrammarBuilder 物件產生關聯。

SemanticResultValue(String, Object)

初始化 SemanticResultValue 類別的新執行個體,並且使語意值與 String 物件產生關聯。

備註

這些 SemanticResultValue 函數支援指定 Object 具有 bool 、、或之基礎資料類型的 int 實例 float string

在兩種情況下,函式可以建立 SemanticResultValue 實例:

  • SemanticResultValue使用來建立時,實例必須明確與文法專案相關聯 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 所管理的值。 必須為型別 boolintfloatstring

範例

下列範例 Grammar 會傳回可辨識命令 "Set/Change/Alter 前景/Background .。。 [色彩清單]]。 SemanticResultValueSemanticResultKey 實例 (搭配使用 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;  
}  

備註

這個函式 SemanticResultValue 所傳回的不會與任何特定的文法專案相關聯。 您必須搭配使用的實例來明確地建立關聯 SemanticResultValue GrammarBuilder

例如,在下面的程式碼片段中,如果 Grammar 使用此實例所建立的可辨識 " GrammarBuilder background" 這個字, 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 所管理的值。 必須為型別 boolintfloatstring

範例

下列範例 Grammar 會傳回可辨識命令 "Set/Change/Alter 前景/Background .。。 [色彩清單]]。 SemanticResultValueSemanticResultKey 實例 (搭配使用 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);  

As 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 所管理的值。 必須為型別 boolintfloatstring

範例

下列範例 Grammar 會傳回可辨識命令 "Set/Change/Alter 前景/Background .。。 [色彩清單]]。 SemanticResultValueSemanticResultKey 實例 (搭配使用 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;  
}  

備註

如果在辨識邏輯中使用所指定的字串 phrasevalue 將會設定為可辨識輸出的語法。

在下列程式碼片段中,如果以實例建立的辨識邏輯 GrammarBuilder (myGb) 會使用字串 "my 抵押" 來識別輸入,此值 true 會加入至已辨識的語法。

myGb.Append(new SemanticResultValue("my mortgage", true);  

適用於