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

Feature/es extra tests #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ venv.bak/

# mypy
.mypy_cache/

### VisualStudioCode ###
.vscode/*

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
4 changes: 2 additions & 2 deletions lingua_franca/lang/common_data_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from collections import OrderedDict


_ARTICLES = {'el', 'la', 'los', 'las'}
_ARTICLES_ES = {'el', 'la', 'los', 'las'}


NUM_STRING_ES = {
Expand All @@ -41,7 +41,7 @@
14: 'catorce',
15: 'quince',
16: 'dieciséis',
17: 'diecisete',
17: 'diecisiete',
18: 'dieciocho',
19: 'diecinueve',
20: 'veinte',
Expand Down
5 changes: 2 additions & 3 deletions lingua_franca/lang/format_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ def nice_number_es(number, speech, denominators):
else:
# else return "2 y 3 cuarto", for example
strNumber = '{} y {} {}'.format(whole, num, den_str)
if num > 1 and den != 3:
# if the numerator is greater than 1 and the denominator
# is not 3 ("tercio"), add an s for plural
if num > 1:
# if the numerator is greater than 1 add an s for plural
strNumber += 's'

return strNumber
Expand Down
6 changes: 3 additions & 3 deletions lingua_franca/lang/parse_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"diecinueve": 19,
"veinte": 20,
"veintiuno": 21,
u"veintid�s": 22,
u"veintitr�s": 23,
u"veintidós": 22,
u"veintitrés": 23,
"veintidos": 22,
"veintitres": 23,
u"veintitrés": 23,
Expand Down Expand Up @@ -266,7 +266,7 @@ def es_cte(i, s):
def es_number_word(i, mi, ma):
if i < len(words):
v = es_numbers.get(words[i])
if v and v >= mi and v <= ma:
if v is not None and v >= mi and v <= ma:
return v, i + 1
return None

Expand Down
6 changes: 5 additions & 1 deletion test/test_format_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
0.027: '0,027',
0.5: 'un medio',
1.333: '1 y 1 tercio',
2.666: '2 y 2 tercio',
2.666: '2 y 2 tercios',
0.25: 'un cuarto',
1.25: '1 y 1 cuarto',
0.75: '3 cuartos',
Expand Down Expand Up @@ -106,12 +106,16 @@ def test_convert_int(self):
self.assertEqual(pronounce_number(10, lang="es"), "diez")
self.assertEqual(pronounce_number(15, lang="es"), "quince")
self.assertEqual(pronounce_number(21, lang="es"), "veintiuno")
self.assertEqual(pronounce_number(22, lang="es"), "veintidós")
self.assertEqual(pronounce_number(23, lang="es"), "veintitrés")
self.assertEqual(pronounce_number(26, lang="es"), "veintiséis")
self.assertEqual(pronounce_number(27, lang="es"), "veintisiete")
self.assertEqual(pronounce_number(30, lang="es"), "treinta")
self.assertEqual(pronounce_number(19, lang="es"), "diecinueve")
self.assertEqual(pronounce_number(88, lang="es"), "ochenta y ocho")
self.assertEqual(pronounce_number(46, lang="es"), "cuarenta y seis")
self.assertEqual(pronounce_number(99, lang="es"), "noventa y nueve")
self.assertEqual(pronounce_number(100, lang="es"), "100")

def test_convert_negative_int(self):
self.assertEqual(pronounce_number(-1, lang="es"), "menos uno")
Expand Down
14 changes: 10 additions & 4 deletions test/test_parse_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def test_numbers_es(self):
self.assertEqual(normalize("esto es cuatro cinco seis prueba",
lang="es"),
"esto es 4 5 6 prueba")
self.assertEqual(normalize(u"siete m�s ocho m�s nueve", lang="es"),
u"7 m�s 8 m�s 9")
self.assertEqual(normalize(u"siete más ocho más nueve", lang="es"),
u"7 más 8 más 9")
self.assertEqual(normalize("diez once doce trece catorce quince",
lang="es"),
"10 11 12 13 14 15")
self.assertEqual(normalize("dos cero uno", lang="es"),
"2 0 1")
self.assertEqual(normalize("hay cero perros", lang="es"),
"hay 0 perros")
self.assertEqual(normalize(u"dieciséis diecisiete", lang="es"),
"16 17")
self.assertEqual(normalize(u"dieciocho diecinueve", lang="es"),
Expand All @@ -52,13 +56,15 @@ def test_numbers_es(self):
"20 30 40")
self.assertEqual(normalize(u"treinta y dos caballos", lang="es"),
"32 caballos")
self.assertEqual(normalize(u"éramos treinta y algunos caballos", lang="es"),
"éramos 30 y algunos caballos")
self.assertEqual(normalize(u"cien caballos", lang="es"),
"100 caballos")
self.assertEqual(normalize(u"ciento once caballos", lang="es"),
"111 caballos")
self.assertEqual(normalize(u"hab�a cuatrocientas una vacas",
self.assertEqual(normalize(u"había cuatrocientas una vacas",
lang="es"),
u"hab�a 401 vacas")
u"había 401 vacas")
self.assertEqual(normalize(u"dos mil", lang="es"),
"2000")
self.assertEqual(normalize(u"dos mil trescientas cuarenta y cinco",
Expand Down