Κοινή χρήση μέσω


SemanticResultValue Constructors

Definition

Initializes a new instance of the SemanticResultValue class.

Overloads

SemanticResultValue(Object)

Initializes a new instance of the SemanticResultValue class and specifies a semantic value.

SemanticResultValue(GrammarBuilder, Object)

Initializes a new instance of the SemanticResultValue class and associates a semantic value with a GrammarBuilder object.

SemanticResultValue(String, Object)

Initializes a new instance of the SemanticResultValue class and associates a semantic value with a String object.

Remarks

The SemanticResultValue constructors support specifying an Object instance with an underlying data type of bool, int, float, or string.

A constructor can create a SemanticResultValue instance in either of two circumstances:

  • The SemanticResultValue instance must be explicitly associated with a grammar element when using a GrammarBuilder to construct a Grammar.

  • The SemanticResultValue is already associated with a string value phrase or a GrammarBuilder object.

SemanticResultValue(Object)

Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs

Initializes a new instance of the SemanticResultValue class and specifies a semantic value.

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)

Parameters

value
Object

The value managed by SemanticResultValue. Must be of type bool, int, float, or string.

Examples

The following example returns a Grammar that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". SemanticResultValue and SemanticResultKey instances (in conjunction with Choices and GrammarBuilder objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.

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;
}

Remarks

A SemanticResultValue returned by this constructor is not associated with any particular grammar element. The association must be made explicit by using the instance of SemanticResultValue in conjunction with GrammarBuilder.

For instance, in the code fragment below, if a Grammar constructed using this GrammarBuilder instance recognizes the word "background", a value of true is set in the recognized phrase semantics.

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

Applies to

SemanticResultValue(GrammarBuilder, Object)

Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs

Initializes a new instance of the SemanticResultValue class and associates a semantic value with a GrammarBuilder object.

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)

Parameters

builder
GrammarBuilder

A grammar component to be used in recognition.

value
Object

The value managed by SemanticResultValue. Must be of type bool, int, float, or string.

Examples

The following example returns a Grammar that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". SemanticResultValue and SemanticResultKey instances (in conjunction with Choices and GrammarBuilder objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.

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;
}

Remarks

If the grammar element specified by GrammarBuilder is used in the recognition logic, value will be set in the semantics of the recognized output.

In the code fragment below, if the recognition logic constructed with the GrammarBuilder instance (myGb) uses the Choices object (myChoice) to identify input, the value true is added to the recognized semantics.

myGb.Append(new SemanticResultValue(myChoice, true);

As GrammarBuilder supports implicit conversion for Choices, SemanticResultValue, and SemanticResultKey, this constructor can use those objects as well.

Applies to

SemanticResultValue(String, Object)

Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs
Source:
SemanticResultValue.cs

Initializes a new instance of the SemanticResultValue class and associates a semantic value with a String object.

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)

Parameters

phrase
String

A phrase to be used in recognition.

value
Object

The value managed by SemanticResultValue. Must be of type bool, int, float, or string.

Examples

The following example returns a Grammar that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". SemanticResultValue and SemanticResultKey instances (in conjunction with Choices and GrammarBuilder objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.

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;
}

Remarks

If the string specified by phrase is used in the recognition logic, value will be set in the semantics of the recognized output.

In the following code fragment, if the recognition logic constructed with the GrammarBuilder instance (myGb) uses the string "my mortgage" to identify input, the value true will be added to the recognized semantics.

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

Applies to