Skip to content

Commit

Permalink
es support
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 12, 2024
1 parent 5626221 commit 1472b26
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/es/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "y",
"or": "o"
}
39 changes: 35 additions & 4 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,9 @@ def join_word_list(items: List[str], connector: str, sep: str, lang: str) -> str
"""
if lang.startswith("it"):
return _join_word_list_it(items, connector, sep)
elif lang.startswith("es"):
return _join_word_list_es(items, connector, sep)

cons = {
"and": _get_word(lang, "and"),
"or": _get_word(lang, "or")
Expand Down Expand Up @@ -2568,15 +2571,43 @@ def _join_word_list_it(items: List[str], connector: str, sep: str = ",") -> str:
else:
sep += " "

# Join the list with Italian euphonic rules applied to the last connector
joined_string = sep.join(item for item in items[:-1])
final_connector = cons[connector]
if len(items) > 2:
joined_string = sep.join(item for item in items[:-1])
else:
joined_string = items[0]

# Check for euphonic transformation cases for "e" and "o"
if cons[connector] == "e" and items[-1][0].lower() == "e":
final_connector = "ed"
elif cons[connector] == "o" and items[-1][0].lower() == "o":
final_connector = "od"
else:
final_connector = cons[connector]
return f"{joined_string} {final_connector} {items[-1]}"


def _join_word_list_es(items: List[str], connector: str, sep: str = ",") -> str:
cons = {
"and": _get_word("es", "and"),
"or": _get_word("es", "or")
}
if not items:
return ""
if len(items) == 1:
return str(items[0])

if not sep:
sep = ", "
else:
sep += " "

final_connector = cons[connector]
if len(items) > 2:
joined_string = sep.join(item for item in items[:-1])
else:
joined_string = items[0]

# Check for euphonic transformation cases for "y"
if cons[connector] == "y" and items[-1][0].lower() == "i":
final_connector = "e"

return f"{joined_string} {final_connector} {items[-1]}"
10 changes: 9 additions & 1 deletion test/unittests/test_euphony.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from ovos_workshop.skills.ovos import _join_word_list_it
from ovos_workshop.skills.ovos import _join_word_list_it, _join_word_list_es


class TestJoinWordListIt(unittest.TestCase):
Expand Down Expand Up @@ -43,5 +43,13 @@ def test_single_word(self):
self.assertEqual(result, "mare")


class TestJoinWordListEs(unittest.TestCase):

def test_euphonic_conjunction_and(self):
# Test euphonic transformation from "y" to "e"
result = _join_word_list_es(["Juan", "Irene"], "and")
self.assertEqual(result, "Juan e Irene")


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

0 comments on commit 1472b26

Please sign in to comment.