15 from enum
import IntEnum
16 from abc
import ABC, abstractmethod
17 from mycroft
import MycroftSkill
28 CQSVisualMatchLevel = IntEnum(
'CQSVisualMatchLevel',
29 [e.name
for e
in CQSMatchLevel])
33 return isinstance(match_level, type(CQSVisualMatchLevel.EXACT))
36 VISUAL_DEVICES = [
'mycroft_mark_2']
40 return platform
in VISUAL_DEVICES
44 """ Question answering skills should be based on this class. The skill 45 author needs to implement `CQS_match_query_phrase` returning an answer 46 and can optionally implement `CQS_action` to perform additional actions 47 if the skill's answer is selected. 49 This class works in conjunction with skill-query which collects 50 answers from several skills presenting the best one available. 56 """ Overrides the default bind method of MycroftSkill. 58 This registers messagebus handlers for the skill during startup 59 but is nothing the skill author needs to consider. 67 search_phrase = message.data[
"phrase"]
71 self.bus.emit(message.response({
"phrase": search_phrase,
72 "skill_id": self.skill_id,
82 callback = result[3]
if len(result) > 3
else None 84 self.bus.emit(message.response({
"phrase": search_phrase,
85 "skill_id": self.skill_id,
87 "callback_data": callback,
91 self.bus.emit(message.response({
"phrase": search_phrase,
92 "skill_id": self.skill_id,
97 consumed_pct = len(match.split()) / len(phrase.split())
98 if consumed_pct > 1.0:
102 platform = self.config_core.get(
'enclosure', {}).
get(
'platform')
108 if int(level) == int(CQSMatchLevel.EXACT):
109 return 0.9 + (consumed_pct / 10) + bonus
110 elif int(level) == int(CQSMatchLevel.CATEGORY):
111 return 0.6 + (consumed_pct / 10) + bonus
112 elif int(level) == int(CQSMatchLevel.GENERAL):
113 return 0.5 + (consumed_pct / 10) + bonus
118 """ Message handler for question:action. Extracts phrase and data from 119 message forward this to the skills CQS_action method. """ 120 if message.data[
"skill_id"] != self.skill_id:
123 phrase = message.data[
"phrase"]
124 data = message.data.get(
"callback_data")
131 Analyze phrase to see if it is a play-able phrase with this 132 skill. Needs to be implemented by the skill. 135 phrase (str): User phrase uttered after "Play", e.g. "some music" 138 (match, CQSMatchLevel[, callback_data]) or None: Tuple containing 139 a string with the appropriate matching phrase, the PlayMatch 140 type, and optionally data to return in the callback if the 148 Take additional action IF the skill is selected. 149 The speech is handled by the common query but if the chosen skill 150 wants to display media, set a context or prepare for sending 151 information info over e-mail this can be implemented here. 154 phrase (str): User phrase uttered after "Play", e.g. "some music" 155 data (dict): Callback data specified in match_query_phrase() def is_CQSVisualMatchLevel(match_level)
def handles_visuals(self, platform)
def CQS_action(self, phrase, data)
def __init__(self, name=None, bus=None)
def CQS_match_query_phrase(self, phrase)
def __handle_question_query(self, message)
def __handle_query_action(self, message)
def __calc_confidence(self, match, phrase, level)
def get(phrase, lang=None, context=None)