Grammars¶
-
class
GlobalRegistry
(name, description=None, context=None, engine=None, **kwargs)[source]¶ Bases:
dragontide._grammars.RegistryGrammar
The GlobalRegistry is a
RegistryGrammar
with a single globally sharedRegistry
. It can be used as the Grammar object across many files, allowing the rules to know about each other for chaining.
-
class
RegistryGrammar
(name, registry=None, **kwargs)[source]¶ Bases:
dragonfly.grammar.grammar_base.Grammar
A RegistryGrammar is like a normal Grammar object, except it registers and unregisters
RegisteredRule
’s as they are activated and deactivated, maintaining a registry of those that are currently active.ContinuingRule
’s that are added to this grammar will automatically use this object’s registry when seeking out commands embedded in utterances.-
__init__
(name, registry=None, **kwargs)[source]¶ - Parameters
name – Passed to dragonfly Grammar
registry (Registry) – The Registry object that serves as the active Registration list. It may be shared across RegistryGrammar instances. If None, a local Registry object is created.
**kwargs – Passed safely to dragonfly Grammar
-
activate_rule
(rule)[source]¶ Activate a rule loaded in this grammar.
Internal: this method is normally not called directly by the user, but instead automatically when the rule itself is activated by the user.
-
-
class
Registry
(literal_tags=['English', 'english', 'literal'], override_tags=False)[source]¶ A registry maintains information about a set of known active rules and the literal tags that must precede their intros when their commands are meant as free speech dictation.
Working directly with a Registry object is an advanced use case.
A registry exposes services regarding inspection and parsing of utterances as it relates to its literal tags and currently actively registered commands.
-
__init__
(literal_tags=['English', 'english', 'literal'], override_tags=False)[source]¶ - Parameters
literal_tags (string list) – These words will function as literalization markers to indicate that what follows is not a command, but rather free speech dictation.
override_tags (bool) – If False, the literal_tags supplied to __init__ will be added to the defaults, otherwise they will replace them.
Literal tags are used during speech to indicate that what follows is not a command. Registry object’s initialize with these default values.
-
translate_literals
(words_iterable)[source]¶ Returns a list of words, stripped of literal tags in a semantically meaningful way. Final isolated literal_tag’s are stripped.
When a literal_tag precedes a literal_tag, the second occurrence only is retained.
In a string of all literal_tag’s, exactly the odd indexed ones (in a 0-indexed sense) would be returned.
-
register_rule
(rule)[source]¶ Adds the rule to a list of known active rules. Not generally called directly by users. For more information see the registration concept section.
-
unregister_rule
(rule)[source]¶ Removes the rule from the list of known active rules. Not generally called directly by users.
-
is_registered
(intro)[source]¶ - Parameters
command_intro (string) – A command intro to test for registration.
- Returns
True if registered, False otherwise
- Return type
bool
-