Skip to content

Commit

Permalink
fix:es_euphony
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 12, 2024
1 parent 1a788f8 commit 627c7f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,11 +2607,13 @@ def _join_word_list_es(items: List[str], connector: str, sep: str = ",") -> str:
joined_string = items[0]

# Check for euphonic transformation cases for "y"
w = items[-1].lower().lstrip("h")[0]
if cons[connector] == "y" and w in ["i", "í"]:
final_connector = "e"
# Check for euphonic transformation cases for "o"
if cons[connector] == "o" and w in ["o", "ó"]:
final_connector = "u"
w = items[-1].lower().lstrip("h")
if not any([w.startswith("io"), w.startswith("ia"), w.startswith("ie")]):
# When following word starts by (H)IA, (H)IE or (H)IO, then usual Y preposition is used
if cons[connector] == "y" and w[0] in ["i", "í"]:
final_connector = "e"
# Check for euphonic transformation cases for "o"
if cons[connector] == "o" and w[0] in ["o", "ó"]:
final_connector = "u"

return f"{joined_string} {final_connector} {items[-1]}"
11 changes: 11 additions & 0 deletions test/unittests/test_euphony.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def test_euphonic_conjunction_and(self):
self.assertEqual(result, "vaqueros e indios")
result = _join_word_list_es(["Manuel", "Hilario"], "and")
self.assertEqual(result, "Manuel e Hilario")
result = _join_word_list_es(["mujer", "hijos"], "and")
self.assertEqual(result, "mujer e hijos")

def test_euphonic_conjunction_exceptionsa_and(self):
# When following word starts by (H)IA, (H)IE or (H)IO, then usual Y preposition is used
result = _join_word_list_es(["frio", "hielo"], "and")
self.assertEqual(result, "frio y hielo")
result = _join_word_list_es(["cloro", "iodo"], "and")
self.assertEqual(result, "cloro y iodo")
result = _join_word_list_es(["Eta", "Iota"], "and")
self.assertEqual(result, "Eta y Iota")

def test_euphonic_conjunction_or(self):
# Test euphonic transformation from "o" to "u"
Expand Down

0 comments on commit 627c7f4

Please sign in to comment.