Last active
July 31, 2019 07:37
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dragonfly import * | |
import nsformat | |
formatting_state = None # | |
def format_dictation(dictation, input_state): | |
formatted_output, output_state = nsformat.formatWords(str(dictation), state=input_state) | |
formatted_output = str(formatted_output) | |
Text(formatted_output).execute() | |
global formatting_state # I'm not sure if I'm managing the state properly here,I don't know how to properly do that in Python | |
formatting_state = output_state | |
class CommandRule(MappingRule): | |
mapping = { | |
"splat [<n>]":Key("c-backspace:%(n)s"), | |
} | |
extras = [IntegerRef("n", 1, 10)] | |
defaults = {"n":1} | |
command_rule = CommandRule() | |
class DictationRule(MappingRule): | |
mapping = { | |
# "<dictation>": Text("%(dictation)s "), # adding a trailing space | |
"<dictation>": Function(format_dictation, input_state=formatting_state) | |
} | |
extras = [ Dictation("dictation") ] | |
dictation_rule = DictationRule() | |
dict_cmd_sequence = Repetition(Alternative([RuleRef(dictation_rule), RuleRef(command_rule)]), | |
min=1, max=10, name="dict_cmd_sequence") | |
class SequenceRule(CompoundRule): | |
spec = "<dict_cmd_sequence>" | |
extras = [dict_cmd_sequence] | |
def _process_recognition(self, node, extras): | |
for action in extras["dict_cmd_sequence"]: | |
action.execute() | |
grammar = Grammar("zurow") | |
sequence_rule = SequenceRule() | |
grammar.add_rule(sequence_rule) | |
grammar.load() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment