SemanticResultValue クラス

定義

セマンティクス値を表し、必要に応じて、音声認識文法のコンポーネントに値を関連付けます。

public ref class SemanticResultValue
public class SemanticResultValue
type SemanticResultValue = class
Public Class SemanticResultValue
継承
SemanticResultValue

次の例では、"Set/Change/Alter Foreground/Background ... コマンドを認識する を返 Grammar します。 [color list]" SemanticResultValueおよび SemanticResultKey インスタンス (および GrammarBuilder オブジェクトとChoices組み合わせて) は、認識時に解析できるセマンティクスを定義するために使用されます。 解析されたセマンティクスは、要求された色と、前景と背景のどちらを変更するかを決定します。

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 と組み合わせてGrammarBuilderChoices使用することは、 のセマンティック構造Grammarを設計する最も簡単な方法SemanticResultKeyです。 句のセマンティック情報にアクセスするには、 の プロパティRecognizedPhraseを使用して のSemanticValueインスタンスをSemantics取得します。

注意

オブジェクトによって管理される SemanticResultValue 値は、コンストラクターに渡されるインスタンスによって Object 定義されます。 このObjectの基になる型は、、、intfloat、または stringである必要がありますbool。 その他の型では、 を使用SemanticResultValueしてインスタンスをGrammar構築できなくなります。

インスタンスの一般的な SemanticResultValue 使用方法は、インスタンスを、 の認識可能なコンポーネント Grammar(フレーズ、ルール、 Choices オブジェクトなど) に関連付けます。 関連付けられたコンポーネントが認識操作の一部として使用される場合、 は、 SemanticResultValue 返されるフレーズのセマンティクスで値を定義するために使用されます。

インスタンスを SemanticResultValue 文法要素に関連付ける基本的なメソッドは、 の作成 SemanticResultValueに使用されるコンストラクターに応じて 2 つあります。

  • (のインスタンスで指定された) 値のみがオブジェクトの Object構築 SemanticResultValue に使用される場合、 SemanticResultValue は オブジェクトに加えて、その前の文法コンポーネントに GrammarBuilder 関連付けられます。

    たとえば、次のコード フラグメントでは、このGrammarBuilderインスタンスをGrammar使用して構築された が "background" という単語を認識した場合、認識されたフレーズ セマンティクスで のtrue値が設定されます。

    GrammarBuilder backgroundGB=new GrammarBuilder("background");
    backgroundGB.Append(new SemanticResultValue(true));
    

    詳細については、SemanticResultValue(Object) の説明を参照してください。

  • 文字列値フレーズまたは特定GrammarBuilderのインスタンスが、値を指定SemanticResultValueする と共Objectに使用される場合、その値は文字列値フレーズまたはインスタンスに自動的にGrammarBuilder関連付けられます。 認識の過程でフレーズまたは GrammarBuilder オブジェクトが使用されている場合、その値は認識されたフレーズのセマンティクスに割り当てられます。

    次の例は、これを示しています。これは、 と への明示的な呼び出しを使用した前の例とSemanticResultValue(Object)機能的にAppend同等です。 認識ロジックで "background" という単語が使用されている場合、その値 true は認識されたセマンティクスに追加されます。

    fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("background", true));
    

    詳細については、 と SemanticResultValue(String, Object)の説明SemanticResultValue(GrammarBuilder, Object)を参照してください。

認識で によってGrammar使用される場合、すべてのSemanticResultValueインスタンスは、その Grammarによって使用されるオブジェクトのいずれかにSemanticValue関連付けられている必要があります。 これは、セマンティック キー SemanticResultValueを に関連付けることによって行われます。

セマンティック キーは、 オブジェクトを使用して SemanticResultValueSemanticResultKey に明示的にアタッチできます。 SemanticResultValue キーに明示的にアタッチされていないインスタンスは、既定 SemanticValueの のルート キーにアタッチされます。

SemanticResultValueを使用して をValue設定した後は、既定のルート キーでタグ付けされているか、特定SemanticResultKeyの によってタグ付けされているかに関係なく、その値を変更しないでください。認識操作中に例外が発生します。

次の例では、 のルート Value を設定して変更するため、例外が Grammar発生します。

GrammarBuilder gb=new GrammarBuilder();
gb.Append(new SemanticResultValue("One"));
gb.Append(new SemanticResultValue("Two"));

一方、次の例のコードは許可されています。 の複数の SemanticResultValueインスタンスを定義しますが、これらは オブジェクトに Choices 含まれており、キー bgOrfgTextの値を設定するために使用されるのは 1 つだけです。

Choices fgOrbgChoice = new Choices();
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("background"));
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground"));
SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgText", fgOrbgChoice);

コンストラクター

SemanticResultValue(GrammarBuilder, Object)

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

SemanticResultValue(Object)

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

SemanticResultValue(String, Object)

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

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToGrammarBuilder()

現在の GrammarBuilder インスタンスから構築された SemanticResultValue のインスタンスを返します

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください