MycroftSkill base class. More...
Public Member Functions | |
def | __init__ (self, name=None, bus=None, use_settings=True) |
def | acknowledge (self) |
def | add_event (self, name, handler, handler_info=None, once=False) |
def | ask_yesno (self, prompt, data=None) |
def | bind (self, bus) |
def | bus (self) |
def | cancel_all_repeating_events (self) |
def | cancel_scheduled_event (self, name) |
def | config (self) |
def | converse (self, utterances, lang=None) |
def | default_shutdown (self) |
def | detach (self) |
def | disable_intent (self, intent_name) |
def | enable_intent (self, intent_name) |
def | enclosure (self) |
def | find_resource (self, res_name, res_dirname=None) |
def | get_intro_message (self) |
def | get_response (self, dialog='', data=None, validator=None, on_fail=None, num_retries=-1) |
def | get_scheduled_event_status (self, name) |
def | handle_disable_intent (self, message) |
def | handle_enable_intent (self, message) |
def | handle_remove_cross_context (self, message) |
def | handle_set_cross_context (self, message) |
def | init_dialog (self, root_directory) |
def | initialize (self) |
def | lang (self) |
def | load_data_files (self, root_directory) |
def | load_regex_files (self, root_directory) |
def | load_vocab_files (self, root_directory) |
def | location (self) |
def | location_pretty (self) |
def | location_timezone (self) |
def | make_active (self) |
def | register_entity_file (self, entity_file) |
def | register_intent (self, intent_parser, handler) |
def | register_intent_file (self, intent_file, handler) |
def | register_regex (self, regex_str) |
def | register_resting_screen (self) |
def | register_vocabulary (self, entity, entity_type) |
def | remove_context (self, context) |
def | remove_cross_skill_context (self, context) |
def | remove_event (self, name) |
def | report_metric (self, name, data) |
def | schedule_event (self, handler, when, data=None, name=None) |
def | schedule_repeating_event (self, handler, when, frequency, data=None, name=None) |
def | send_email (self, title, body) |
def | set_context (self, context, word='', origin=None) |
def | set_cross_skill_context (self, context, word='') |
def | shutdown (self) |
def | speak (self, utterance, expect_response=False, wait=False) |
def | speak_dialog (self, key, data=None, expect_response=False, wait=False) |
def | stop (self) |
def | translate (self, text, data=None) |
def | translate_list (self, list_name, data=None) |
def | translate_namedvalues (self, name, delim=None) |
def | translate_template (self, template_name, data=None) |
def | update_scheduled_event (self, name, data=None) |
def | voc_match (self, utt, voc_filename, lang=None) |
Public Attributes | |
config_core | |
converse | |
dialog_renderer | |
events | |
file_system | |
gui | |
log | |
name | |
registered_intents | |
reload_skill | |
resting_name | |
root_dir | |
scheduled_repeats | |
settings | |
skill_id | |
voc_match_cache | |
Private Member Functions | |
def | __get_response (self) |
def | __handle_stop (self, event) |
def | __translate_file (self, name, data) |
def | _handle_collect_resting (self, message=None) |
def | _register_decorated (self) |
def | _schedule_event (self, handler, when, data=None, name=None, repeat=None) |
def | _unique_name (self, name) |
Private Attributes | |
_bus | |
_config | |
_dir | |
_enclosure | |
MycroftSkill base class.
Abstract base class which provides common behaviour and parameters to all Skills implementation.
def mycroft.skills.core.MycroftSkill.__init__ | ( | self, | |
name = None , |
|||
bus = None , |
|||
use_settings = True |
|||
) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
def mycroft.skills.core.MycroftSkill.acknowledge | ( | self | ) |
def mycroft.skills.core.MycroftSkill.add_event | ( | self, | |
name, | |||
handler, | |||
handler_info = None , |
|||
once = False |
|||
) |
Create event handler for executing intent Args: name (string): IntentParser name handler (func): Method to call handler_info (string): Base message when reporting skill event handler status on messagebus. once (bool, optional): Event handler will be removed after it has been run once.
def mycroft.skills.core.MycroftSkill.ask_yesno | ( | self, | |
prompt, | |||
data = None |
|||
) |
Read prompt and wait for a yes/no answer This automatically deals with translation and common variants, such as 'yeah', 'sure', etc. Args: prompt (str): a dialog id or string to read Returns: string: 'yes', 'no' or whatever the user response if not one of those, including None
def mycroft.skills.core.MycroftSkill.bind | ( | self, | |
bus | |||
) |
def mycroft.skills.core.MycroftSkill.cancel_all_repeating_events | ( | self | ) |
def mycroft.skills.core.MycroftSkill.cancel_scheduled_event | ( | self, | |
name | |||
) |
def mycroft.skills.core.MycroftSkill.config | ( | self | ) |
def mycroft.skills.core.MycroftSkill.converse | ( | self, | |
utterances, | |||
lang = None |
|||
) |
Handle conversation. This method gets a peek at utterances before the normal intent handling process after a skill has been invoked once. To use, override the converse() method and return True to indicate that the utterance has been handled. Args: utterances (list): The utterances from the user. If there are multiple utterances, consider them all to be transcription possibilities. Commonly, the first entry is the user utt and the second is normalized() version of the first utterance lang: language the utterance is in, None for default Returns: bool: True if an utterance was handled, otherwise False
def mycroft.skills.core.MycroftSkill.default_shutdown | ( | self | ) |
def mycroft.skills.core.MycroftSkill.disable_intent | ( | self, | |
intent_name | |||
) |
def mycroft.skills.core.MycroftSkill.enable_intent | ( | self, | |
intent_name | |||
) |
def mycroft.skills.core.MycroftSkill.find_resource | ( | self, | |
res_name, | |||
res_dirname = None |
|||
) |
Find a resource file Searches for the given filename using this scheme: 1) Search the resource lang directory: <skill>/<res_dirname>/<lang>/<res_name> 2) Search the resource directory: <skill>/<res_dirname>/<res_name> 3) Search the locale lang directory or other subdirectory: <skill>/locale/<lang>/<res_name> or <skill>/locale/<lang>/.../<res_name> Args: res_name (string): The resource name to be found res_dirname (string, optional): A skill resource directory, such 'dialog', 'vocab', 'regex' or 'ui'. Defaults to None. Returns: string: The full path to the resource file or None if not found
def mycroft.skills.core.MycroftSkill.get_intro_message | ( | self | ) |
def mycroft.skills.core.MycroftSkill.get_response | ( | self, | |
dialog = '' , |
|||
data = None , |
|||
validator = None , |
|||
on_fail = None , |
|||
num_retries = -1 |
|||
) |
Prompt user and wait for response The given dialog is spoken, followed immediately by listening for a user response. The response can optionally be validated before returning. Example: color = self.get_response('ask.favorite.color') Args: dialog (str): Announcement dialog to speak to the user data (dict): Data used to render the dialog validator (any): Function with following signature def validator(utterance): return utterance != "red" on_fail (any): Dialog or function returning literal string to speak on invalid input. For example: def on_fail(utterance): return "nobody likes the color red, pick another" num_retries (int): Times to ask user for input, -1 for infinite NOTE: User can not respond and timeout or say "cancel" to stop Returns: str: User's reply or None if timed out or canceled
def mycroft.skills.core.MycroftSkill.get_scheduled_event_status | ( | self, | |
name | |||
) |
def mycroft.skills.core.MycroftSkill.handle_disable_intent | ( | self, | |
message | |||
) |
def mycroft.skills.core.MycroftSkill.handle_enable_intent | ( | self, | |
message | |||
) |
def mycroft.skills.core.MycroftSkill.handle_remove_cross_context | ( | self, | |
message | |||
) |
def mycroft.skills.core.MycroftSkill.handle_set_cross_context | ( | self, | |
message | |||
) |
def mycroft.skills.core.MycroftSkill.init_dialog | ( | self, | |
root_directory | |||
) |
def mycroft.skills.core.MycroftSkill.initialize | ( | self | ) |
def mycroft.skills.core.MycroftSkill.load_data_files | ( | self, | |
root_directory | |||
) |
def mycroft.skills.core.MycroftSkill.load_regex_files | ( | self, | |
root_directory | |||
) |
def mycroft.skills.core.MycroftSkill.load_vocab_files | ( | self, | |
root_directory | |||
) |
def mycroft.skills.core.MycroftSkill.location | ( | self | ) |
def mycroft.skills.core.MycroftSkill.location_pretty | ( | self | ) |
def mycroft.skills.core.MycroftSkill.location_timezone | ( | self | ) |
def mycroft.skills.core.MycroftSkill.make_active | ( | self | ) |
def mycroft.skills.core.MycroftSkill.register_entity_file | ( | self, | |
entity_file | |||
) |
Register an Entity file with the intent service. An Entity file lists the exact values that an entity can hold. For example: === ask.day.intent === Is it {weekend}? === weekend.entity === Saturday Sunday Args: entity_file (string): name of file that contains examples of an entity. Must end with '.entity'
def mycroft.skills.core.MycroftSkill.register_intent | ( | self, | |
intent_parser, | |||
handler | |||
) |
def mycroft.skills.core.MycroftSkill.register_intent_file | ( | self, | |
intent_file, | |||
handler | |||
) |
Register an Intent file with the intent service. For example: === food.order.intent === Order some {food}. Order some {food} from {place}. I'm hungry. Grab some {food} from {place}. Optionally, you can also use <register_entity_file> to specify some examples of {food} and {place} In addition, instead of writing out multiple variations of the same sentence you can write: === food.order.intent === (Order | Grab) some {food} (from {place} | ). I'm hungry. Args: intent_file: name of file that contains example queries that should activate the intent. Must end with '.intent' handler: function to register with intent
def mycroft.skills.core.MycroftSkill.register_regex | ( | self, | |
regex_str | |||
) |
def mycroft.skills.core.MycroftSkill.register_resting_screen | ( | self | ) |
def mycroft.skills.core.MycroftSkill.register_vocabulary | ( | self, | |
entity, | |||
entity_type | |||
) |
def mycroft.skills.core.MycroftSkill.remove_context | ( | self, | |
context | |||
) |
def mycroft.skills.core.MycroftSkill.remove_cross_skill_context | ( | self, | |
context | |||
) |
def mycroft.skills.core.MycroftSkill.remove_event | ( | self, | |
name | |||
) |
def mycroft.skills.core.MycroftSkill.report_metric | ( | self, | |
name, | |||
data | |||
) |
def mycroft.skills.core.MycroftSkill.schedule_event | ( | self, | |
handler, | |||
when, | |||
data = None , |
|||
name = None |
|||
) |
Schedule a single-shot event. Args: handler: method to be called when (datetime/int/float): datetime (in system timezone) or number of seconds in the future when the handler should be called data (dict, optional): data to send when the handler is called name (str, optional): reference name NOTE: This will not warn or replace a previously scheduled event of the same name.
def mycroft.skills.core.MycroftSkill.schedule_repeating_event | ( | self, | |
handler, | |||
when, | |||
frequency, | |||
data = None , |
|||
name = None |
|||
) |
Schedule a repeating event. Args: handler: method to be called when (datetime): time (in system timezone) for first calling the handler, or None to initially trigger <frequency> seconds from now frequency (float/int): time in seconds between calls data (dict, optional): data to send when the handler is called name (str, optional): reference name, must be unique
def mycroft.skills.core.MycroftSkill.send_email | ( | self, | |
title, | |||
body | |||
) |
def mycroft.skills.core.MycroftSkill.set_context | ( | self, | |
context, | |||
word = '' , |
|||
origin = None |
|||
) |
def mycroft.skills.core.MycroftSkill.set_cross_skill_context | ( | self, | |
context, | |||
word = '' |
|||
) |
def mycroft.skills.core.MycroftSkill.shutdown | ( | self | ) |
def mycroft.skills.core.MycroftSkill.speak | ( | self, | |
utterance, | |||
expect_response = False , |
|||
wait = False |
|||
) |
def mycroft.skills.core.MycroftSkill.speak_dialog | ( | self, | |
key, | |||
data = None , |
|||
expect_response = False , |
|||
wait = False |
|||
) |
Speak a random sentence from a dialog file. Args: key (str): dialog file key (e.g. "hello" to speak from the file "locale/en-us/hello.dialog") data (dict): information used to populate sentence expect_response (bool): set to True if Mycroft should listen for a response immediately after speaking the utterance. wait (bool): set to True to block while the text is being spoken.
def mycroft.skills.core.MycroftSkill.translate | ( | self, | |
text, | |||
data = None |
|||
) |
Load a translatable single string resource The string is loaded from a file in the skill's dialog subdirectory 'dialog/<lang>/<text>.dialog' The string is randomly chosen from the file and rendered, replacing mustache placeholders with values found in the data dictionary. Args: text (str): The base filename (no extension needed) data (dict, optional): a JSON dictionary Returns: str: A randomly chosen string from the file
def mycroft.skills.core.MycroftSkill.translate_list | ( | self, | |
list_name, | |||
data = None |
|||
) |
Load a list of translatable string resources The strings are loaded from a list file in the skill's dialog subdirectory. 'dialog/<lang>/<list_name>.list' The strings are loaded and rendered, replacing mustache placeholders with values found in the data dictionary. Args: list_name (str): The base filename (no extension needed) data (dict, optional): a JSON dictionary Returns: list of str: The loaded list of strings with items in consistent positions regardless of the language.
def mycroft.skills.core.MycroftSkill.translate_namedvalues | ( | self, | |
name, | |||
delim = None |
|||
) |
Load translation dict containing names and values. This loads a simple CSV from the 'dialog' folders. The name is the first list item, the value is the second. Lines prefixed with # or // get ignored Args: name (str): name of the .value file, no extension needed delim (char): delimiter character used, default is ',' Returns: dict: name and value dictionary, or empty dict if load fails
def mycroft.skills.core.MycroftSkill.translate_template | ( | self, | |
template_name, | |||
data = None |
|||
) |
Load a translatable template The strings are loaded from a template file in the skill's dialog subdirectory. 'dialog/<lang>/<template_name>.template' The strings are loaded and rendered, replacing mustache placeholders with values found in the data dictionary. Args: template_name (str): The base filename (no extension needed) data (dict, optional): a JSON dictionary Returns: list of str: The loaded template file
def mycroft.skills.core.MycroftSkill.update_scheduled_event | ( | self, | |
name, | |||
data = None |
|||
) |
def mycroft.skills.core.MycroftSkill.voc_match | ( | self, | |
utt, | |||
voc_filename, | |||
lang = None |
|||
) |
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. Args: 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 Returns: bool: True if the utterance has the given vocabulary it