Skip to content

Commit

Permalink
padatious handlers in padatious service
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 20, 2023
1 parent 7e5c016 commit 5693c33
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 34 deletions.
55 changes: 21 additions & 34 deletions ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,15 @@ def __init__(self, bus):
self.bus = bus
config = Configuration()

# Dictionary for translating a skill id to a name
self.skill_names = {}

self.pipeline_plugins = self.load_pipeline_plugins()
self.utterance_plugins = UtteranceTransformersService(bus, config=config)
self.metadata_plugins = MetadataTransformersService(bus, config=config)

self.bus.on('mycroft.skills.loaded', self.update_skill_name_dict) # deprecated

# Intents API
self.bus.on('intent.service.intent.get', self.handle_get_intent)
self.bus.on('intent.service.skills.get', self.handle_get_skills)

# Pipeline API
self.bus.on('recognizer_loop:utterance', self.handle_utterance)

# Session related handlers
Expand All @@ -70,20 +66,6 @@ def __init__(self, bus):
self.bus.on('intent.service.skills.activate', self.handle_activate_skill_request)
self.bus.on('active_skill_request', self.handle_activate_skill_request) # TODO backwards compat, deprecate

# TODO - move to own class
# adapt handlers
self.registered_vocab = []
self.bus.on('detach_intent', self.handle_detach_intent)
self.bus.on('detach_skill', self.handle_detach_skill)
self.bus.on('intent.service.adapt.get', self.handle_get_adapt)
self.bus.on('intent.service.adapt.manifest.get', self.handle_adapt_manifest)
self.bus.on('intent.service.adapt.vocab.manifest.get', self.handle_vocab_manifest)

# padatious handlers
self.bus.on('intent.service.padatious.get', self.handle_get_padatious)
self.bus.on('intent.service.padatious.manifest.get', self.handle_padatious_manifest)
self.bus.on('intent.service.padatious.entities.manifest.get', self.handle_entity_manifest)

@property
def pipeline(self):
# List of functions to use to match the utterance with intent, listed in priority order.
Expand Down Expand Up @@ -374,6 +356,8 @@ def handle_get_intent(self, message):
self.bus.emit(message.reply("intent.service.intent.reply",
{"intent": None}))

@deprecated("skill manifest moved to SkillManager, "
"this handler is not connected to bus events, subclassing it has no effect")
def handle_get_skills(self, message):
"""Send registered skills to caller.
Expand Down Expand Up @@ -472,6 +456,12 @@ def padatious_service(self):
"pipeline plugin object references can be found under self.pipeline_plugins", "0.1.0")
return self.pipeline_plugins.get("padatious") or self.padacioso_service

@property
def skill_names(self):
log_deprecation("self.skill_names has been deprecated and is always an empty dict,"
" skill names no longer in use, reference skill_id directly", "0.0.8")
return {}

@property
def registered_intents(self):
log_deprecation("self.registered_intents has been deprecated, moved to AdaptService,"
Expand All @@ -481,6 +471,15 @@ def registered_intents(self):
return adapt.registered_intents
return []

@property
def registered_vocab(self):
log_deprecation("self.registered_vocab has been deprecated, moved to AdaptService,"
"pipeline plugin object references can be found under self.pipeline_plugins", "0.1.0")
adapt = self.pipeline_plugins.get("adapt")
if adapt:
return adapt.registered_vocab
return []

@deprecated("skill names have been replaced across the whole ecosystem with skill_ids, "
"this handler is no longer connected to the messagebus", "0.0.8")
def update_skill_name_dict(self, message):
Expand Down Expand Up @@ -578,15 +577,7 @@ def handle_get_padatious(self, message):
Args:
message (Message): message triggering the method
"""
utterance = message.data["utterance"]
norm = message.data.get('norm_utt', utterance)
intent = self.padacioso_service.calc_intent(utterance)
if not intent and norm != utterance:
intent = self.padacioso_service.calc_intent(norm)
if intent:
intent = intent.__dict__
self.bus.emit(message.reply("intent.service.padatious.reply",
{"intent": intent}))
pass

@deprecated("handle_padatious_manifest moved to PadatiousService, overriding this method has no effect, "
"it has been disconnected from the bus event", "0.0.8")
Expand All @@ -596,9 +587,7 @@ def handle_padatious_manifest(self, message):
Args:
message (Message): message triggering the method
"""
self.bus.emit(message.reply(
"intent.service.padatious.manifest",
{"intents": self.padacioso_service.registered_intents}))
pass

@deprecated("handle_entity_manifest moved to PadatiousService, overriding this method has no effect, "
"it has been disconnected from the bus event", "0.0.8")
Expand All @@ -608,6 +597,4 @@ def handle_entity_manifest(self, message):
Args:
message (Message): message triggering the method
"""
self.bus.emit(message.reply(
"intent.service.padatious.entities.manifest",
{"entities": self.padacioso_service.registered_entities}))
pass
41 changes: 41 additions & 0 deletions ovos_core/intent_services/padatious_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def register_bus_events(self):
self.bus.on('detach_skill', self.handle_detach_skill)
self.bus.on('mycroft.skills.initialized', self.train)

self.bus.on('intent.service.padatious.get', self.handle_get_padatious)
self.bus.on('intent.service.padatious.manifest.get', self.handle_padatious_manifest)
self.bus.on('intent.service.padatious.entities.manifest.get', self.handle_entity_manifest)


def _match_level(self, utterances, limit, lang=None):
"""Match intent and make sure a certain level of confidence is reached.
Expand Down Expand Up @@ -160,6 +165,42 @@ def match_low(self, utterances, lang=None, message=None):
return self._match_level(utterances, self.conf_low, lang)

# implementation
def handle_get_padatious(self, message):
"""messagebus handler for perfoming padatious parsing.
Args:
message (Message): message triggering the method
"""
utterance = message.data["utterance"]
norm = message.data.get('norm_utt', utterance)
intent = self.calc_intent(utterance)
if not intent and norm != utterance:
intent = self.calc_intent(norm)
if intent:
intent = intent.__dict__
self.bus.emit(message.reply("intent.service.padatious.reply",
{"intent": intent}))

def handle_padatious_manifest(self, message):
"""Messagebus handler returning the registered padatious intents.
Args:
message (Message): message triggering the method
"""
self.bus.emit(message.reply(
"intent.service.padatious.manifest",
{"intents": self.registered_intents}))

def handle_entity_manifest(self, message):
"""Messagebus handler returning the registered padatious entities.
Args:
message (Message): message triggering the method
"""
self.bus.emit(message.reply(
"intent.service.padatious.entities.manifest",
{"entities": self.registered_entities}))

def train(self, message=None):
"""Perform padatious training.
Expand Down

0 comments on commit 5693c33

Please sign in to comment.