From 837b87a41d27b97e057dba4010e25ddb392c14fc Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Thu, 29 Jul 2021 12:35:07 +0200 Subject: [PATCH] Added spotify skill (not really working atm... issue with regexs) --- jarvis/main.py | 15 +++++++++------ jarvis/skills/daily/__init__.py | 0 jarvis/skills/entertainement/__init__.py | 0 .../skills/entertainement/spotify/__init__.py | 17 +++++++++++++++++ .../spotify/regex/fr-fr/play.song.only.title.rx | 1 + .../fr-fr/play.song.with.title.and.singer.rx | 1 + .../entertainement/spotify/vocab/fr-fr/From.voc | 3 +++ .../entertainement/spotify/vocab/fr-fr/Play.voc | 6 ++++++ .../spotify/vocab/fr-fr/Spotify.voc | 3 +++ jarvis/skills/intent_manager.py | 9 ++++++--- 10 files changed, 46 insertions(+), 9 deletions(-) delete mode 100644 jarvis/skills/daily/__init__.py delete mode 100644 jarvis/skills/entertainement/__init__.py create mode 100644 jarvis/skills/entertainement/spotify/__init__.py create mode 100644 jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.only.title.rx create mode 100644 jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.with.title.and.singer.rx create mode 100644 jarvis/skills/entertainement/spotify/vocab/fr-fr/From.voc create mode 100644 jarvis/skills/entertainement/spotify/vocab/fr-fr/Play.voc create mode 100644 jarvis/skills/entertainement/spotify/vocab/fr-fr/Spotify.voc diff --git a/jarvis/main.py b/jarvis/main.py index 0c8cac6..afd1789 100644 --- a/jarvis/main.py +++ b/jarvis/main.py @@ -3,8 +3,7 @@ from flask import Flask, request, jsonify, Response from jarvis.ia import process from jarvis.skills import intent_manager -from jarvis.skills.entertainement.jokes import JokesSkill -from jarvis.skills.research.wikipedia import WikipediaSkill +from jarvis.skills.entertainement.spotify import SpotifySkill from utils import config_utils, flask_utils, intents_utils, utils app = Flask(__name__) @@ -36,13 +35,17 @@ def process_request(): if __name__ == '__main__': # Tests - WikipediaSkill().register() - JokesSkill().register() + # WikipediaSkill().register() + # JokesSkill().register() + SpotifySkill().register() intent_manager.process_handlers() - intent_manager.recognise("cherche sur wikipedia Elon Musk") - intent_manager.recognise("raconte moi une blague") + # intent_manager.recognise("cherche sur wikipedia Elon Musk") + # intent_manager.recognise("raconte moi une blague") + intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify") + intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify") + intent_manager.recognise("joue crazy crazy nights") # start the flask server app.config['JSON_AS_ASCII'] = False diff --git a/jarvis/skills/daily/__init__.py b/jarvis/skills/daily/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/jarvis/skills/entertainement/__init__.py b/jarvis/skills/entertainement/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/jarvis/skills/entertainement/spotify/__init__.py b/jarvis/skills/entertainement/spotify/__init__.py new file mode 100644 index 0000000..4b311de --- /dev/null +++ b/jarvis/skills/entertainement/spotify/__init__.py @@ -0,0 +1,17 @@ +from adapt.intent import IntentBuilder + +from jarvis.skills import Skill, SkillRegistering +from jarvis.skills.decorators import intent_handler + + +class SpotifySkill(Skill, metaclass=SkillRegistering): + def __init__(self): + super().__init__("SpotifySkill") + + @intent_handler(IntentBuilder("PlaySongOnlyTitle").require("Play").optionally("Spotify").optionally("SongNameOnly")) + def handle_play_song_only_title(self, data): + print("") + + @intent_handler(IntentBuilder("PlaySongTitleAndSinger").require("Play").optionally("Spotify").require("From").optionally("SongName").optionally("Singer")) + def handle_play_song_title_and_singer(self, data): + print("") \ No newline at end of file diff --git a/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.only.title.rx b/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.only.title.rx new file mode 100644 index 0000000..bb12ca6 --- /dev/null +++ b/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.only.title.rx @@ -0,0 +1 @@ +.*(?:joue|mets|mets|fait moi écouter|moi|écouter) (?:le morceau|la chanson|voir|) ?(?P.+?(?= sur|$)()) \ No newline at end of file diff --git a/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.with.title.and.singer.rx b/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.with.title.and.singer.rx new file mode 100644 index 0000000..9230196 --- /dev/null +++ b/jarvis/skills/entertainement/spotify/regex/fr-fr/play.song.with.title.and.singer.rx @@ -0,0 +1 @@ +(?:joue|mets|mets|fait moi écouter|moi|écouter) (?:le morceau|la chanson|voir|) ?(?P.+) (?:de) (?P.+?(?= sur|$)) \ No newline at end of file diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/From.voc b/jarvis/skills/entertainement/spotify/vocab/fr-fr/From.voc new file mode 100644 index 0000000..0a9c8be --- /dev/null +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/From.voc @@ -0,0 +1,3 @@ +de +du groupe +d' \ No newline at end of file diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/Play.voc b/jarvis/skills/entertainement/spotify/vocab/fr-fr/Play.voc new file mode 100644 index 0000000..089ec9b --- /dev/null +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/Play.voc @@ -0,0 +1,6 @@ +joue +mets +mets +fait moi écouter +écouter +joue le morceau \ No newline at end of file diff --git a/jarvis/skills/entertainement/spotify/vocab/fr-fr/Spotify.voc b/jarvis/skills/entertainement/spotify/vocab/fr-fr/Spotify.voc new file mode 100644 index 0000000..03457d3 --- /dev/null +++ b/jarvis/skills/entertainement/spotify/vocab/fr-fr/Spotify.voc @@ -0,0 +1,3 @@ +Spotify +spotify +spot \ No newline at end of file diff --git a/jarvis/skills/intent_manager.py b/jarvis/skills/intent_manager.py index 3eff940..b434e9a 100644 --- a/jarvis/skills/intent_manager.py +++ b/jarvis/skills/intent_manager.py @@ -38,7 +38,10 @@ def handle(intent_name): def recognise(sentence): - for intents in engine.determine_intent(sentence): - json_response = json.loads(json.dumps(intents)) + sentence = sentence.lower() + print(sentence) - handle(json_response['intent_type']) + best_intents = engine.determine_intent(sentence, 100) + best_intent = next(best_intents) + + print(best_intent)