Reverting "Add intent fallback system (#899)"

This is because this will break wolfra alpha skill unless they update
skills, but if they update before getting the new version, it will also
break wolfram

This reverts commit 6ca4161335.
pull/920/head
Matthew D. Scholefield 2017-07-14 17:53:03 -05:00
parent 6ca4161335
commit 90aff68034
4 changed files with 14 additions and 55 deletions

View File

@ -90,8 +90,8 @@ def mute_and_speak(utterance):
lock.release()
def handle_complete_intent_failure(event):
logger.info("Failed to find intent.")
def handle_multi_utterance_intent_failure(event):
logger.info("Failed to find intent on multiple intents.")
# TODO: Localize
mute_and_speak("Sorry, I didn't catch that. Please rephrase your request.")
@ -205,7 +205,9 @@ def main():
loop.on('recognizer_loop:no_internet', handle_no_internet)
ws.on('open', handle_open)
ws.on('speak', handle_speak)
ws.on('complete_intent_failure', handle_complete_intent_failure)
ws.on(
'multi_utterance_intent_failure',
handle_multi_utterance_intent_failure)
ws.on('recognizer_loop:sleep', handle_sleep)
ws.on('recognizer_loop:wake_up', handle_wake_up)
ws.on('mycroft.mic.mute', handle_mic_mute)

View File

@ -14,11 +14,12 @@
#
# You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
import abc
import imp
import time
import operator
import os.path
import re
import time
@ -382,50 +383,3 @@ class MycroftSkill(object):
self.emitter.emit(
Message("detach_skill", {"skill_name": self.name + ":"}))
self.stop()
class FallbackSkill(MycroftSkill):
fallback_handlers = {}
def __init__(self, name, emitter=None):
MycroftSkill.__init__(self, name, emitter)
@classmethod
def make_intent_failure_handler(cls, ws):
"""Goes through all fallback handlers until one returns true"""
def handler(message):
for _, handler in sorted(cls.fallback_handlers.items(),
key=operator.itemgetter(0)):
try:
if handler(message):
return
except Exception as e:
logger.info('Exception in fallback: ' + str(e))
ws.emit(Message('complete_intent_failure'))
logger.warn('No fallback could handle intent.')
return handler
@classmethod
def register_fallback(cls, handler, priority):
"""
Register a function to be called as a general info fallback
Fallback should receive message and return
a boolean (True if succeeded or False if failed)
Lower priority gets run first
0 for high priority 100 for low priority
"""
while priority in cls.fallback_handlers:
priority += 1
cls.fallback_handlers[priority] = handler
@classmethod
def remove_fallback(cls, handler_to_del):
for priority, handler in cls.fallback_handlers.items():
if handler == handler_to_del:
del cls.fallback_handlers[priority]
return
logger.warn('Could not remove fallback!')

View File

@ -63,11 +63,16 @@ class IntentService(object):
reply = message.reply(
best_intent.get('intent_type'), best_intent)
self.emitter.emit(reply)
else:
elif len(utterances) == 1:
self.emitter.emit(Message("intent_failure", {
"utterance": utterances[0],
"lang": lang
}))
else:
self.emitter.emit(Message("multi_utterance_intent_failure", {
"utterances": utterances,
"lang": lang
}))
def handle_register_vocab(self, message):
start_concept = message.data.get('start')

View File

@ -30,7 +30,7 @@ from mycroft.lock import Lock # Creates PID file for single instance
from mycroft.messagebus.client.ws import WebsocketClient
from mycroft.messagebus.message import Message
from mycroft.skills.core import load_skill, create_skill_descriptor, \
MainModule, SKILLS_DIR, FallbackSkill
MainModule, SKILLS_DIR
from mycroft.skills.intent_service import IntentService
from mycroft.util import connected
from mycroft.util.log import getLogger
@ -117,8 +117,6 @@ def _load_skills():
check_connection()
ws.on('intent_failure', FallbackSkill.make_intent_failure_handler(ws))
# Create skill_manager listener and invoke the first time
ws.on('skill_manager', skills_manager)
ws.on('mycroft.internet.connected', install_default_skills)