Skip to content

Commit

Permalink
fix: laws of robotics (#43)
Browse files Browse the repository at this point in the history
* fix: laws of robotics

Only one law at a time when requesting a specific law
  • Loading branch information
mikejgray authored Jul 5, 2024
1 parent f0a658b commit d39f858
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 43 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/skill_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ jobs:
neon_versions: "[3.8, 3.9, '3.10', '3.11']"
ovos_versions: "[3.8, 3.9, '3.10', '3.11']"
skill_intent_tests:
uses: neongeckocom/.github/.github/workflows/skill_test_intents.yml@master
uses: neongeckocom/.github/.github/workflows/skill_test_intents.yml@master
with:
test_padacioso: false
test_padatious: true
neon_versions: "[3.8, 3.9, '3.10', '3.11']"
ovos_versions: "[3.8, 3.9, '3.10', '3.11']"
skill_resource_tests:
uses: neongeckocom/.github/.github/workflows/skill_test_resources.yml@master
# skill_install_tests: # May be bugged from alpha
Expand Down
41 changes: 20 additions & 21 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from os.path import dirname, join

from dateutil.tz import gettz
from lingua_franca.parse import extract_number
from lingua_franca.time import default_timezone
from ovos_bus_client.apis.ocp import OCPInterface
from ovos_bus_client.message import Message
from ovos_mark1.faceplate.animations import FallingDots
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.decorators import intent_handler, skill_api_method
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill
from skill_easter_eggs.constants import ANNUAL, ASCII_SNOW, SPICY_SOUNDS
from skill_easter_eggs.stardate import StarDate
Expand Down Expand Up @@ -112,25 +113,31 @@ def _create_spoken_stardate(self):
def handle_pod_intent(self, _):
self.speak_dialog("pod")

@intent_handler(
IntentBuilder("robotics_laws_intent")
.require("robotics_keyword")
.require("law_keyword")
.optionally("LawOfRobotics")
.build()
)
def handle_robotic_laws_intent(self, message):
law = str(message.data.get("LawOfRobotics", "all"))
@intent_handler("law_of_robotics.intent")
def handle_robotic_laws_intent(self, message: Message):
law = str(message.data.get("ordinal", ""))
law = extract_number(law, ordinals=True)
self.log.debug("law: %s", law)
if not law:
self.log.debug("No specific law detected, reciting all three")
self.speak_dialog("rule1")
self.speak_dialog("rule2")
self.speak_dialog("rule3")
return
# lingua-franca currently returns a number, but let's not trust, let's ensure
law = str(law)
if law == "1":
self.log.debug("First law of robotics requested")
self.speak_dialog("rule1")
elif law == "2":
self.log.debug("Second law of robotics requested")
self.speak_dialog("rule2")
elif law == "3":
self.log.debug("Third law of robotics requested")
self.speak_dialog("rule3")
else:
self.speak_dialog("rule1")
self.speak_dialog("rule2")
self.speak_dialog("rule3")
self.log.debug("Invalid law requested")
self.speak_dialog("invalid_law")

@intent_handler(
IntentBuilder("rock_paper_scissors_lizard_spock_intent")
Expand Down Expand Up @@ -313,11 +320,3 @@ def _play_in_ocp(self, media, title="Easter Egg!"):
f"https://github.com/OpenVoiceOS/ovos-skill-easter-eggs/raw/dev/sounds/{'/'.join(media.split('/')[-2:])}"
)
self.ocp.play(tracks=[data])


if __name__ == "__main__":
from ovos_utils.fakebus import FakeBus

skill = EasterEggsSkill(bus=FakeBus(), skill_id="skill_easter_eggs.test")
skill.handle_portal_intent(None)
print("BREAK")
1 change: 1 addition & 0 deletions locale/en-us/dialog/invalid_law.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I only know three laws of robotics, sorry.
1 change: 0 additions & 1 deletion locale/en-us/regex/Law.rx

This file was deleted.

2 changes: 0 additions & 2 deletions locale/en-us/vocab/law_keyword.voc

This file was deleted.

8 changes: 8 additions & 0 deletions locale/en-us/vocab/law_of_robotics.intent
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
what are the laws of robotics
tell me the laws of (robotic|robotics)
recite the laws of (robotic|robotics)
speak the laws of (robotic|robotics)
what is (the |){ordinal} law of (robotic|robotics)
tell me (the |){ordinal} law of (robotic|robotics)
recite (the |){ordinal} law of (robotic|robotics)
speak (the |){ordinal} law of (robotic|robotics)
2 changes: 0 additions & 2 deletions locale/en-us/vocab/robotics_keyword.voc

This file was deleted.

3 changes: 2 additions & 1 deletion requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
neon-minerva>=0.1.1a5
neon-minerva>=0.2.0
ovos_plugin_manager
pytest
pytest-cov
ovos_config
1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ python-dateutil~=2.9.0
ovos-utils~=0.0, >=0.0.38
ovos_workshop~=0.0, >=0.0.15
ovos_bus_client~=0.0, >=0.0.6
ovos-lingua-franca~=0.0, >=0.4.7
ovos-mark1-utils~=0.0.0a2
1 change: 1 addition & 0 deletions skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"systemDeps": false,
"requirements": {
"python": [
"ovos-lingua-franca~=0.0, >=0.4.7",
"ovos-lingua-franca~=0.4.8a1",
"ovos-mark1-utils~=0.0.0a2",
"ovos-utils~=0.0, >=0.0.38",
Expand Down
31 changes: 25 additions & 6 deletions test/test_intents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ en-us:
- like glados
- like portal
- forrtal song
robotics_laws_intent:
- say the laws of robotics
- do you know the robotic laws
rock_paper_scissors_lizard_spock_intent:
- rock paper scissors lizard spock
bill_and_ted_intent:
Expand All @@ -76,6 +73,31 @@ en-us:
sing_intent:
- sing
- sing me a song
law_of_robotics.intent:
- what are the laws of robotics
- tell me the laws of robotic
- tell me the laws of robotics
- recite the laws of robotic
- recite the laws of robotics
- speak the laws of robotic
- speak the laws of robotics
- what is first law of robotic
- what is first law of robotics
- what is the first law of robotic
- what is the first law of robotics
- tell me the first law of robotic
- tell me first law of robotic
- tell me the first law of robotics
- tell me first law of robotics
- recite first law of robotic
- recite first law of robotics
- recite the first law of robotic
- recite the first law of robotics
- speak the first law of robotic
- speak first law of robotic
- speak the first law of robotics
- speak first law of robotics

de-de:
adult_mode_intent:
- hurt me plenty
Expand Down Expand Up @@ -121,9 +143,6 @@ de-de:
- portal Lied
- like glados
- like portal
# roboticskeyword:
# - Roboter
# - Robotic
rock_paper_scissors_lizard_spock_intent:
- Schere Stein Papier Echse Spock
stardate_intent:
Expand Down
12 changes: 4 additions & 8 deletions test/test_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
languages:
- "en-us"

regex: []

# vocab is lowercase .voc file basenames
vocab:
- arnold_keyword
Expand All @@ -12,10 +14,8 @@ vocab:
- glados_keyword
- hal_keyword
- languages_you_speak_keyword
- law_keyword
- pod_bay_doors_keyword
- portal_keyword
- robotics_keyword
- rock_paper_scissors_lizard_spock_keyword
- stardate_keyword
- adult_mode_keyword
Expand All @@ -38,20 +38,16 @@ dialog:
- stardate
- santa

# regex entities, not necessarily filenames
regex:
- LawOfRobotics

intents:
# Padatious intents are the `.intent` file names
padatious: []
padatious:
- law_of_robotics.intent

# Adapt intents are the names passed to `IntentBuilder`
adapt:
- stardate_intent
- pod_bay_doors_intent
- rock_paper_scissors_lizard_spock_intent
- robotics_laws_intent
- languages_you_speak_intent
- portal_intent
- hal_intent
Expand Down
36 changes: 35 additions & 1 deletion test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import pytest
from genericpath import isdir
from ovos_utils.fakebus import FakeBus
from ovos_bus_client import Message
from ovos_config.locale import setup_locale
from ovos_plugin_manager.skills import find_skill_plugins
from ovos_utils.fakebus import FakeBus
from skill_easter_eggs import EasterEggsSkill
from skill_easter_eggs.constants import SPICY_SOUNDS

Expand Down Expand Up @@ -51,6 +53,7 @@ class TestEasterEggSkill:
if not isdir(test_fs):
makedirs(data_dir)
makedirs(conf_dir)
setup_locale()

with open(join(conf_dir, "mycroft.conf"), "w", encoding="utf-8") as f:
f.write(dumps({"Audio": {"backends": {"ocp": {"active": True}}}}))
Expand Down Expand Up @@ -210,6 +213,37 @@ def test_handle_sing_intent(self, test_skill, reset_skill_mocks): # TODO: Expan
)
test_skill.speak_dialog.assert_called_once_with("singing", wait=5)

def test_laws_of_robotics_all(self, test_skill):
test_skill.handle_robotic_laws_intent(Message("test", {"ordinal": ""}))
test_skill.speak_dialog.assert_has_calls(
[
mock.call("rule1"),
mock.call("rule2"),
mock.call("rule3"),
]
)

@pytest.mark.parametrize(
"ordinal,dialog",
[
("first", "rule1"),
("1st", "rule1"),
("second", "rule2"),
("2nd", "rule2"),
("third", "rule3"),
("3rd", "rule3"),
],
)
def test_laws_of_robotics_individual(
self, test_skill, reset_skill_mocks, ordinal, dialog
):
other_rules = ["rule1", "rule2", "rule3"]
other_rules.remove(dialog)
test_skill.handle_robotic_laws_intent(Message("test", {"ordinal": ordinal}))
test_skill.speak_dialog.assert_has_calls([mock.call(dialog)])
for rule in other_rules:
assert mock.call(rule) not in test_skill.speak_dialog.mock_calls

def test_get_display_date(self, test_skill):
# TODO: Fully implement
assert True
Expand Down

0 comments on commit d39f858

Please sign in to comment.