def __init__(self): self.state = None self.clip = {} self.sticky = [] self.history = [] if not settings.WSR: self.history = RecognitionHistory(20) self.history.register() self.preserved = None self.comm = Communicator() self.intermediary = StatusIntermediary(self.comm) self.timer = TimerForWSR(0.025) if not settings.WSR: from dragonfly.timer import _Timer self.timer = _Timer(0.025) self.dep = DependencyMan() self.macros_grammar = Grammar("recorded_macros") self.noderules = []
class Nexus: def __init__(self): self.state = None self.clip = {} self.sticky = [] self.history = [] if not settings.WSR: self.history = RecognitionHistory(20) self.history.register() self.preserved = None self.comm = Communicator() self.intermediary = StatusIntermediary(self.comm) self.timer = TimerForWSR(0.025) if not settings.WSR: from dragonfly.timer import _Timer self.timer = _Timer(0.025) self.dep = DependencyMan() self.macros_grammar = Grammar("recorded_macros") self.noderules = [] def inform_state(self, state):# resolves circular import self.state = state def add_node_rule(self, n): self.noderules.append(n) def get_node_rule(self, name): for n in self.noderules: if n.master_node.text == name: return n def node_rule_active(self, name, value): self.get_node_rule(name).master_node.active = value settings.SETTINGS["nodes"][name] = value settings.save_config()
class Nexus: def __init__(self): self.state = None self.clip = {} self.sticky = [] self.history = [] if not settings.WSR: self.history = RecognitionHistory(20) self.history.register() self.preserved = None self.comm = Communicator() self.intermediary = StatusIntermediary(self.comm) self.timer = TimerForWSR(0.025) if not settings.WSR: from dragonfly.timer import _Timer self.timer = _Timer(0.025) self.dep = DependencyMan() self.macros_grammar = Grammar("recorded_macros") self.noderules = [] def inform_state(self, state): # resolves circular import self.state = state def add_node_rule(self, n): self.noderules.append(n) def get_node_rule(self, name): for n in self.noderules: if n.master_node.spec == name: return n def node_rule_active(self, name, value): self.get_node_rule(name).master_node.active = value settings.SETTINGS["nodes"][name] = value settings.save_config()
def __init__(self): self.state = None self.clip = {} self.sticky = [] self.history = RecognitionHistory(20) self.history.register() self.preserved = None self.comm = Communicator() self.intermediary = StatusIntermediary(self.comm) self.timer = _Timer(0.025) self.dep = DependencyMan() self.intermediary = None self.macros_grammar = Grammar("recorded_macros") self.noderules = []
def get_and_register_history(utterances=10): history = RecognitionHistory(utterances) history.register() return history
def test_recognition_observers(self): # RecognitionObservers are a bit quirky for the sapi5 engines, # so the tests for them are repeated here to handle that. from dragonfly import (Integer, Literal, RecognitionHistory, RecognitionObserver) from dragonfly.test import ElementTester, RecognitionFailure class RecognitionObserverTester(RecognitionObserver): """ RecognitionObserver class from the recobs doctests. """ def __init__(self): RecognitionObserver.__init__(self) self.waiting = False self.words = None def on_begin(self): self.waiting = True def on_recognition(self, words): self.waiting = False self.words = words def on_failure(self): self.waiting = False self.words = False test_recobs = RecognitionObserverTester() test_recobs.register() results = test_recobs.waiting, test_recobs.words assert results == (False, None) # Test simple literal element recognitions. test_lit = ElementTester(Literal("hello world")) assert test_lit.recognize("hello world") == "hello world" results = test_recobs.waiting, test_recobs.words assert results == (False, (u'hello', u'world')) assert test_lit.recognize("hello universe") is RecognitionFailure results = test_recobs.waiting, test_recobs.words assert results == (False, False) # Test Integer element recognitions test_int = ElementTester(Integer(min=1, max=100)) assert test_int.recognize("seven") == 7 results = test_recobs.waiting, test_recobs.words assert results == (False, (u'seven',)) assert test_int.recognize("forty seven") == 47 results = test_recobs.waiting, test_recobs.words assert results == (False, (u'forty', u'seven')) assert test_int.recognize("one hundred") is RecognitionFailure results = test_recobs.waiting, test_recobs.words assert results == (False, False) assert test_lit.recognize("hello world") == u'hello world' # Now test RecognitionHistory. history = RecognitionHistory() assert test_lit.recognize("hello world") == u'hello world' # Not yet registered, so didn't receive previous recognition. assert history == [] history.register() assert test_lit.recognize("hello world") == u'hello world' # Now registered, so should have received previous recognition. assert history == [(u'hello', u'world')] assert test_lit.recognize("hello universe") is RecognitionFailure # Failed recognitions are ignored, so history is unchanged. assert history == [(u'hello', u'world')] assert test_int.recognize("eighty six") == 86 assert history == [(u'hello', u'world'), (u'eighty', u'six')] # The RecognitionHistory class allows its maximum length to be set. history = RecognitionHistory(3) history.register() assert history == [] for i, word in enumerate(["one", "two", "three", "four", "five"]): assert test_int.recognize(word) == i + 1 assert history == [(u'three',), (u'four',), (u'five',)] history = RecognitionHistory(1) history.register() assert history == [] for i, word in enumerate(["one", "two", "three", "four", "five"]): assert test_int.recognize(word) == i + 1 assert history == [(u'five',)]