예제 #1
0
    def register_vocabulary(self, entity, entity_type):
        """ Register a word to an keyword

            Args:
                entity:         word to register
                entity_type:    Intent handler entity to tie the word to
        """
        self.emitter.emit(Message('register_vocab', {
            'start': entity, 'end': to_letters(self.skill_id) + entity_type
        }))
예제 #2
0
    def set_context(self, context, word=''):
        """
            Add context to intent service

            Args:
                context:    Keyword
                word:       word connected to keyword
        """
        if not isinstance(context, basestring):
            raise ValueError('context should be a string')
        if not isinstance(word, basestring):
            raise ValueError('word should be a string')
        context = to_letters(self.skill_id) + context
        self.emitter.emit(Message('add_context',
                                  {'context': context, 'word': word}))
예제 #3
0
def unmunge_message(message, skill_id):
    """Restore message keywords by removing the Letterified skill ID.

    Args:
        message (Message): Intent result message
        skill_id (int): skill identifier

    Returns:
        Message without clear keywords
    """
    if isinstance(message, Message) and isinstance(message.data, dict):
        for key in message.data:
            new_key = key.replace(to_letters(skill_id), '')
            message.data[new_key] = message.data.pop(key)

    return message
예제 #4
0
    def register_intent(self, intent_parser, handler, need_self=False):
        skill_id = to_letters(self.skill_id)
        if isinstance(intent_parser, Intent):
            intent_parser.optional += [(skill_id + "AudioBackend", None)]

        elif isinstance(intent_parser, IntentBuilder):
            intent_parser.optionally("AudioBackend")

        name = intent_parser.name or handler.__name__
        self.audio.register_backend_update(skill_id + name)

        def adapt_handler(message, dummy=None):
            message = self._clean_message(message)
            LOG.info(get_handler_name(handler))
            handler(message)

        super(AudioSkill, self).register_intent(intent_parser, adapt_handler)
예제 #5
0
    def hack_enable_intent(self, intent_name):
        # THIS IS HACKING AROUND A BUG IN 0.9.17's enable_intent()
        for (name, intent) in self.registered_intents:
            if name == intent_name:
                self.registered_intents.remove((name, intent))
                intent.name = name

                # Hackery - clean up the name of intent pieces
                munged = to_letters(self.skill_id)
                req = []
                for i in intent.requires:
                    if munged in i[0]:
                        req.append((i[0].replace(munged,
                                                 ""), i[1].replace(munged,
                                                                   "")))
                    else:
                        req.append(i)
                intent.requires = req

                self.register_intent(intent, None)
                break