Example #1
0
 def voc_match(self, utt, voc_filename, lang=None, exact=False):
     # TODO: Handles bug to be addressed in: https://github.com/OpenVoiceOS/ovos_utils/issues/73
     try:
         return super().voc_match(utt, voc_filename, lang, exact)
     except FileNotFoundError:
         LOG.info(f"`{voc_filename}` not found, checking in neon_core")
         from mycroft.skills.skill_data import read_vocab_file
         from neon_utils.packaging_utils import get_core_root
         from itertools import chain
         import re
     lang = lang or self.lang
     voc = os.path.join(get_core_root(), "neon_core", "res", "text", lang, f"{voc_filename}.voc")
     if not os.path.exists(voc):
         raise FileNotFoundError(voc)
     vocab = read_vocab_file(voc)
     cache_key = lang + voc_filename
     self.voc_match_cache[cache_key] = list(chain(*vocab))
     if utt:
         if exact:
             # Check for exact match
             return any(i.strip() == utt
                        for i in self.voc_match_cache[cache_key])
         else:
             # Check for matches against complete words
             return any([re.match(r'.*\b' + i + r'\b.*', utt)
                         for i in self.voc_match_cache[cache_key]])
     else:
         return False
Example #2
0
    def initialize(self):
        self.register_fallback(self.handle_fallback,
                               int(self.settings["priority"]))
        self._converse_keepalive = create_daemon(self.converse_keepalive)

        say_voc = self.find_resource('and_say.voc', 'vocab')
        if say_voc:
            # load vocab and flatten into a simple list
            # TODO sort by length
            self.say_vocab = list(chain(*read_vocab_file(say_voc)))
        self.start_sip()
        if self.settings["sipxcom_sync"]:
            self.sipxcom_sync()

        # Register GUI Events
        self.handle_gui_state("Clear")
        self.gui.register_handler("voip.jarbas.acceptCall", self.accept_call)
        self.gui.register_handler("voip.jarbas.hangCall", self.hang_call)
        self.gui.register_handler("voip.jarbas.muteCall", self.mute_call)
        self.gui.register_handler("voip.jarbas.unmuteCall", self.unmute_call)
        self.gui.register_handler("voip.jarbas.callContact",
                                  self.handle_call_contact_from_gui)
        self.gui.register_handler("voip.jarbas.updateConfig",
                                  self.handle_config_from_gui)
        self.add_event('skill--voip.jarbasskills.home', self.show_homescreen)
Example #3
0
    def initialize(self):
        self.register_fallback(self.handle_fallback,
                               int(self.settings["priority"]))
        self._converse_keepalive = create_daemon(self.converse_keepalive)

        say_voc = self.find_resource('and_say.voc', 'vocab')
        if say_voc:
            # load vocab and flatten into a simple list
            self.say_vocab = list(chain(*read_vocab_file(say_voc)))
        self.start_sip()
Example #4
0
    def get_voc(self, voc_filename):
        # Check for both skill resources and mycroft-core resources
        voc = self.find_resource(voc_filename + '.voc', 'vocab')
        if not voc:  # Check for vocab in mycroft core resources
            voc = resolve_resource_file(
                join('text', self.lang, voc_filename + '.voc'))

        if not voc or not exists(voc):
            raise FileNotFoundError(
                'Could not find {}.voc file'.format(voc_filename))
        # load vocab and flatten into a simple list
        vocab = read_vocab_file(voc)
        return list(chain(*vocab))
Example #5
0
    def voc_match(self, utt, voc_filename, lang=None, exact=False):
        """Determine if the given utterance contains the vocabulary provided.
        Checks for vocabulary match in the utterance instead of the other
        way around to allow the user to say things like "yes, please" and
        still match against "Yes.voc" containing only "yes". The method first
        checks in the current skill's .voc files and secondly the "res/text"
        folder of mycroft-core. The result is cached to avoid hitting the
        disk each time the method is called.
        Arguments:
            utt (str): Utterance to be tested
            voc_filename (str): Name of vocabulary file (e.g. 'yes' for
                                'res/text/en-us/yes.voc')
            lang (str): Language code, defaults to self.long
            exact (bool): comparison using "==" instead of "in"
        Returns:
            bool: True if the utterance has the given vocabulary it
        """
        lang = lang or self.lang
        cache_key = lang + voc_filename
        if cache_key not in self.voc_match_cache:
            # Check for both skill resources and mycroft-core resources
            voc = self.find_resource(voc_filename + '.voc', 'vocab')
            if not voc:  # Check for vocab in mycroft core resources
                voc = resolve_resource_file(
                    join('text', lang, voc_filename + '.voc'))

            if not voc or not exists(voc):
                raise FileNotFoundError(
                    'Could not find {}.voc file'.format(voc_filename))
            # load vocab and flatten into a simple list
            vocab = read_vocab_file(voc)
            self.voc_match_cache[cache_key] = list(chain(*vocab))
        if utt:
            if exact:
                # Check for exact match
                return any(i.strip() == utt
                           for i in self.voc_match_cache[cache_key])
            else:
                # Check for matches against complete words
                return any([
                    re.match(r'.*\b' + i + r'\b.*', utt)
                    for i in self.voc_match_cache[cache_key]
                ])
        else:
            return False
Example #6
0
 def check_read_vocab_file(self, path, result_list=None):
     resultlist = result_list or []
     self.assertEqual(sorted(read_vocab_file(path)), sorted(result_list))