def remove_context(self, s, cxt): """remove an adapt context.""" if isinstance(cxt, list): for x in cxt: MycroftSkill.remove_context(s, x) else: MycroftSkill.remove_context(s, cxt)
def __init__(self): MycroftSkill.__init__(self) self.jokes = [] self.joke = None self.stage = 0 self.path_to_joke_file = join(abspath(dirname(__file__)), 'jokes', 'jokes.txt')
def __init__(self): MycroftSkill.__init__(self) # this variable is needed if adding new shopping lists self.new_shopping_list_name = '' self.list_id = '' self.list_name = '' self.category = None self.current_time = datetime.datetime.now() self.time_heading_in_dict = 'refresh_date' self.grocery_state_file = "" self.category_state_file = "grocery_categories.txt"
def __init__(self): MycroftSkill.__init__(self) self.cups_ml_constant_number = 0.0042268 self.cups_litres_constant_number = 4.2268 self.pints_ml_constant_number = 0.0021134 self.pints_litres_constant_number = 2.1134 self.fl_oz_ml_constant_number = 0.033814 self.fl_oz_litres_constant_number = 33.814 self.grams_oz_constant_number = 0.035274 self.grams_lbs_constant_number = 0.0022046 self.convert_from_this_unit = '' self.convert_to_this_unit = '' self.number_of_new_units = ''
def __init__(self): MycroftSkill.__init__(self) self.default_location = self.room_name self.protocol = self.settings.get('protocol') self.mqttssl = self.settings.get('ssl') self.mqttca = self.settings.get('ca_certificate') self.mqtthost = self.settings.get('host') self.mqttport = self.settings.get('port') self.mqttauth = self.settings.get('auth') self.mqttuser = self.settings.get('username') self.mqttpass = self.settings.get('password') # global ws # ws = WebsocketClient() # ws.on('recognizer_loop:record_begin', self.handle_record_begin) # ws.on('recognizer_loop:record_end', self.handle_record_end) # ws.on('recognizer_loop:utterance', self.handle_utterance) # create_daemon(ws.run_forever) # wait_for_exit_signal() LOGGER.info('WakeWordSkill loaded ........')
def set_context(self, s, cxt): """Set an adapt context.""" for key, value in cxt.items(): MycroftSkill.set_context(s, key, value)
def __init__(self): MycroftSkill.__init__(self, name="IntentSkill") self.engine = IntentDeterminationEngine()
def __init__(self): MycroftSkill.__init__(self) self.strategy: RespeakerStrategy = None
def __init__(self): MycroftSkill.__init__(self, name="IntentSkill") self.engine = IntentDeterminationEngine() self.reload_skill = False
def __init__(self): MycroftSkill.__init__(self) self.all_confluence_search_results = '' self.delete_these_results = [] self.parse_these_results = {}
def __init__(self): MycroftSkill.__init__(self, "DesktopLauncherSkill") self.appmap = {}
def __init__(self, name=None, emitter=None): MycroftSkill.__init__(self, name, emitter) self.make_active()
def handle_register_skill(data): """ Create new MycroftSkill for ROS node and load into SkillManager Arguements: data: mycroft/register_skill service payload containing MycroftSkill srv """ global bus, skill_manager mycroft_skill = data.skill skill_path = mycroft_skill.path.rstrip('/') skill_id = basename(skill_path) skill = skill_manager.loaded_skills.setdefault(skill_path, {}) skill.update({"id": skill_id, "path": skill_path}) skill["loaded"] = True skill["is_ros_node"] = True instance = MycroftSkill(name=skill_id) instance.skill_id = skill_id instance.bind(bus) try: instance.load_data_files(skill_path) skill_topic = 'mycroft/' + skill_id register_intents(instance=instance, intents=mycroft_skill.intents, skill_topic=skill_topic, intent_files=mycroft_skill.intent_files, entities=mycroft_skill.entities) instance.initialize() except Exception as e: instance.default_shutdown() raise e skill["instance"] = instance modified = 0 if skill['instance'] is not None: bus.emit( Message( 'mycroft.skills.loaded', { 'path': skill_path, 'id': skill['id'], 'name': skill['instance'].name, 'modified': modified })) return MycroftSkillResponse(True) else: bus.emit( Message('mycroft.skills.loading_failure', { 'path': skill_path, 'id': skill['id'] })) return MycroftSkillResponse(False)
def __init__(self): MycroftSkill.__init__(self, name="WolframAlphaSkill") self.__init_client() self.question_parser = EnglishQuestionParser()
def __init__(self): MycroftSkill.__init__(self, "CerberusConfigSkill")
def __init__(self): MycroftSkill.__init__(self) self.settings.set_changed_callback(self._setup_api) self._setup_api()
def __init__(self): MycroftSkill.__init__(self) self.db = None self.feeds = [] self.config = []
def run(self, loader): """ Run a test for a skill. The skill, test_case_file and emitter is already set up in the __init__ method Args: loader: A list of loaded skills """ s = [s for s in loader.skills if s and s.root_dir == self.skill] if s: s = s[0] else: raise Exception('Skill couldn\'t be loaded') print('Test case file: ', self.test_case_file) test_case = json.load(open(self.test_case_file, 'r')) print("Test case: ", test_case) if 'responses' in test_case: def get_response(dialog='', data=None, announcement='', validator=None, on_fail=None, num_retries=-1): data = data or {} utt = announcement or s.dialog_renderer.render(dialog, data) s.speak(utt) response = test_case['responses'].pop(0) print(">" + utt) print("Responding with ", response) return response s.get_response = get_response # If we keep track of test status for the entire skill, then # get all intents from the skill, and mark current intent # tested if self.test_status: self.test_status.append_intent(s) if 'intent_type' in test_case: self.test_status.set_tested(test_case['intent_type']) evaluation_rule = EvaluationRule(test_case, s) # Set up queue for emitted events. Because # the evaluation method expects events to be received in convoy, # and be handled one by one. We cant make assumptions about threading # in the core or the skill q = Queue() s.emitter.q = q # Set up context before calling intent # This option makes it possible to better isolate (reduce dependance) # between test_cases cxt = test_case.get('remove_context', None) if cxt: if isinstance(cxt, list): for x in cxt: MycroftSkill.remove_context(s, x) else: MycroftSkill.remove_context(s, cxt) cxt = test_case.get('set_context', None) if cxt: for key, value in cxt.items(): MycroftSkill.set_context(s, key, value) # Emit an utterance, just like the STT engine does. This sends the # provided text to the skill engine for intent matching and it then # invokes the skill. self.emitter.emit( 'recognizer_loop:utterance', Message('recognizer_loop:utterance', {'utterances': [test_case.get('utterance', None)]})) # Wait up to X seconds for the test_case to complete timeout = time.time() + int(test_case.get('evaluation_timeout')) \ if test_case.get('evaluation_timeout', None) and \ isinstance(test_case['evaluation_timeout'], int) \ else time.time() + DEFAULT_EVALUAITON_TIMEOUT while not evaluation_rule.all_succeeded(): try: event = q.get(timeout=1) if ':' in event.type: event.data['__type__'] = event.type.split(':')[1] else: event.data['__type__'] = event.type evaluation_rule.evaluate(event.data) if event.type == 'mycroft.skill.handler.complete': break except Empty: pass if time.time() > timeout: break # Stop emmiter from sending on queue s.emitter.q = None # remove the skill which is not responding self.emitter.remove_all_listeners('speak') self.emitter.remove_all_listeners('mycroft.skill.handler.complete') # Report test result if failed if not evaluation_rule.all_succeeded(): print("Evaluation failed") print("Rule status: ", evaluation_rule.rule) return False return True
def __init__(self): MycroftSkill.__init__(self) self.ducking = False self.idle_count = 0 self.player = None
def execute_test(self, s): """ Execute test case. Arguments: s (MycroftSkill): mycroft skill to test Returns: (bool) True if the test succeeded completely. """ print("") print(color.HEADER + "="*20 + " RUNNING TEST " + "="*20 + color.RESET) print('Test file: ', self.test_case_file) with open(self.test_case_file, 'r') as f: test_case = json.load(f) print('Test:', json.dumps(test_case, indent=4, sort_keys=False)) if 'settings' in test_case: s.settings = TestSettings('/tmp/', self.test_case_file) for key in test_case['settings']: s.settings[key] = test_case['settings'][key] print(color.YELLOW, 'will run test with custom settings:', '\n{}'.format(s.settings), color.RESET) if 'responses' in test_case: def get_response(dialog='', data=None, announcement='', validator=None, on_fail=None, num_retries=-1): data = data or {} utt = announcement or s.dialog_renderer.render(dialog, data) print(color.MYCROFT + ">> " + utt + color.RESET) s.speak(utt) response = test_case['responses'].pop(0) print("SENDING RESPONSE:", color.USER_UTT + response + color.RESET) return response s.get_response = get_response # If we keep track of test status for the entire skill, then # get all intents from the skill, and mark current intent # tested if self.test_status: self.test_status.append_intent(s) if 'intent_type' in test_case: self.test_status.set_tested(test_case['intent_type']) evaluation_rule = EvaluationRule(test_case, s) # Set up queue for emitted events. Because # the evaluation method expects events to be received in convoy, # and be handled one by one. We cant make assumptions about threading # in the core or the skill q = Queue() s.bus.q = q # Set up context before calling intent # This option makes it possible to better isolate (reduce dependance) # between test_cases cxt = test_case.get('remove_context', None) if cxt: if isinstance(cxt, list): for x in cxt: MycroftSkill.remove_context(s, x) else: MycroftSkill.remove_context(s, cxt) cxt = test_case.get('set_context', None) if cxt: for key, value in cxt.items(): MycroftSkill.set_context(s, key, value) # Emit an utterance, just like the STT engine does. This sends the # provided text to the skill engine for intent matching and it then # invokes the skill. utt = test_case.get('utterance', None) play_utt = test_case.get('play_query', None) play_start = test_case.get('play_start', None) if utt: print("UTTERANCE:", color.USER_UTT + utt + color.RESET) self.emitter.emit( 'recognizer_loop:utterance', Message('recognizer_loop:utterance', {'utterances': [utt]})) elif play_utt: print('PLAY QUERY', color.USER_UTT + play_utt + color.RESET) self.emitter.emit('play:query', Message('play:query:', {'phrase': play_utt})) elif play_start: print('PLAY START') callback_data = play_start callback_data['skill_id'] = s.skill_id self.emitter.emit('play:start', Message('play:start', callback_data)) else: raise SkillTestError('No input utterance provided') # Wait up to X seconds for the test_case to complete timeout = time.time() + int(test_case.get('evaluation_timeout')) \ if test_case.get('evaluation_timeout', None) and \ isinstance(test_case['evaluation_timeout'], int) \ else time.time() + DEFAULT_EVALUAITON_TIMEOUT while not evaluation_rule.all_succeeded(): try: event = q.get(timeout=1) if ':' in event.type: event.data['__type__'] = event.type.split(':')[1] else: event.data['__type__'] = event.type evaluation_rule.evaluate(event.data) if event.type == 'mycroft.skill.handler.complete': break except Empty: pass if time.time() > timeout: break # Stop emmiter from sending on queue s.bus.q = None # remove the skill which is not responding self.emitter.remove_all_listeners('speak') self.emitter.remove_all_listeners('mycroft.skill.handler.complete') # Report test result if failed if not evaluation_rule.all_succeeded(): self.failure_msg = str(evaluation_rule.get_failure()) print(color.FAIL + "Evaluation failed" + color.RESET) print(color.FAIL + "Failure:", self.failure_msg + color.RESET) return False return True
def run(self, loader): """ Run a test for a skill. The skill, test_case_file and emitter is already set up in the __init__ method Args: loader: A list of loaded skills """ s = [s for s in loader.skills if s and s.root_dir == self.skill] if s: s = s[0] else: # The skill wasn't loaded, print the load log for the skill if self.skill in loader.load_log: print('\n {} Captured Logs from loading {}'.format( '=' * 15, '=' * 15)) print(loader.load_log.pop(self.skill)) raise SkillTestError('Skill couldn\'t be loaded') print("") print(color.HEADER + "=" * 20 + " RUNNING TEST " + "=" * 20 + color.RESET) print('Test file: ', self.test_case_file) with open(self.test_case_file, 'r') as f: test_case = json.load(f) print('Test:', json.dumps(test_case, indent=4, sort_keys=False)) original_settings = None if 'settings' in test_case: original_settings = s.settings s.settings = TestSettings('/tmp/', self.test_case_file) for key in test_case['settings']: s.settings[key] = test_case['settings'][key] print(color.YELLOW, 'will run test with custom settings:', '\n{}'.format(s.settings), color.RESET) if 'responses' in test_case: def get_response(dialog='', data=None, announcement='', validator=None, on_fail=None, num_retries=-1): data = data or {} utt = announcement or s.dialog_renderer.render(dialog, data) print(color.MYCROFT + ">> " + utt + color.RESET) s.speak(utt) response = test_case['responses'].pop(0) print("SENDING RESPONSE:", color.USER_UTT + response + color.RESET) return response s.get_response = get_response # If we keep track of test status for the entire skill, then # get all intents from the skill, and mark current intent # tested if self.test_status: self.test_status.append_intent(s) if 'intent_type' in test_case: self.test_status.set_tested(test_case['intent_type']) evaluation_rule = EvaluationRule(test_case, s) # Set up queue for emitted events. Because # the evaluation method expects events to be received in convoy, # and be handled one by one. We cant make assumptions about threading # in the core or the skill q = Queue() s.bus.q = q # Set up context before calling intent # This option makes it possible to better isolate (reduce dependance) # between test_cases cxt = test_case.get('remove_context', None) if cxt: if isinstance(cxt, list): for x in cxt: MycroftSkill.remove_context(s, x) else: MycroftSkill.remove_context(s, cxt) cxt = test_case.get('set_context', None) if cxt: for key, value in cxt.items(): MycroftSkill.set_context(s, key, value) # Emit an utterance, just like the STT engine does. This sends the # provided text to the skill engine for intent matching and it then # invokes the skill. utt = test_case.get('utterance', None) play_utt = test_case.get('play_query', None) play_start = test_case.get('play_start', None) if utt: print("UTTERANCE:", color.USER_UTT + utt + color.RESET) self.emitter.emit( 'recognizer_loop:utterance', Message('recognizer_loop:utterance', {'utterances': [utt]})) elif play_utt: print('PLAY QUERY', color.USER_UTT + play_utt + color.RESET) self.emitter.emit('play:query', Message('play:query:', {'phrase': play_utt})) elif play_start: print('PLAY START') callback_data = play_start callback_data['skill_id'] = s.skill_id self.emitter.emit('play:start', Message('play:start', callback_data)) else: raise SkillTestError('No input utterance provided') # Wait up to X seconds for the test_case to complete timeout = time.time() + int(test_case.get('evaluation_timeout')) \ if test_case.get('evaluation_timeout', None) and \ isinstance(test_case['evaluation_timeout'], int) \ else time.time() + DEFAULT_EVALUAITON_TIMEOUT while not evaluation_rule.all_succeeded(): try: event = q.get(timeout=1) if ':' in event.type: event.data['__type__'] = event.type.split(':')[1] else: event.data['__type__'] = event.type evaluation_rule.evaluate(event.data) if event.type == 'mycroft.skill.handler.complete': break except Empty: pass if time.time() > timeout: break # Stop emmiter from sending on queue s.bus.q = None # remove the skill which is not responding self.emitter.remove_all_listeners('speak') self.emitter.remove_all_listeners('mycroft.skill.handler.complete') # Report test result if failed if not evaluation_rule.all_succeeded(): self.failure_msg = str(evaluation_rule.get_failure()) print(color.FAIL + "Evaluation failed" + color.RESET) print(color.FAIL + "Failure:", self.failure_msg + color.RESET) return False if original_settings: s.settings = original_settings return True
def __init__(self): MycroftSkill.__init__(self)
def __init__(self): MycroftSkill.__init__(self, name="DuckDuckGoSkill") self.question_parser = EnglishQuestionParser()