Specifying the Content of Semantic Results
This document describes how the semantic interpreter generates semantic results, the model and syntax of semantic interpretation script expressions, and how to prepare a grammar for semantic interpretation.
How Semantic Results are Generated
Every rule element in a grammar has a single Rule Variable that holds a semantic value which may be composed of multiple properties. This Rule Variable is identified by a dollar sign ("$") and it is formally referred to as the Grammar Rule Name (GRN) Rule Variable (see Grammar Rule Name Referencing).
The semantic values that are associated with a Rule Variable consist of the recognized text and the recognition confidence score that are generated when the recognizer matches the user's speech to the words or phrases that are defined by the rule. The semantic value corresponding to the highest level rule in the grammar (the root rule) is serialized and returned in the Semantic Markup Language (SML) output. Because a valid grammar contains a single root rule element, the semantic values that are returned in the SML output consist of the recognized text and recognition confidence score for the complete set of words and phrases in an utterance that match a path through the whole grammar.
Application developers can use script expressions that are contained in tag elements to generate semantic values for items that are contained in the rule, and associate these item-specific values with the Rule Variable as properties of the Rule Variable. Developers can also assign the semantic value of sub-rules (referenced rules) in the grammar to the Rule Variable of the higher level containing rule. The values generated by script expressions are not explicitly typed, and they can be of any type defined in ECMA-327. See Using the <tag> Element for more information.
Script Expression Syntax
The model and syntax of semantic interpretation that is implemented in the Microsoft Speech Application SDK Version 1.1 (SASDK) is based on the W3C working draft of Semantic Interpretation for Speech Recognition with two exceptions:
- The SASDK does not recognize use of the $$$.text variable. Use $$._value instead to read the text property of the last rule reference.
- The SASDK does not support Augmented Backus-Naur Form (ABNF) grammars. Use only XML form grammars.
The scripting language supported by this specification is ECMA-327, which is implemented in the SASDK with the Microsoft JScript interpreter.
Preparing a Grammar for Semantic Interpretation
The tag-format attribute of the root grammar element identifies the type of semantic interpretation markup in a grammar. For grammars used with the SASDK, this value must be semantics-ms/1.0:
<grammar tag-format="semantics-ms/1.0" root="rootrulename">
Note After an author adds semantic interpretation markup to the grammar, in addition to the utteranceConfidence, the recognized text, and the confidence attributes for the root rule, only values generated by script expressions contained in tag elements appear in the SML output. Refer to SML Output Overview in the SML Reference for more information and examples.