Fixed the skill system (I don't know how, luck probably)

This commit is contained in:
Mathieu B 2021-07-28 17:56:05 +02:00
parent 36a17ff425
commit 1e9f9cd0ba
3 changed files with 10 additions and 28 deletions

View File

@ -15,7 +15,7 @@ class Skill:
def register(self):
self.register_entities()
self.register_regex()
print("Registred entitie(s) and regex(s) for " + self.name)
print("[" + self.name + "] Registred entitie(s) and regex(s)")
def register_entities(self):
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
@ -27,8 +27,7 @@ class Skill:
for line in infile.readlines():
filename = file.split("/")[-1].split(".voc")[0]
intent_manager.engine.register_entity(line.replace('\n', ''), filename, self.name)
# intent_manager.register_entity(line.replace('\n', ''), filename, self.name)
intent_manager.register_entity(line.replace('\n', ''), filename, self.name)
def register_regex(self):
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
@ -38,5 +37,4 @@ class Skill:
for file in files:
with open(file, "r") as infile:
for line in infile.readlines():
intent_manager.engine.register_regex_entity(line.replace('\n', ''), self.name)
# intent_manager.register_regex(line.replace('\n', ''), self.name)
intent_manager.register_regex(line.replace('\n', ''), self.name)

View File

@ -1,38 +1,21 @@
from adapt.engine import DomainIntentDeterminationEngine
from adapt.intent import IntentBuilder
engine = DomainIntentDeterminationEngine()
def register_entity(value, type, domain):
engine.register_entity(entity_value=value, entity_type=type, domain=domain)
print("entity : " + value + " / " + type + " / " + domain)
# print("Registred entity : \"" + entity + "\" for domain : " + domain)
def register_entity(entity_value, entity_type, domain):
engine.register_entity(entity_value=entity_value, entity_type=entity_type, domain=domain)
print("[Adapt]: Added entity with type " + entity_type + " for " + domain)
def register_regex(regex, domain):
engine.register_regex_entity(regex, domain)
# print("Registred regex : \"" + regex + "\" for domain : " + domain)
print("[Adapt]: Added new regex for " + domain)
def register_intent(intent, domain):
if domain not in engine.domains:
engine.register_domain(domain)
# TODO: INVESTIGATE WHY IT WORKS WHEN DID MANUALLY BUT DOESN'T WHEN DID AUTOMATICALLY VIA THE INTENT
# register_entity('cherche', "Wikipedia", domain='WikipediaSkill')
# register_regex('.*(wiki|sur|au sujet de|wikipedia)(?! (sur|au sujet)) (?P<ArticleTitle>.+)',
# domain='WikipediaSkill')
# engine.register_entity('cherche', "Wikipedia", domain='WikipediaSkill')
# engine.register_regex_entity('.*(wiki|sur|au sujet de|wikipedia)(?! (sur|au sujet)) (?P<ArticleTitle>.+)',
# domain='WikipediaSkill')
# intent = IntentBuilder("WikipediaQueryIntent").require("Wikipedia").optionally('ArticleTitle').build()
engine.register_intent_parser(intent, domain='WikipediaSkill')
# print("Registred intent : " + domain)
print("[Adapt]: Registered new intent for skill " + domain)
def recognise(sentence):

View File

@ -10,4 +10,5 @@ class WikipediaSkill(Skill):
def register(self):
super().register()
intent_manager.engine.register_intent_parser(IntentBuilder("WikipediaQueryIntent").require("Wikipedia").build(), domain=self.name)
intent_manager.register_intent(IntentBuilder("WikipediaQueryIntent").require("Wikipedia").require("ArticleTitle").build(),
domain=self.name)