Whole new skill system (starting wikipedia skill) BUT DOESN'T WORK SEE TODO

This commit is contained in:
Mathieu B 2021-07-27 23:10:01 +02:00
parent 6f75239397
commit 36a17ff425
9 changed files with 113 additions and 2 deletions

View File

@ -1,7 +1,9 @@
import flask
from flask import Flask, request, jsonify, Response
import jarvis.ia.process
from jarvis.ia import process
from jarvis.skills import intent_manager
from jarvis.skills.research.wikipedia import WikipediaSkill
from utils import config_utils, flask_utils, intents_utils, utils
app = Flask(__name__)
@ -15,7 +17,7 @@ def process_request():
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
sentence = data['sentence']
tag_for_request = jarvis.ia.process.get_tag_for_sentence(sentence)
tag_for_request = process.get_tag_for_sentence(sentence)
print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request)
@ -32,6 +34,10 @@ def process_request():
if __name__ == '__main__':
# Tests
WikipediaSkill().register()
intent_manager.recognise("cherche sur wikipedia Elon Musk")
# start the flask server
app.config['JSON_AS_ASCII'] = False
app.run(port=config_utils.get_in_config("PORT"), debug=False, host='0.0.0.0', threaded=True)

View File

@ -0,0 +1,42 @@
import glob
import os
from jarvis import get_path_file
from jarvis.skills import intent_manager
from jarvis.utils import languages_utils
class Skill:
def __init__(self, name, category, skill_folder):
self.name = name
self.category = category
self.skill_folder = skill_folder
def register(self):
self.register_entities()
self.register_regex()
print("Registred entitie(s) and regex(s) for " + self.name)
def register_entities(self):
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
path = path + "/vocab/" + languages_utils.get_language() + "/*.voc"
files = glob.glob(path, recursive=True)
for file in files:
with open(file, "r") as infile:
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)
def register_regex(self):
path = os.path.dirname(get_path_file.__file__) + "/skills/" + self.category + "/" + self.skill_folder
path = path + "/regex/" + languages_utils.get_language() + "/*.rx"
files = glob.glob(path, recursive=True)
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)

View File

@ -0,0 +1,40 @@
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_regex(regex, domain):
engine.register_regex_entity(regex, domain)
# print("Registred regex : \"" + regex + "\" for domain : " + 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)
def recognise(sentence):
for intents in engine.determine_intent(sentence):
print(intents)

View File

@ -0,0 +1,13 @@
from adapt.intent import IntentBuilder
from jarvis.skills import Skill, intent_manager
class WikipediaSkill(Skill):
def __init__(self):
super().__init__("WikipediaSkill", "research", "wikipedia")
def register(self):
super().register()
intent_manager.engine.register_intent_parser(IntentBuilder("WikipediaQueryIntent").require("Wikipedia").build(), domain=self.name)

View File

@ -0,0 +1,3 @@
Un moment, je cherche pour {{query}}
Laissez moi regarder pour {{query}}
Je vais regarder sur Wikipédia pour {{query}}

View File

@ -0,0 +1 @@
.*(wiki|sur|au sujet de|wikipedia)(?! (sur|au sujet)) (?P<ArticleTitle>.+)

View File

@ -0,0 +1,6 @@
wiki
wikipédia
parle moi de
parle nous de
que dit wikipédia à propos de
cherche