次の方法で共有


SemanticResultValue コンストラクター

定義

SemanticResultValue クラスの新しいインスタンスを初期化します。

オーバーロード

SemanticResultValue(Object)

SemanticResultValue クラスの新しいインスタンスを初期化して、セマンティクス値を指定します。

SemanticResultValue(GrammarBuilder, Object)

SemanticResultValue クラスの新しいインスタンスを初期化して、セマンティクス値と GrammarBuilder オブジェクトを関連付けます。

SemanticResultValue(String, Object)

SemanticResultValue クラスの新しいインスタンスを初期化して、セマンティクス値と String オブジェクトを関連付けます。

注釈

SemanticResultValueコンストラクターは、、、 Object 、またはの基になるデータ型のインスタンスの指定をサポート bool int float string します。

コンストラクターは、 SemanticResultValue 次の2つの状況のいずれかでインスタンスを作成できます。

  • 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 で管理された値。 bool 型、int 型、float 型、または string 型である必要があります。

次の例では、 Grammar コマンド "Set/Change/Alter 前景/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;  
}  

注釈

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 で管理された値。 bool 型、int 型、float 型、または string 型である必要があります。

次の例では、 Grammar コマンド "Set/Change/Alter 前景/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 型である必要があります。

次の例では、 Grammar コマンド "Set/Change/Alter 前景/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 抵当" を使用して入力を識別すると、その値が認識される true セマンティクスに追加されます。

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

適用対象