New method speak_dialog for skills
This commit is contained in:
parent
2a73291fa0
commit
512c423f45
@ -1,5 +1,6 @@
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from jarvis import get_path_file
|
from jarvis import get_path_file
|
||||||
@ -18,17 +19,34 @@ class Skill:
|
|||||||
self.category = path[2]
|
self.category = path[2]
|
||||||
self.skill_folder = path[3]
|
self.skill_folder = path[3]
|
||||||
|
|
||||||
|
self.path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
|
||||||
|
|
||||||
def speak(self, sentence):
|
def speak(self, sentence):
|
||||||
client_utils.speak(sentence, self.client_ip, self.client_port)
|
client_utils.speak(sentence, self.client_ip, self.client_port)
|
||||||
|
|
||||||
|
def speak_dialog(self, dialog, data):
|
||||||
|
file = self.path + "/dialog/" + languages_utils.get_language() + "/" + dialog + ".dialog"
|
||||||
|
if os.path.exists(file):
|
||||||
|
with open(file, "r") as infile:
|
||||||
|
random_line = random.choice(infile.readlines())
|
||||||
|
|
||||||
|
for key, val in data.items():
|
||||||
|
if "{{" + key + "}}" in random_line:
|
||||||
|
random_line = random_line.replace("{{" + key + "}}", val)
|
||||||
|
|
||||||
|
infile.close()
|
||||||
|
|
||||||
|
self.speak(random_line)
|
||||||
|
|
||||||
|
return "Error, dialog not found for : " + dialog
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
self.register_entities()
|
self.register_entities()
|
||||||
self.register_regex()
|
self.register_regex()
|
||||||
print("[" + self.name + "] Registered entity/entities and regex(s)")
|
print("[" + self.name + "] Registered entity/entities and regex(s)")
|
||||||
|
|
||||||
def register_entities(self):
|
def register_entities(self):
|
||||||
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
|
path = self.path + "/vocab/" + languages_utils.get_language() + "/*.voc"
|
||||||
path = path + "/vocab/" + languages_utils.get_language() + "/*.voc"
|
|
||||||
|
|
||||||
files = glob.glob(path, recursive=True)
|
files = glob.glob(path, recursive=True)
|
||||||
for file in files:
|
for file in files:
|
||||||
@ -39,8 +57,7 @@ class Skill:
|
|||||||
intent_manager.register_entity_adapt(line.replace('\n', ''), filename, self.name)
|
intent_manager.register_entity_adapt(line.replace('\n', ''), filename, self.name)
|
||||||
|
|
||||||
def register_regex(self):
|
def register_regex(self):
|
||||||
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
|
path = self.path + "/regex/" + languages_utils.get_language() + "/*.rx"
|
||||||
path = path + "/regex/" + languages_utils.get_language() + "/*.rx"
|
|
||||||
|
|
||||||
files = glob.glob(path, recursive=True)
|
files = glob.glob(path, recursive=True)
|
||||||
for file in files:
|
for file in files:
|
||||||
|
Reference in New Issue
Block a user