How do I implement recursive grammars?
Last reviewed: 11/4/1998
HOW Article ID: H119801
The information in this article applies to:
- SpeechKit 2.1
Summary
I am looking to attach Grammars to specific edit controls. I viewed the Chant samples and I found the numbers.bnf sample.
<number> = <_digit>+ .
<_digit> = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 .
This sample I believe uses a recursive vocabulary. I do not believe that Microsoft speech API allows recursive grammars. In SAPI 4 this means I cannot do the following:
<number> = <_bigNumber> | <_smallNumber> .
<_bigNumber> = <smallNumber> <smallNumber> .
<_smallNumber> = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 .
But you can do:
<number> = <_smallNumber>+
or
<number> = <bigNumber> | <_smallNumber> .
<_smallNumber> = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 .
and use a separate grammar
<bignumber> = <_digit> | <_teens> .
<_digit> = 1 | 2 ... .
<_teens> = 11 | 12 ... .
The + says that the small number may occur one or more times which is valid. An * says that the small number may occur 0 (optional) or more times. Both are legitimate rules and the Chant component grammar compiler builds the chunks for SAPI 4 to handle these.
More Information
My goal is to get the edit control to display things like 11.6 when the user says 11 feet 6 inches.
<height> = <_number> feet <_inchNumber> inches
| <_number> feet // For "x feet" only
| <_inchNumber> inches // For "x inches" only
.
<_number> = 1 | 2 | 3 | ... .
<_inchNumber> = 1 | 2 | .... 11 .
If you need a greater domain for number (i.e., the need to have a tree bnf), then create a separate grammar for number like the numbers sample. and change the reference in the above grammar to
<number>
In SAPI 4 you can export grammar rules by omitting the "_" in the name.