SemanticResultValue Constructor (String, Object)
Creates a new instance of SemanticResultValue with a given value and associates it with a phrase.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Public Sub New ( _
phrase As String, _
value As Object _
)
public SemanticResultValue (
string phrase,
Object value
)
public:
SemanticResultValue (
String^ phrase,
Object^ value
)
public SemanticResultValue (
String phrase,
Object value
)
public function SemanticResultValue (
phrase : String,
value : Object
)
Parameters
- phrase
A String containing a phrase specifying words to be used in recognition.
- value
An instance of Object specifying the value the SemanticResultValue managed. Must be of type bool, int, float, or string.
Remarks
If the string specified by phrase is used in the logic of recognition, 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 string "my mortgage" to identify input, the value true will be added to the recognized semantics.
myGb.Append(new SemanticResultValue("my mortgage", true);
Example
The example below returns a Grammar for recognizing the command "Set/Change/Alter Foreground/Background … [color list]". SemanticResultValue, and SemanticResultKey instances (along with Choices and GrammarBuilder objects) are used to define a semantics that can be parsed on recognition to determine what color was request, and whether the foreground or background is to be modified.
The use of SemanticResultValue is highlighted.
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);
//Now define the arguments to the command for Foreground or background and color as sementic 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))) {
colorChoice.Add((GrammarBuilder)
(new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));
//Uses implicit conversion of SemanticResultValue to GrammarBuilder
}
//Create GrammarBuilder for CmdArgs to be appended to CmdInto 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;
}
Platforms
Development Platforms
Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition
Target Platforms
See Also
Reference
SemanticResultValue Class
SemanticResultValue Members
Microsoft.Speech.Recognition Namespace