Export (0) Print
Expand All

SemanticResultValue.SemanticResultValue(Object) Constructor

Constructs an instance of SemanticResultValue with a specified value.

Namespace: System.Speech.Recognition
Assembly: System.Speech (in system.speech.dll)

public SemanticResultValue (
	Object value
)
public SemanticResultValue (
	Object value
)
public function SemanticResultValue (
	value : Object
)
Not applicable.

Parameters

value

An instance of Object specifying the value the SemanticResultValue managed. Must be of type bool, int, float, or string.

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

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 System.Speech.Recognition.SemanticResultValue is highlighted, as are the explicit association of returned SemanticResultValue instances with grammar elements.


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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft