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

Fix/general #12

Merged
merged 4 commits into from
Sep 22, 2022
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ Once you have installed all dependencies you are ready to go with:
from nl2ltl import translate
from nl2ltl.engines.rasa.core import RasaEngine
from nl2ltl.filters.simple_filters import BasicFilter
from nl2ltl.engines.utils import pretty

engine = RasaEngine()
filter = BasicFilter()
utterance = "Eventually send me a Slack after receiving a Gmail"

ltlf_formulas = translate(utterance, engine, filter)
pretty(ltlf_formulas)
```

The `translate` function takes a natural language utterance, an engine and an
Expand Down
12 changes: 0 additions & 12 deletions nl2ltl/engines/rasa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import glob
import os
from pathlib import Path
from typing import Dict

from pylogics.syntax.base import Formula


def _get_latest_model(path: Path):
Expand All @@ -17,12 +14,3 @@ def _get_latest_model(path: Path):
if len(list_of_files) == 0:
return None
return max(list_of_files, key=os.path.getctime)


def pretty(result: Dict[Formula, float]):
"""Pretty print Rasa output."""
print("=" * 150)
for k, v in result.items():
print(f"Declare Template: {str(k)}", end="\n")
print(f"English meaning: {k.to_english()}", end="\n")
print(f"Confidence: {str(v)}", end="\n\n")
9 changes: 9 additions & 0 deletions nl2ltl/engines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ def _get_formulas(name: str, args: Dict[str, float]) -> Set[Formula]:
grounding_func: Callable = grounding_map[str(class_name_match[0])]
grounded_formulas: Set[Formula] = grounding_func(args)
return grounded_formulas


def pretty(result: Dict[Formula, float]):
"""Pretty print Rasa output."""
print("=" * 150)
for k, v in result.items():
print(f"Declare Template: {str(k)}", end="\n")
print(f"English meaning: {k.to_english()}", end="\n")
print(f"Confidence: {str(v)}", end="\n\n")
13 changes: 10 additions & 3 deletions tests/test_gpt3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from nl2ltl import translate
from nl2ltl.engines.gpt3.core import GPT3Engine
from nl2ltl.filters.simple_filters import BasicFilter
from nl2ltl.filters.simple_filters import BasicFilter, GreedyFilter

from .conftest import UtterancesFixtures

Expand All @@ -22,9 +22,16 @@ def setup_class(cls):
"""
cls.gpt3_engine = GPT3Engine()
cls.basic_filter = BasicFilter()
cls.greedy_filter = GreedyFilter()

@pytest.mark.parametrize("utterance", UtterancesFixtures.utterances)
def test_rasa_engine(self, utterance):
"""Test Rasa engine for utterances."""
def test_gpt3_engine_basic(self, utterance):
"""Test GPT-3 engine for utterances with basic filter."""
output = translate(utterance, self.gpt3_engine, self.basic_filter)
assert isinstance(output, Dict)

@pytest.mark.parametrize("utterance", UtterancesFixtures.utterances)
def test_gpt3_engine_greedy(self, utterance):
"""Test GPT-3 engine for utterances with greedy filter."""
output = translate(utterance, self.gpt3_engine, self.greedy_filter)
assert isinstance(output, Dict)
13 changes: 10 additions & 3 deletions tests/test_rasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from nl2ltl import translate
from nl2ltl.engines.rasa.core import RasaEngine
from nl2ltl.filters.simple_filters import BasicFilter
from nl2ltl.filters.simple_filters import BasicFilter, GreedyFilter

from .conftest import UtterancesFixtures

Expand All @@ -22,9 +22,16 @@ def setup_class(cls):
"""
cls.rasa_engine = RasaEngine()
cls.basic_filter = BasicFilter()
cls.greedy_filter = GreedyFilter()

@pytest.mark.parametrize("utterance", UtterancesFixtures.utterances)
def test_rasa_engine(self, utterance):
"""Test Rasa engine for utterances."""
def test_rasa_engine_basic(self, utterance):
"""Test Rasa engine for utterances with basic filter."""
output = translate(utterance, self.rasa_engine, self.basic_filter)
assert isinstance(output, Dict)

@pytest.mark.parametrize("utterance", UtterancesFixtures.utterances)
def test_rasa_engine_greedy(self, utterance):
"""Test Rasa engine for utterances with greedy filter."""
output = translate(utterance, self.rasa_engine, self.greedy_filter)
assert isinstance(output, Dict)