From f0a71e2562eb5550c80e8a4654b1aef75fcfd9b3 Mon Sep 17 00:00:00 2001 From: antoniomaciej Date: Sat, 17 Aug 2019 19:49:55 +0200 Subject: [PATCH 1/5] Add missing test cases for full coverage of format_es. Delete unnecessary condition for avoiding plural of Spanish word for third. Use proper Spanish tilde symbols in es tests and parse_es.py. Add ES suffix to ARTICLES collection in common_data_es, according to the convention used across this library. --- lingua_franca/lang/common_data_es.py | 4 ++-- lingua_franca/lang/format_es.py | 2 +- lingua_franca/lang/parse_es.py | 4 ++-- test/test_format_es.py | 6 +++++- test/test_parse_es.py | 8 ++++---- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lingua_franca/lang/common_data_es.py b/lingua_franca/lang/common_data_es.py index 64364a4a..0d831ff5 100644 --- a/lingua_franca/lang/common_data_es.py +++ b/lingua_franca/lang/common_data_es.py @@ -20,7 +20,7 @@ from collections import OrderedDict -_ARTICLES = {'el', 'la', 'los', 'las'} +_ARTICLES_ES = {'el', 'la', 'los', 'las'} NUM_STRING_ES = { @@ -41,7 +41,7 @@ 14: 'catorce', 15: 'quince', 16: 'dieciséis', - 17: 'diecisete', + 17: 'diecisiete', 18: 'dieciocho', 19: 'diecinueve', 20: 'veinte', diff --git a/lingua_franca/lang/format_es.py b/lingua_franca/lang/format_es.py index be7d0d19..087ab473 100644 --- a/lingua_franca/lang/format_es.py +++ b/lingua_franca/lang/format_es.py @@ -135,7 +135,7 @@ 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 num > 1: # if the numerator is greater than 1 and the denominator # is not 3 ("tercio"), add an s for plural strNumber += 's' diff --git a/lingua_franca/lang/parse_es.py b/lingua_franca/lang/parse_es.py index 1cdc7b16..d30eb1a4 100644 --- a/lingua_franca/lang/parse_es.py +++ b/lingua_franca/lang/parse_es.py @@ -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, diff --git a/test/test_format_es.py b/test/test_format_es.py index 4fdc4f7c..08aa1456 100644 --- a/test/test_format_es.py +++ b/test/test_format_es.py @@ -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.667: '2 y 2 tercios', 0.25: 'un cuarto', 1.25: '1 y 1 cuarto', 0.75: '3 cuartos', @@ -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") diff --git a/test/test_parse_es.py b/test/test_parse_es.py index cb92e312..2fd19a01 100644 --- a/test/test_parse_es.py +++ b/test/test_parse_es.py @@ -39,8 +39,8 @@ 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") @@ -56,9 +56,9 @@ def test_numbers_es(self): "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", From 65d1a7ac91bae4f2bdf4d7b28a778f4681ffe590 Mon Sep 17 00:00:00 2001 From: antoniomaciej Date: Sun, 18 Aug 2019 12:26:46 +0200 Subject: [PATCH 2/5] Fix parsing Spanish zero Full branch coverage of es_number_parse in parse_es.py. --- .gitignore | 7 +++++++ lingua_franca/lang/parse_es.py | 2 +- test/test_parse_es.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 894a44cc..12b2fa7c 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,10 @@ venv.bak/ # mypy .mypy_cache/ + +### VisualStudioCode ### +.vscode/* + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history \ No newline at end of file diff --git a/lingua_franca/lang/parse_es.py b/lingua_franca/lang/parse_es.py index d30eb1a4..e3c96801 100644 --- a/lingua_franca/lang/parse_es.py +++ b/lingua_franca/lang/parse_es.py @@ -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 diff --git a/test/test_parse_es.py b/test/test_parse_es.py index 2fd19a01..721e330f 100644 --- a/test/test_parse_es.py +++ b/test/test_parse_es.py @@ -44,6 +44,10 @@ def test_numbers_es(self): 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"), @@ -52,6 +56,8 @@ def test_numbers_es(self): "20 30 40") self.assertEqual(normalize(u"treinta y dos caballos", lang="es"), "32 caballos") + self.assertEqual(normalize(u"eramos treinta y algunos caballos", lang="es"), + "eramos 30 y algunos caballos") self.assertEqual(normalize(u"cien caballos", lang="es"), "100 caballos") self.assertEqual(normalize(u"ciento once caballos", lang="es"), From 1146dcef276956161fb5787195f51a0b87d04e9a Mon Sep 17 00:00:00 2001 From: antoniomaciej Date: Mon, 19 Aug 2019 21:23:18 +0200 Subject: [PATCH 3/5] Revert unintended change. --- test/test_format_es.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_format_es.py b/test/test_format_es.py index 08aa1456..55b9f9f9 100644 --- a/test/test_format_es.py +++ b/test/test_format_es.py @@ -29,7 +29,7 @@ 0.027: '0,027', 0.5: 'un medio', 1.333: '1 y 1 tercio', - 2.667: '2 y 2 tercios', + 2.666: '2 y 2 tercios', 0.25: 'un cuarto', 1.25: '1 y 1 cuarto', 0.75: '3 cuartos', From 815c9f0e0383f4200785540289f2d80e8126b71f Mon Sep 17 00:00:00 2001 From: antoniomaciej Date: Tue, 20 Aug 2019 22:17:38 +0200 Subject: [PATCH 4/5] Update comment after recent change on the condition being documented by it. --- lingua_franca/lang/format_es.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lingua_franca/lang/format_es.py b/lingua_franca/lang/format_es.py index 087ab473..0979e5aa 100644 --- a/lingua_franca/lang/format_es.py +++ b/lingua_franca/lang/format_es.py @@ -136,8 +136,7 @@ def nice_number_es(number, speech, denominators): # else return "2 y 3 cuarto", for example strNumber = '{} y {} {}'.format(whole, num, den_str) if num > 1: - # if the numerator is greater than 1 and the denominator - # is not 3 ("tercio"), add an s for plural + # if the numerator is greater than 1 add an s for plural strNumber += 's' return strNumber From 6b04622b09566763f347aa6f6d842a04b8b2ffc3 Mon Sep 17 00:00:00 2001 From: antoniomaciej Date: Sat, 24 Aug 2019 12:41:18 +0200 Subject: [PATCH 5/5] Spanish orthography fix. --- test/test_parse_es.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_parse_es.py b/test/test_parse_es.py index 721e330f..80f660a1 100644 --- a/test/test_parse_es.py +++ b/test/test_parse_es.py @@ -56,8 +56,8 @@ def test_numbers_es(self): "20 30 40") self.assertEqual(normalize(u"treinta y dos caballos", lang="es"), "32 caballos") - self.assertEqual(normalize(u"eramos treinta y algunos caballos", lang="es"), - "eramos 30 y algunos 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"),