Skip to content

Commit

Permalink
Merge pull request #18 from OpenVoiceOS/release-1.0.1a1
Browse files Browse the repository at this point in the history
Release 1.0.1a1
  • Loading branch information
JarbasAl authored Oct 16, 2024
2 parents f547997 + 43c8c1e commit 649f2a6
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 12 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [1.0.0a1](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/tree/1.0.0a1) (2024-10-16)
## [1.0.1a1](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/tree/1.0.1a1) (2024-10-16)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/compare/0.1.3...1.0.0a1)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/compare/1.0.0...1.0.1a1)

**Breaking changes:**
**Merged pull requests:**

- feat!:pipeline factory [\#15](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/pull/15) ([JarbasAl](https://github.com/JarbasAl))
- port tests from core [\#17](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/pull/17) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
16 changes: 10 additions & 6 deletions ovos_padatious/opm.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,22 @@ def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
self.containers = {lang: PadatiousIntentContainer(f"{intent_cache}/{lang}")
for lang in langs}

self.bus.on('padatious:register_intent', self.register_intent)
self.bus.on('padatious:register_entity', self.register_entity)
self.bus.on('detach_intent', self.handle_detach_intent)
self.bus.on('detach_skill', self.handle_detach_skill)
self.bus.on('mycroft.skills.initialized', self.train)

self.finished_training_event = Event()
self.finished_initial_train = False

self.registered_intents = []
self.registered_entities = []
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match

self.bus.on('padatious:register_intent', self.register_intent)
self.bus.on('padatious:register_entity', self.register_entity)
self.bus.on('detach_intent', self.handle_detach_intent)
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)

LOG.debug('Loaded Padatious intent parser.')

@property
Expand Down
4 changes: 2 additions & 2 deletions ovos_padatious/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 0
VERSION_ALPHA = 0
VERSION_BUILD = 1
VERSION_ALPHA = 1
# END_VERSION_BLOCK
109 changes: 109 additions & 0 deletions tests/test_intent_serv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2017 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from unittest import TestCase, mock

from ovos_bus_client.message import Message

from ovos_padatious.opm import PadatiousPipeline


def create_intent_msg(keyword, value):
"""Create a message for registering a padatious intent."""
return Message('padatious:register_intent',
{'name': f"skill:{keyword}", 'samples': [value]},
{"skill_id": "skill"})


def create_entity_msg(keyword, value):
"""Create a message for registering a padatious entity."""
return Message('padatious:register_entity',
{'name': f"skill:{keyword}", 'samples': [value]},
{"skill_id": "skill"})


def get_last_message(bus):
"""Get last sent message on mock bus."""
last = bus.emit.call_args
return last[0][0]


class TestIntentServiceApi(TestCase):
def setUp(self):
self.intent_service = PadatiousPipeline(mock.Mock())
self.setup_simple_padatious_intent()

def setup_simple_padatious_intent(self,
msg=create_intent_msg('testIntent', 'test'),
msg2=create_entity_msg('testEntity', 'enty')):
self.intent_service.register_intent(msg)
self.intent_service.register_entity(msg2)

def test_get_padatious_intent(self):
# Check that the intent is returned
msg = Message('intent.service.padatious.get',
data={'utterance': 'test'})
self.intent_service.handle_get_padatious(msg)

reply = get_last_message(self.intent_service.bus)

self.assertEqual(reply.data['intent']['name'],
'skill:testIntent')

def test_get_padatious_intent_no_match(self):
"""Check that if the intent doesn't match at all None is returned."""
# Check that no intent is matched
msg = Message('intent.service.padatious.get',
data={'utterance': 'five'})
self.intent_service.handle_get_padatious(msg)
reply = get_last_message(self.intent_service.bus)
self.assertLess(reply.data["intent"]['conf'], 0.4)

def test_get_padatious_intent_manifest(self):
"""Make sure the manifest returns a list of Intent Parser objects."""
msg = Message('intent.service.padatious.manifest.get')
self.intent_service.handle_padatious_manifest(msg)
reply = get_last_message(self.intent_service.bus)
self.assertEqual(reply.data['intents'][0], 'skill:testIntent')

def test_get_padatious_vocab_manifest(self):
msg = Message('intent.service.padatious.entities.manifest.get')
self.intent_service.handle_entity_manifest(msg)
reply = get_last_message(self.intent_service.bus)
value = reply.data["entities"][0]['name']
keyword = reply.data["entities"][0]['samples'][0]
self.assertEqual(value, 'skill:testEntity')
self.assertEqual(keyword, 'enty')

def test_get_no_match_after_detach(self):
"""Check that a removed intent doesn't match."""
# Check that no intent is matched
msg = Message('detach_intent',
data={'intent_name': 'skill:testIntent'})
self.intent_service.handle_detach_intent(msg)
msg = Message('intent.service.padatious.get', data={'utterance': 'test'})
self.intent_service.handle_get_padatious(msg)
reply = get_last_message(self.intent_service.bus)
self.assertEqual(reply.data['intent'], None)

def test_get_no_match_after_detach_skill(self):
"""Check that a removed skill's intent doesn't match."""
# Check that no intent is matched
msg = Message('detach_intent',
data={'skill_id': 'skill'})
self.intent_service.handle_detach_skill(msg)
msg = Message('intent.service.padatious.get', data={'utterance': 'test'})
self.intent_service.handle_get_padatious(msg)
reply = get_last_message(self.intent_service.bus)
self.assertEqual(reply.data['intent'], None)

0 comments on commit 649f2a6

Please sign in to comment.