Skip to content

Commit

Permalink
fix:es_euphony (#281)
Browse files Browse the repository at this point in the history
* fix:es_euphony
  • Loading branch information
JarbasAl authored Nov 12, 2024
1 parent 3c598fb commit 8ce8593
Show file tree
Hide file tree
Showing 2 changed files with 26 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").replace("ó", "o").replace("í", "i").replace("á", "a")
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] == "i":
final_connector = "e"
# Check for euphonic transformation cases for "o"
if cons[connector] == "o" and w[0] == "o":
final_connector = "u"

return f"{joined_string} {final_connector} {items[-1]}"
18 changes: 18 additions & 0 deletions test/unittests/test_euphony.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ 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")
result = _join_word_list_es(["mató", "hirió"], "and")
self.assertEqual(result, "mató e hirió")
result = _join_word_list_es(["geografía", "historia"], "and")
self.assertEqual(result, "geografía e historia")

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")
result = _join_word_list_es(["paz", "hiógrafo"], "and")
self.assertEqual(result, "paz y hiógrafo")

def test_euphonic_conjunction_or(self):
# Test euphonic transformation from "o" to "u"
Expand All @@ -72,5 +89,6 @@ def test_euphonic_conjunction_or(self):
self.assertEqual(result, "unos u otros")



if __name__ == "__main__":
unittest.main()

0 comments on commit 8ce8593

Please sign in to comment.