SemanticResultValue コンストラクター

定義

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

オーバーロード

名前 説明
SemanticResultValue(Object)

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

SemanticResultValue(GrammarBuilder, Object)

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

SemanticResultValue(String, Object)

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

注釈

SemanticResultValue コンストラクターは、基になるデータ型が boolintfloat、またはstringObject インスタンスの指定をサポートしています。

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

  • SemanticResultValueインスタンスは、GrammarBuilderを使用してGrammarを構築するときに、文法要素に明示的に関連付ける必要があります。

  • SemanticResultValueは、文字列値フレーズまたはGrammarBuilder オブジェクトに既に関連付けられています。

SemanticResultValue(Object)

ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs

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によって管理される値。 boolintfloat、またはstringの型である必要があります。

次の例 Grammar では、"Set/Change/Alter Foreground/Background ... [color list]" 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.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs

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によって管理される値。 boolintfloat、またはstringの型である必要があります。

次の例 Grammar では、"Set/Change/Alter Foreground/Background ... [color list]" 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では、ChoicesSemanticResultValue、およびSemanticResultKeyの暗黙的な変換がサポートされるため、このコンストラクターはこれらのオブジェクトも使用できます。

適用対象

SemanticResultValue(String, Object)

ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs
ソース:
SemanticResultValue.cs

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によって管理される値。 boolintfloat、またはstringの型である必要があります。

次の例 Grammar では、"Set/Change/Alter Foreground/Background ... [color list]" 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);

適用対象