Rule class reference

This section describes the following class:

Rule class

class Rule(name, element, context=None, imported=False, exported=False)

Rule class for implementing complete or partial voice-commands.

This rule class represents a voice-command or part of a voice- command. It contains a root element, which defines the language construct of this rule.

Constructor arguments:
  • name (str) – name of this rule
  • element (Element) – root element for this rule
  • context (Context, default: None) – context within which to be active. If None, the rule will always be active.
  • imported (boolean, default: False) – if true, this rule is imported from outside its grammar
  • exported (boolean, default: False) – if true, this rule is a complete top-level rule which can be spoken by the user. This should be True for voice-commands that the user can speak.

The self._log logger objects should be used in methods of derived classes for logging purposes. It is a standard logger object from the logger module in the Python standard library.

name
This rule’s name. (Read-only)
exported
Read-only access to a rule’s exported state.
imported
This rule’s imported status. (Read-only)
grammar
This rule’s grammar object. (Set once)
process_begin(executable, title, handle)

Start of phrase callback.

This method is called when the speech recognition engine detects that the user has begun to speak a phrase. It is called by the rule’s containing grammar if the grammar and this rule are active.

The default implementation of this method checks whether this rule’s context matches, and if it does this method calls dragonfly.grammar.rule.Rule._process_begin().

Arguments:
  • executable – the full path to the module whose window is currently in the foreground
  • title – window title of the foreground window
  • handle – window handle to the foreground window
_process_begin()

Start of phrase detection callback.

This is generally the method which developers should override in derived rule classes to give them custom functionality when the start of a phrase is detected.

This method is called when the speech recognition engine detects that the user has begun to speak a phrase. It is called by this rule’s dragonfly.grammar.rule.Rule.process_begin() after some context checks.

The default implementation of this method does nothing.

value(node)

Start of phrase callback.

This is generally the method which developers should override in derived rule classes to change the default semantic value of a recognized rule.

This method is called to obtain the semantic value associated with a particular recognition. It could be called from another rule’s dragonfly.grammar.rule.Rule.value() if that rule references this rule. If also be called from this rule’s dragonfly.grammar.rule.Rule.process_recognition() if that method has been overridden to do so in a derived class.

The default implementation of this method returns the value of this rule’s root element.

process_recognition(node)

Rule recognition callback.

This is generally the method which developers should override in derived rule classes to give them custom functionality when a top-level rule is recognized.

This method is called when the user has spoken words matching this rule’s contents. This method is called only once for each recognition, and only for the matching top-level rule.

The default implementation of this method does nothing.

Table Of Contents

This Page

Quick search