Complete Example Grammars with SI Markup
This page contains two complete examples of grammars that contain markup for semantic interpretation (SI). Unlike the simplified grammar examples in other parts of the SI Help documents, the first six lines in these examples contain all the attribute-value pairs that are required or recommended by the World Wide Web Consortium (W3C) Speech Recognition Grammar Specification (SRGS) Version 1.0. Also, the grammar in Plan_itinerary.grxml contains rule references to the grammar in Time_information.grxml. It is an accepted convention to use the .grxml file extension for XML-based grammar documents that conform to the SRGS specification. The examples contain line numbers to simplify the identification of specific lines for comment in the notes sections.
Plan_itinerary.grxml
Notes on Plan_itinerary.grxml
Line 5: |
A grammar must specify a root rule. |
Line 6: |
A base URI (xml:base) is recommended, but is not required. |
Line 6: |
The tag-format attribute must have the value "semantics/1.0" or "semantics-ms/1.0" to activate semantic interpretation. |
Line 10: |
The airports value for the uri attribute of the ruleref element indicates a reference to a rule element with its id attribute set to airports that is located within the same grammar. |
Line 10: |
The expression, out.departFrom=rules.airports;, assigns the value of the Rule Variable for the rule named airports to the property named departFrom of the Rule Variable for the rule named itinerary. The value of Rule Variable for the rule named airports is generated by the tag elements in the airports rule. |
Line 12: |
Because the example grammar file Time_information.grxml (below) specifies flightDays as its root rule, flightDays is automatically a publicly-scoped rule. A ruleref element that specifies only the bare URI of a grammar file without specifying a rule within the grammar file references its root rule by default. |
Line 14: |
The flightTimes rule in the Time_information.grxml grammar file (below) is referenced in line 13. Although it is not the root rule in the Time_information.grxml grammar file, a value can be read from the flightTimes Rule Variable because the scope of flightTimes is set to public. |
Line 15: |
The special rule name, GARBAGE, matches any speech until the next rule match, the next token, or the end of spoken input. In this example, the speaker can say anything in between saying a relative time, such as "Afternoon" and "and arriving at." |
Line 24: |
Because the scope attribute is not explicitly specified for the airports rule, the scope is set to private by default. As a consequence, values generated by this rule can be referenced only by rules contained within the same grammar and not by rules contained in other grammars. |
Time_information.grxml
Notes on Time_information.grxml
Line 16: |
Because the scope of the flightTimes rule has been set to public, values generated by this rule can be read by rules outside of this grammar. |