This repository has been archived on 2023-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
jarvis-server/jarvis/skills/intent_manager.py

45 lines
1.3 KiB
Python
Raw Normal View History

import json
from adapt.engine import DomainIntentDeterminationEngine
engine = DomainIntentDeterminationEngine()
intents_handlers = dict()
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("[Adapt]: Added new regex for " + domain)
def register_intent(intent, domain):
engine.register_intent_parser(intent, domain=domain)
2021-07-28 21:44:48 +02:00
print("[Adapt]: Registered new intent " + intent.name + " for skill " + domain)
def process_handlers():
for handler in intents_handlers:
function_handler = intents_handlers.get(handler)
intent_builder = getattr(function_handler[0], "_register", [])[0]
skill_name = function_handler[1]
register_intent(intent_builder.build(), domain=skill_name)
def handle(intent_name):
if intent_name in intents_handlers:
method = intents_handlers.get(intent_name)[0]
method(None, [])
def recognise(sentence):
for intents in engine.determine_intent(sentence):
json_response = json.loads(json.dumps(intents))
handle(json_response['intent_type'])