Commit 7b76db41f6c160168ce399bb2370d28eb81651a4
1 parent
39dc2b34
Exists in
master
and in
1 other branch
Adiciona conversão de números romanos
Showing
3 changed files
with
31 additions
and
9 deletions
Show diff stats
src/AplicaRegras.py
| ... | ... | @@ -38,12 +38,12 @@ class AplicaRegras(object): |
| 38 | 38 | # Gera arvore a partir do arquivos regras.xml |
| 39 | 39 | def get_root(self): |
| 40 | 40 | '''Verifica qual o SO e gera o path de onde se encontra o diretório data. |
| 41 | - ''' | |
| 42 | - if "TRANSLATE_DATA" in environ: | |
| 41 | + ''' | |
| 42 | + if "TRANSLATE_DATA" in environ: | |
| 43 | 43 | arq_regras = path.join(environ.get("TRANSLATE_DATA"), "regras.xml") |
| 44 | 44 | return ET.parse(arq_regras).getroot() |
| 45 | - elif platform.system() == 'Windows': | |
| 46 | - return ET.parse(environ.get("HOMEDRIVE")+'\\vlibras-libs\\vlibras-translate\data\\regras.xml').getroot() | |
| 45 | + elif platform.system() == "Windows": | |
| 46 | + return ET.parse(environ.get("HOMEDRIVE")+'\\vlibras-libs\\vlibras-translate\\data\\regras.xml').getroot() | |
| 47 | 47 | return ET.parse(expanduser("~")+'/vlibras-translate/data/regras.xml').getroot() |
| 48 | 48 | |
| 49 | 49 | # Aplica regras morfológicas apartir do arquivo regras.xml |
| ... | ... | @@ -399,9 +399,11 @@ class AplicaRegras(object): |
| 399 | 399 | tag = it.get_ticket() |
| 400 | 400 | |
| 401 | 401 | if tag == "NUM": |
| 402 | + num_romano = roman_to_int(it.get_word()) | |
| 403 | + lista_simplificada[it.get_count()] = [num_romano.decode('utf-8'), 'NUM-R'] | |
| 402 | 404 | num = True |
| 403 | 405 | |
| 404 | - if tag[-2:] == "-P" and self.verificar_excecao_plural(it.get_word()): | |
| 406 | + if tag[-2:] == "-P" or tag[-2:] == "_P" and self.verificar_excecao_plural(it.get_word()): | |
| 405 | 407 | singular = self.analisar_plural(it.get_word()) |
| 406 | 408 | lista_simplificada[it.get_count()][0] = singular |
| 407 | 409 | |
| ... | ... | @@ -438,7 +440,7 @@ class AplicaRegras(object): |
| 438 | 440 | return token[:-2]+"l" |
| 439 | 441 | return token |
| 440 | 442 | elif(token[-1] == "s"): |
| 441 | - #TODO: Palavras paroxítonas ou proparoxítonas terminadas em S. Ex: lápis, vírus, tagênis, ônibus, etc | |
| 443 | + #TODO: Palavras paroxítonas ou proparoxítonas terminadas em S. Ex: lápis, vírus, tagênis, ônibus, etc | |
| 442 | 444 | return token[:-1] |
| 443 | 445 | else: |
| 444 | 446 | return token | ... | ... |
src/ConverteExtenso.py
| ... | ... | @@ -25,7 +25,28 @@ ext = [{"um":"1", "dois":"2", "tres":"3", "quatro":"4", "cinco":"5", "seis":"6", |
| 25 | 25 | und = {"mil":1000, "milhao":1000000, "bilhao":1000000000, "trilhao":1000000000000} |
| 26 | 26 | unds = {"mil":"000", "milhao":"000000","milhoes":"000000", "bilhao":"000000000","bilhoes":"000000000", "trilhao":"000000000000", "trilhoes":"000000000000"} |
| 27 | 27 | |
| 28 | - | |
| 28 | +numeral_map = zip( | |
| 29 | + (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1), | |
| 30 | + ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I') | |
| 31 | +) | |
| 32 | + | |
| 33 | +def int_to_roman(i): | |
| 34 | + result = [] | |
| 35 | + for integer, numeral in numeral_map: | |
| 36 | + count = int(i / integer) | |
| 37 | + result.append(numeral * count) | |
| 38 | + i -= integer * count | |
| 39 | + return ''.join(result) | |
| 40 | + | |
| 41 | +def roman_to_int(n): | |
| 42 | + n = unicode(n).upper() | |
| 43 | + | |
| 44 | + i = result = 0 | |
| 45 | + for integer, numeral in numeral_map: | |
| 46 | + while n[i:i + len(numeral)] == numeral: | |
| 47 | + result += integer | |
| 48 | + i += len(numeral) | |
| 49 | + return str(result) | |
| 29 | 50 | |
| 30 | 51 | def oneDigit(x): |
| 31 | 52 | return ext[0][x] | ... | ... |
src/alexp.py
| ... | ... | @@ -98,10 +98,9 @@ def corrigeAnotacao(lista): |
| 98 | 98 | def encontraArquivo(): |
| 99 | 99 | """Encontra arquivo na pasta vlibras-translate. |
| 100 | 100 | """ |
| 101 | - so = platform.system() | |
| 102 | 101 | if "TRANSLATE_DATA" in environ: |
| 103 | 102 | return path.join(environ.get("TRANSLATE_DATA"), "cfg.syn.nltk") |
| 104 | - elif so == 'Windows': | |
| 103 | + elif platform.system() == 'Windows': | |
| 105 | 104 | return environ.get("HOMEDRIVE") + "\\vlibras-libs\\vlibras-translate\data\cfg.syn.nltk" |
| 106 | 105 | return expanduser("~") + "/vlibras-translate/data/cfg.syn.nltk" |
| 107 | 106 | ... | ... |