Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mycroft_bus_client import #53

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
# 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 os.path import join, isfile

from ovos_bus_client.util import get_message_lang
from ovos_workshop.decorators import fallback_handler
from ovos_workshop.skills.fallback import FallbackSkill
from neon_utils.message_utils import request_for_neon
Expand Down Expand Up @@ -71,13 +73,21 @@ def _read_voc_lines(self, name) -> filter:
:param name: vocab resource name
:returns: filter for specified vocab resource
"""
with open(self.find_resource(name + '.voc', 'vocab')) as f:
vocab = self.find_resource(f"{name}.voc", 'vocab',
lang=self.lang)
if self.lang not in vocab:
test_path = join(self.root_dir, "vocab", self.lang, f"{name}.voc")
if isfile(test_path):
LOG.warning(f"Resolved {vocab} but using {test_path}")
vocab = test_path
LOG.debug(f"Reading voc file {vocab} for lang={self.lang}")
with open(vocab) as f:
return filter(bool, map(str.strip, f.read().split('\n')))

@fallback_handler(priority=100)
def handle_fallback(self, message: Message):
LOG.info("Unknown Fallback Checking for Neon!!!")
utterance = message.data['utterance']
LOG.info(f"Unknown Fallback handling: {utterance}")
client = message.context.get('client')
ww_state = self.config_core.get("listener", {}).get("wake_word_enabled",
True)
Expand Down Expand Up @@ -110,12 +120,12 @@ def handle_fallback(self, message: Message):
}))

LOG.debug(f"Checking if neon must respond: {message.data}")

# Determine what kind of question this is to reply appropriately
for i in ['question', 'who.is', 'why.is']:
for line in self._read_voc_lines(i):
LOG.info(f"Checking for pattern: {line}.*")
if utterance.startswith(line):
LOG.info('Fallback type: ' + i)
LOG.info(f'Fallback type: {i} ({utterance})')
self.speak_dialog(i,
data={'remaining': line.replace(i, '')})
return True
Expand Down
24 changes: 15 additions & 9 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

from os.path import dirname
from mock import Mock
from mycroft_bus_client import Message
from neon_utils.skills import NeonFallbackSkill
from ovos_bus_client.message import Message

from neon_minerva.tests.skill_unit_test_base import SkillTestCase

Expand Down Expand Up @@ -67,22 +66,29 @@ def neon_must_respond(msg: Message):
self.skill.report_metric = Mock()

message_not_for_neon = Message("test",
{"utterance": "this is long enough"})
{"utterance": "this is long enough",
"lang": "en-us"})
message_too_short = Message("test", {"neon_in_request": True,
"utterance": "short"})
"utterance": "short",
"lang": "en-us"})
# message_neon_must_respond = Message("test",
# {"neon_must_respond": True,
# "utterance": "test search"})
message_question = Message("test", {"neon_in_request": True,
"utterance": "what is rain"})
"utterance": "what is rain",
"lang": "en-us"})
message_who_is = Message("test", {"neon_in_request": True,
"utterance": "who is rain"})
"utterance": "who is rain",
"lang": "en-us"})
message_why_is = Message("test", {"neon_in_request": True,
"utterance": "why is rain"})
"utterance": "why is rain",
"lang": "en-us"})
message_unknown = Message("test", {"neon_in_request": True,
"utterance": "is it raining"})
"utterance": "is it raining",
"lang": "en-us"})
message_transact_client = Message("test", {"neon_in_request": True,
"utterance": "short"},
"utterance": "short",
"lang": "en-us"},
{"client": "mq_api"})
self.assertTrue(self.skill.handle_fallback(message_not_for_neon))
self.skill.speak_dialog.assert_not_called()
Expand Down
Loading