def build(self, call_info): name = call_info.name if call_info.arguments: raise SyntaxError("Invalid arguments for dictation extra: %r" % (call_info.arguments, )) print "just build", dragonfly.Dictation(name) return dragonfly.Dictation(name)
def load_grammar(): extras = [ df.Choice("direction_keys", game.direction_keys), letters.letters_and_keys, df.Dictation("dictation") ] grammar = menu_utils.build_menu_grammar(mapping, ANIMAL_QUERY_MENU, extras=extras) grammar.load()
class KeystrokeRule(fly.MappingRule): exported = False mapping = config.cmd.map extras = [ fly.IntegerRef('n', 1, 100), fly.Dictation('text'), ] defaults = { 'n': 1, }
def load_grammar(): extras = [ df.Choice("farm_types", farm_types), df.Choice("arrow_fields", arrow_fields), df.Choice("arrows", arrows), df_utils.positive_num, letters.letters_and_keys, df.Dictation("dictation"), ] grammar = menu_utils.build_menu_grammar(mapping, validate_new_game_menu, extras=extras) grammar.load()
def cleanupProtoRule(self, r, allPrototypes): # have to uniquify in this round about way because lists # aren't hashable and we need them for ListRef. if type(r["extras"]) == dict: r["extras"] = r["extras"].values() newExtras = [] for e in r["extras"]: if isinstance(e, protocol.Integer): newExtras.append(dfly.Integer(e.name, e.min, e.max)) elif isinstance(e, protocol.Dictation): newExtras.append(dfly.Dictation(e.name)) elif isinstance(e, protocol.Repetition): if e.rule_ref not in self.concreteRules: self.cleanupProtoRule(allPrototypes[e.rule_ref], allPrototypes) # Dragonfly wants RuleRef to take a RuleRef rather than an actual # Rule, so we just make one rather than forcing the server to # handle this, see protocol.py comments. concrete = self.concreteRules[e.rule_ref] log.info("concrete type: [%s]" % type(concrete)) newExtras.append( dfly.Repetition(dfly.RuleRef(rule=concrete), e.min, e.max, e.name)) elif isinstance(e, protocol.RuleRef): if e.rule_ref not in self.concreteRules: self.cleanupProtoRule(allPrototypes[e.rule_ref], allPrototypes) newExtras.append( dfly.RuleRef(self.concreteRules[e.rule_ref], e.name)) elif isinstance(e, protocol.ListRef): self.concreteWordLists[e.name] = List(e.name + "ConcreteList") # self.concreteWordLists[e.name].set(e.words) newExtras.append( dfly.ListRef(e.ref_name, self.concreteWordLists[e.name])) else: raise Exception("Unknown extra type: [%s]" % e) r["extras"] = newExtras self.concreteStartTime = time.time() self.buildConcreteRule(r) self.concreteEndTime = time.time() self.concreteTime += (self.concreteEndTime - self.concreteStartTime) r["built"] = True return True
class ExampleDictationRule(dragonfly.MappingRule): mapping = { "dictate <text>": dragonfly.Function(lambda text: print("I heard %r!" % str(text))), } extras = [dragonfly.Dictation("text")]
def dictation_rule(default=None): return df.Dictation('dictation', default=default)
class GreetUser(dragonfly.MappingRule): mapping = { 'greet user example <name>': dragonfly.Function(greeter), 'greet user anonymous example': dragonfly.Function(anonymous_greeter) } extras = [dragonfly.Dictation(name='name')]
class FormatRule(fly.MappingRule): mapping = format_functions extras = [fly.Dictation('dictation')]