Semantic Grammar Tags

Tags are special grammar tokens that can contain any information you wish to put in them. They are useful for transforming output — for example, an application might accept "Yes," "Yeah," or "Yes please" but return "TRUE" regardless of which is spoken. Using tags in conjunction with Semantic Interpretation for Speech Recognition (SISR), the standard method of embedding semantic interpretation information inside grammars, is the mechanism for mapping a specific input (or range of inputs) to a desired output.

Tags are placed inside ABNF grammars using curly braces ({ }) and in GrXML using the <tag> element. In both formats, the content inside a tag is identical.

ABNF Example

$yes = (yes | yeah | yes please) { out="TRUE" };

GrXML Example

<rule id="yes">
  <one-of>
    <item>yes</item>
    <item>yeah</item>
    <item>yes please</item>
  </one-of>
  <tag>out="TRUE"</tag>
</rule>

Because SISR allows ECMAScript (JavaScript) code that treats the curly brace as a reserved character, ABNF tags can also be enclosed with the three-character sequences {!{ and }!}. Both methods are equivalent, except that {!{ allows single curly braces to appear within the tag itself. GrXML does not require anything special to use curly braces within a tag.

SISR is a powerful method of embedding extra information inside tags. For a tutorial and further details, see the Introduction to Semantic Interpretation.

To use SISR within an ABNF grammar, include a tag-format declaration in your grammar's header:

#ABNF 1.0 UTF-8;
language en-US;
mode voice;
tag-format <semantics/1.0>;

The tag format value must be enclosed within angle brackets.

In GrXML, it is set as an attribute of the <grammar> element:

<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="yesorno" mode="voice" tag-format="semantics/1.0">

See the list of tag formats for the acceptable formats you may declare.

Continue to Applying Grammar Weights, the next chapter in the grammar tutorial.


Was this article helpful?