grammars — Extension grammar classes module¶
This module contains extension grammar classes.
DictationGrammar(rules=None, name='default', case_sensitive=False)¶
Grammar subclass that processes rules using
Dictationexpansions so they can be compiled, matched and used with normal JSGF rules with utterance breaks.
- rules – list
- name – str
- case_sensitive – bool
Add a rule to the grammar.
This method will override the new rule’s
case_sensitivevalue with the grammar’s
Parameters: rule – Rule Raises: GrammarError
Compile this grammar’s header, imports and rules into a string that can be recognised by a JSGF parser.
Compile this grammar with one public “root” rule containing rule references in an alternative set to every other rule as such:
public <root> = (<rule1>|<rule2>|..|<ruleN>); <rule1> = ...; <rule2> = ...; . . . <ruleN> = ...;
This is useful if you are using JSGF grammars with CMU Pocket Sphinx.
Find each visible rule passed to the grammar that matches the speech string. Also set matches for the original rule.
- speech – str
- advance_sequence_rules – whether to call
set_next()for successful sequence rule matches.
Get the rules generated from a rule added to this grammar.
Parameters: rule – Rule Returns: generator
Get the original rule from a generated rule.
Parameters: rule – Rule Returns: Rule
The rules that the
find_matching_rulesmethod will match against.
SequenceRulein this grammar between the dictation rules list and the internal grammar used for JSGF only rules depending on whether a
SequenceRule’s current expansion is dictation-only or not.
Remove a rule from this grammar.
- rule – Rule object or the name of a rule in this grammar
- ignore_dependent – whether to check if the rule has dependent rules
SequenceRulein this grammar so that they can accept matches again.
The rules in this grammar.
This includes internal generated rules as well as original rules.