GrammarBuilder.op_Implicit Method (SemanticResultKey)
Implicitly converts a SemanticResultKey object to an instance of GrammarBuilder.
Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)
Syntax
'Declaration
Public Shared Widening Operator CType ( _
semanticKey As SemanticResultKey _
) As GrammarBuilder
public static implicit operator GrammarBuilder (
SemanticResultKey semanticKey
)
public:
static implicit operator GrammarBuilder^ (
SemanticResultKey^ semanticKey
)
Parameters
- semanticKey
Valid instance of SemanticResultKey to be implicitly converted to a containing GrammarBuilder object.
Return Value
Returns an instance of SemanticResultKey containing the logical choice defined by the semanticKey argument.
Remarks
Implicit conversion creates a new instance of GrammarBuilder.
The new instance of GrammarBuilder has its first element defined by the semanticKey argument to the constructor.
Other elements may be appended to the GrammarBuilder instance.
An instance of GrammarBuilder with elements prepending the semanticKey can be created by appending or adding other instances of GrammarBuilder.
Example
The code sample below constructs a Grammar which recognizes either of two phrases: "Make background [color]" or "Configure background as [color]" using a explicit creation of and implicit conversion to GrammarBuilder instances.
The implicit conversion of a SemanticResultKey instance to a GrammarBuilder object is highlighted in the example code below.
private Grammar CreateGrammarBuilderRGBSemantics(params int[] info) {
//Create a set of choices, each a lookup from a color name to RGB
//Choices constructors do not take SematicResultValue, so cast SematicResultValue to GramarBuilder
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor))) {
colorChoice.Add((GrammarBuilder)
(new SemanticResultValue(colorName, Color.FromName(colorName).ToARGB())));
}
GrammarBuilder choiceBuilder = new SemanticResultKey("RGB", colorChoice);
//Uses implicit conversion of SemanticResultKey to GrammarBuilder
//Create two intermediate grammars with introductory phrase and the color choice
GrammarBuilder makeBackgroundBuilder = "Make background";
makeBackgroundBuilder.Append(choiceBuilder);
GrammarBuilder configureBackgroundBuilder = new GrammarBuilder("Configure background as");
configureBackgroundBuilder.Append(new SemanticResultKey("RGB", colorChoice));
//Create the final grammar, which recognizes either intermediate grammar
Grammar grammar = new Grammar(new Choices(makeBackgroundBuilder, configureBackgroundBuilder));
grammar.Name = "Make Background /Configure background as";
return grammar;
}
Thread Safety
All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.
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
GrammarBuilder Class
GrammarBuilder Members
Microsoft.Speech.Recognition Namespace