16 """Module containing methods needed to load skill 17 data such as dialogs, intents and regular expressions. 21 from os.path
import splitext, join
31 This reads a .voc file, stripping out empty lines comments and expand 32 parentheses. It retruns each line as a list of all expanded 36 path (str): path to vocab file. 39 List of Lists of strings. 42 with open(path,
'r', encoding='utf8') as voc_file:
43 for line
in voc_file.readlines():
44 if line.startswith(
'#')
or line.strip() ==
'':
51 """Load Mycroft vocabulary from file 52 The vocab is sent to the intent handler using the message bus 55 path: path to vocabulary file (*.voc) 56 vocab_type: keyword name 57 bus: Mycroft messagebus connection 58 skill_id(str): skill id 60 if path.endswith(
'.voc'):
63 bus.emit(
Message(
"register_vocab", {
64 'start': entity,
'end': vocab_type
66 for alias
in parts[1:]:
67 bus.emit(
Message(
"register_vocab", {
68 'start': alias,
'end': vocab_type,
'alias_of': entity
73 """Load regex from file 74 The regex is sent to the intent handler using the message bus 77 path: path to vocabulary file (*.voc) 78 bus: Mycroft messagebus connection 80 if path.endswith(
'.rx'):
81 with open(path,
'r', encoding='utf8') as reg_file:
82 for line
in reg_file.readlines():
83 if line.startswith(
"#"):
92 """Load vocabulary from all files in the specified directory. 95 basedir (str): path of directory to load from (will recurse) 96 bus (messagebus emitter): messagebus instance used to send the vocab to 98 skill_id: skill the data belongs to 100 for path, _, files
in walk(basedir):
102 if f.endswith(
".voc"):
103 vocab_type =
to_alnum(skill_id) + splitext(f)[0]
108 """Load regex from all files in the specified directory. 111 basedir (str): path of directory to load from 112 bus (messagebus emitter): messagebus instance used to send the vocab to 114 skill_id (str): skill identifier 116 for path, _, files
in walk(basedir):
118 if f.endswith(
".rx"):
123 """Convert a skill id to only alphanumeric characters 125 Non alpha-numeric characters are converted to "_" 128 skill_id (str): identifier to be converted 130 (str) String of letters 132 return ''.join(c
if c.isalnum()
else '_' for c
in str(skill_id))
136 """Insert skill id as letters into match groups. 139 regex (str): regex string 140 skill_id (str): skill identifier 145 return base.join(regex.split(
'(?P<'))
149 """Rename intent keywords to make them skill exclusive 150 This gives the intent parser an exclusive name in the 151 format <skill_id>:<name>. The keywords are given unique 152 names in the format <Skill id as letters><Intent name>. 154 The function will not munge instances that's already been 158 intent_parser: (IntentParser) object to update 159 name: (str) Skill name 160 skill_id: (int) skill identifier 163 if str(skill_id) +
':' not in name:
164 intent_parser.name = str(skill_id) +
':' + name
166 intent_parser.name = name
172 for i
in intent_parser.requires:
173 if skill_id
not in i[0]:
174 kw = (skill_id + i[0], skill_id + i[0])
178 intent_parser.requires = reqs
182 for i
in intent_parser.optional:
183 if skill_id
not in i[0]:
184 kw = (skill_id + i[0], skill_id + i[0])
188 intent_parser.optional = opts
192 for i
in intent_parser.at_least_one:
193 element = [skill_id + e.replace(skill_id,
'')
for e
in i]
194 at_least_one.append(tuple(element))
195 intent_parser.at_least_one = at_least_one
def load_regex(basedir, bus, skill_id)
def read_vocab_file(path)
def load_vocabulary(basedir, bus, skill_id)
def munge_intent_parser(intent_parser, name, skill_id)
def load_regex_from_file(path, bus, skill_id)
def munge_regex(regex, skill_id)
def load_vocab_from_file(path, vocab_type, bus)