expansions — Extension expansion classes and functions module

This module contains extension rule expansion classes and functions.


class jsgf.ext.expansions.Dictation

Class representing dictation input matching any spoken words.

This is largely based on the Dictation element class in the dragonfly Python library.

Dictation expansions compile to a special reference (<DICTATION>), similar to NullRef and VoidRef. See the DictationGrammar class if you want to use this expansion type with CMU Pocket Sphinx.

The matching implementation for Dictation expansions will look ahead for possible next literals to avoid matching them and making the rule fail to match. It will also look backwards for literals in possible future repetitions.

It will not however look at referencing rules for next possible literals. If you have match failures because of this, only use Dictation expansions in public rules or use the JointTreeContext class before matching if you don’t mind reducing the matching performance.


A regex pattern for matching this expansion.

This property has been left in for backwards compatibility. The Expansion.matches method now uses the matcher_element property instead.

Returns:regex pattern object

Whether to match the current_match value next time rather than matching one or more words.

This is used by the SequenceRule.graft_sequence_matches method.


Check that the expansion is compilable. If it isn’t, this method should raise a CompilationError.



jsgf.ext.expansions.calculate_expansion_sequence(expansion, should_deepcopy=True)

Split an expansion into 2*n expansions where n is the number of Dictation expansions in the expansion tree.

If there aren’t any Dictation expansions, the result will be the original expansion.

  • expansion – Expansion
  • should_deepcopy – whether to deepcopy the expansion before using it



Take an expansion and expand any AlternativeSet with alternatives containing Dictation expansions. This function returns a list of all expanded expansions.

Parameters:expansion – Expansion