Trying to move spotify skill to padatious and looks promising (test.py)
This commit is contained in:
parent
892e1c8cfe
commit
fe76f2bad3
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,6 +10,9 @@ __pycache__/
|
|||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
||||||
|
intent_cache/*
|
||||||
|
**/intent_cache/**
|
||||||
|
|
||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
|
@ -44,7 +44,6 @@ if __name__ == '__main__':
|
|||||||
# intent_manager.recognise("cherche sur wikipedia Elon Musk")
|
# intent_manager.recognise("cherche sur wikipedia Elon Musk")
|
||||||
# intent_manager.recognise("raconte moi une blague")
|
# 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 le morceau crazy crazy nights de KISS sur spotify")
|
|
||||||
intent_manager.recognise("joue crazy crazy nights")
|
intent_manager.recognise("joue crazy crazy nights")
|
||||||
|
|
||||||
# start the flask server
|
# start the flask server
|
||||||
|
@ -42,17 +42,20 @@ class Skill:
|
|||||||
for line in infile.readlines():
|
for line in infile.readlines():
|
||||||
intent_manager.register_regex(line.replace('\n', ''), self.name)
|
intent_manager.register_regex(line.replace('\n', ''), self.name)
|
||||||
|
|
||||||
def speak(self, message):
|
|
||||||
print(message)
|
|
||||||
|
|
||||||
|
|
||||||
class SkillRegistering(type):
|
class SkillRegistering(type):
|
||||||
def __init__(cls, name, bases, attrs):
|
def __init__(cls, name, bases, attrs):
|
||||||
for key, val in attrs.items():
|
for key, val in attrs.items():
|
||||||
if type(val) is types.FunctionType and not str(val).__contains__("__"):
|
if type(val) is types.FunctionType and not str(val).__contains__("__"):
|
||||||
properties = getattr(val, "_register", None)
|
type = getattr(val, "_type", None)
|
||||||
|
|
||||||
if properties is not None:
|
if type is not None:
|
||||||
intent = properties[0]
|
properties = getattr(val, "_data", None)
|
||||||
intent_name = intent.name
|
|
||||||
intent_manager.intents_handlers[f"{intent_name}"] = [getattr(cls, key), name]
|
if properties is not None:
|
||||||
|
if type is 'adapt':
|
||||||
|
intent = properties[0]
|
||||||
|
intent_name = intent.name
|
||||||
|
intent_manager.intents_handlers_adapt[f"{intent_name}"] = [getattr(cls, key), name]
|
||||||
|
elif type is 'padatious':
|
||||||
|
intent_file = properties[0]
|
||||||
|
@ -5,7 +5,22 @@ def intent_handler(*args):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
f._register = args
|
f._type = "adapt"
|
||||||
|
f._data = args
|
||||||
|
return f
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
def intent_file_handler(*args):
|
||||||
|
"""
|
||||||
|
Creates an attribute on the method, so it can
|
||||||
|
be discovered by the metaclass
|
||||||
|
"""
|
||||||
|
|
||||||
|
def decorator(f):
|
||||||
|
f._type = "padatious"
|
||||||
|
f._data = args
|
||||||
return f
|
return f
|
||||||
|
|
||||||
return decorator
|
return decorator
|
@ -1,17 +1,11 @@
|
|||||||
from adapt.intent import IntentBuilder
|
|
||||||
|
|
||||||
from jarvis.skills import Skill, SkillRegistering
|
from jarvis.skills import Skill, SkillRegistering
|
||||||
from jarvis.skills.decorators import intent_handler
|
from jarvis.skills.decorators import intent_file_handler
|
||||||
|
|
||||||
|
|
||||||
class SpotifySkill(Skill, metaclass=SkillRegistering):
|
class SpotifySkill(Skill, metaclass=SkillRegistering):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("SpotifySkill")
|
super().__init__("SpotifySkill")
|
||||||
|
|
||||||
@intent_handler(IntentBuilder("PlaySongOnlyTitle").require("Play").optionally("Spotify").optionally("SongNameOnly"))
|
@intent_file_handler("play_a_song.intent")
|
||||||
def handle_play_song_only_title(self, data):
|
def handle_play_a_song(self, data):
|
||||||
print("")
|
print("Play song")
|
||||||
|
|
||||||
@intent_handler(IntentBuilder("PlaySongTitleAndSinger").require("Play").optionally("Spotify").require("From").optionally("SongName").optionally("Singer"))
|
|
||||||
def handle_play_song_title_and_singer(self, data):
|
|
||||||
print("")
|
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
Joue {song} sur spotify
|
||||||
|
Joue {song}
|
||||||
|
Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Mets la chanson {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Mets la chanson {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
||||||
|
Mets le titre {song}
|
||||||
|
Mets le titre {song} sur spotify
|
||||||
|
Mets le morceau {song}
|
||||||
|
Mets le morceau {song} sur spotify
|
||||||
|
Joue le morceau {song}
|
||||||
|
Joue le morceau {song} sur spotify
|
||||||
|
Mets le titre {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Mets le titre {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
||||||
|
Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
||||||
|
Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Joue le morceau {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Joue le morceau {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
||||||
|
Mets voir {song}
|
||||||
|
Mets voir {song} sur spotify
|
||||||
|
Mets voir {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Mets voir {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
||||||
|
Fait moi écouter {song}
|
||||||
|
Fait moi écouter {song} sur spotify
|
||||||
|
Fait moi écouter {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}
|
||||||
|
Fait moi écouter {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify
|
@ -1,10 +1,9 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
from adapt.engine import DomainIntentDeterminationEngine
|
from adapt.engine import DomainIntentDeterminationEngine
|
||||||
|
|
||||||
engine = DomainIntentDeterminationEngine()
|
engine = DomainIntentDeterminationEngine()
|
||||||
|
|
||||||
intents_handlers = dict()
|
intents_handlers_adapt = dict()
|
||||||
|
intents_handlers_padatious = dict()
|
||||||
|
|
||||||
|
|
||||||
def register_entity(entity_value, entity_type, domain):
|
def register_entity(entity_value, entity_type, domain):
|
||||||
@ -23,17 +22,20 @@ def register_intent(intent, domain):
|
|||||||
|
|
||||||
|
|
||||||
def process_handlers():
|
def process_handlers():
|
||||||
for handler in intents_handlers:
|
for handler in intents_handlers_adapt:
|
||||||
function_handler = intents_handlers.get(handler)
|
function_handler = intents_handlers_adapt.get(handler)
|
||||||
intent_builder = getattr(function_handler[0], "_register", [])[0]
|
intent_builder = getattr(function_handler[0], "_register", [])[0]
|
||||||
skill_name = function_handler[1]
|
skill_name = function_handler[1]
|
||||||
|
|
||||||
register_intent(intent_builder.build(), domain=skill_name)
|
register_intent(intent_builder.build(), domain=skill_name)
|
||||||
|
|
||||||
|
for handler in intents_handlers_padatious:
|
||||||
|
# TODO : register file intents
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
def handle(intent_name):
|
def handle(intent_name):
|
||||||
if intent_name in intents_handlers:
|
if intent_name in intents_handlers_adapt:
|
||||||
method = intents_handlers.get(intent_name)[0]
|
method = intents_handlers_adapt.get(intent_name)[0]
|
||||||
method(None, [])
|
method(None, [])
|
||||||
|
|
||||||
|
|
||||||
|
57
jarvis/utils/test.py
Normal file
57
jarvis/utils/test.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
from padatious import IntentContainer
|
||||||
|
|
||||||
|
container = IntentContainer('intent_cache')
|
||||||
|
|
||||||
|
container.add_intent('spotify',
|
||||||
|
["Joue {song} sur spotify",
|
||||||
|
"Joue {song}",
|
||||||
|
"Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}",
|
||||||
|
"Mets la chanson {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}",
|
||||||
|
"Mets la chanson {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify",
|
||||||
|
"Mets le titre {song}",
|
||||||
|
"Mets le titre {song} sur spotify",
|
||||||
|
"Mets le morceau {song}",
|
||||||
|
"Mets le morceau {song} sur spotify",
|
||||||
|
"Joue le morceau {song}",
|
||||||
|
"Joue le morceau {song} sur spotify",
|
||||||
|
"Mets le titre {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}",
|
||||||
|
"Mets le titre {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify",
|
||||||
|
"Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify",
|
||||||
|
"Joue {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}",
|
||||||
|
"Joue le morceau {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}"
|
||||||
|
"Joue le morceau {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify"
|
||||||
|
"Mets voir {song}",
|
||||||
|
"Mets voir {song} sur spotify",
|
||||||
|
"Mets voir {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}",
|
||||||
|
"Mets voir {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify",
|
||||||
|
"Fait moi écouter {song}"
|
||||||
|
"Fait moi écouter {song} sur spotify"
|
||||||
|
"Fait moi écouter {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer}"
|
||||||
|
"Fait moi écouter {song} (de|des|du groupe|du chanteur|de la chanteuse) {singer} sur spotify"
|
||||||
|
])
|
||||||
|
|
||||||
|
container.train()
|
||||||
|
|
||||||
|
tests = ["joue time after time sur spotify",
|
||||||
|
"mets le morceau fortunate son sur spotify",
|
||||||
|
"joue le morceau crazy crazy nights",
|
||||||
|
"mets voir crazy crazy nights",
|
||||||
|
"mets la chanson crazy crazy nights de KISS",
|
||||||
|
"fait moi écouter bye bye miss american pie",
|
||||||
|
"joue le morceau bye bye miss american pie",
|
||||||
|
"joue le morceau bye bye miss american pie du groupe billy cassidy",
|
||||||
|
"joue hooked on a feeling sur spotify",
|
||||||
|
"joue le morceau fortunate son de Willy and the Boys sur spotify"]
|
||||||
|
|
||||||
|
for test in tests:
|
||||||
|
print("Sentence : " + test)
|
||||||
|
|
||||||
|
result = container.calc_intent(test)
|
||||||
|
if 'song' in result.matches:
|
||||||
|
print("Song : " + result.matches.get('song'))
|
||||||
|
|
||||||
|
if 'singer' in result.matches:
|
||||||
|
print("Singer/Group : " + result.matches.get('singer'))
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("")
|
Reference in New Issue
Block a user