rules — Extension rule classes module

This module contains extension rule classes.

Classes

class jsgf.ext.rules.SequenceRule(name, visible, expansion, case_sensitive=False)

Class representing a list of regular expansions and Dictation expansions that must be spoken in a sequence.

can_repeat

Whether the entire SequenceRule can be repeated multiple times.

Note that if the rule can be repeated, data from a repetition of the rule, such as current_match values of each sequence expansion, should be stored before restart_sequence is called for a further repetition.

compile(ignore_tags=False)

Compile this rule’s expansion tree and return the result. Set ignore_tags to True to not include expansion tags in the result.

Parameters:ignore_tags – bool
Returns:str
current_is_dictation_only

Whether the current expansion in the sequence contains only Dictation expansions.

Returns:bool
entire_match

If the entire sequence is matched by successive calls to the matches method, this returns all strings that matched joined together by spaces.

Returns:str
expansion_sequence

The expansion sequence used by the rule.

Returns:tuple
static graft_sequence_matches(sequence_rule, expansion)

Take a SequenceRule and an expansion and attempt to graft the matches of all expansions in the sequence onto the given expansion in-place.

Not all expansions in the sequence need to have been matched.

Parameters:
  • sequence_rule – SequenceRule
  • expansion – Expansion
has_next_expansion

Whether there is another sequence expansion after the current one.

Returns:bool
matches(speech)

Return whether or not speech matches the current expansion in the sequence.

This also sets current_match values for the original expansion used to create this rule.

This method will only match once and return False on calls afterward until refuse_matches is False.

Parameters:speech – str
Returns:bool
refuse_matches

Whether or not matches on this rule can succeed.

This is set to False if set_next is called and there is a next expansion or if restart_sequence is called.

This can also be manually set with the setter for problematic situations where, for example, the current expansion is a Repeat expansion with a Dictation descendant.

Returns:bool
restart_sequence()

Resets the current sequence expansion to the first one in the sequence and clears the match data of each sequence expansion.

set_next()

Moves to the next expansion in the sequence if there is one.

tags

The set of JSGF tags in this rule’s expansion. This does not include tags in referenced rules.

Returns:set
class jsgf.ext.rules.PublicSequenceRule(name, expansion, case_sensitive=False)

SequenceRule subclass with visible set to True.

jsgf.ext.rules.HiddenSequenceRule

alias of jsgf.ext.rules.PrivateSequenceRule