2017-05-08 16:52:01 +03:00
|
|
|
# coding: utf8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-05-12 16:37:39 +03:00
|
|
|
from ...attrs import LIKE_NUM
|
2017-05-08 16:52:01 +03:00
|
|
|
|
|
|
|
|
2017-05-12 16:37:39 +03:00
|
|
|
_num_words = ['zero', 'um', 'dois', 'três', 'quatro', 'cinco', 'seis', 'sete',
|
|
|
|
'oito', 'nove', 'dez', 'onze', 'doze', 'treze', 'catorze',
|
|
|
|
'quinze', 'dezasseis', 'dezassete', 'dezoito', 'dezanove', 'vinte',
|
|
|
|
'trinta', 'quarenta', 'cinquenta', 'sessenta', 'setenta',
|
|
|
|
'oitenta', 'noventa', 'cem', 'mil', 'milhão', 'bilião', 'trilião',
|
|
|
|
'quadrilião']
|
2017-05-08 16:52:01 +03:00
|
|
|
|
2018-01-08 05:38:44 +03:00
|
|
|
_ordinal_words = ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto',
|
|
|
|
'sétimo', 'oitavo', 'nono', 'décimo', 'vigésimo', 'trigésimo',
|
|
|
|
'quadragésimo', 'quinquagésimo', 'sexagésimo', 'septuagésimo',
|
|
|
|
'octogésimo', 'nonagésimo', 'centésimo', 'ducentésimo',
|
|
|
|
'trecentésimo', 'quadringentésimo', 'quingentésimo', 'sexcentésimo',
|
|
|
|
'septingentésimo', 'octingentésimo', 'nongentésimo', 'milésimo',
|
|
|
|
'milionésimo', 'bilionésimo']
|
2017-05-08 16:52:01 +03:00
|
|
|
|
2017-05-12 16:37:39 +03:00
|
|
|
|
|
|
|
def like_num(text):
|
|
|
|
text = text.replace(',', '').replace('.', '')
|
|
|
|
if text.isdigit():
|
|
|
|
return True
|
|
|
|
if text.count('/') == 1:
|
|
|
|
num, denom = text.split('/')
|
|
|
|
if num.isdigit() and denom.isdigit():
|
|
|
|
return True
|
2018-01-08 05:25:08 +03:00
|
|
|
if text.lower() in _num_words:
|
2017-05-12 16:37:39 +03:00
|
|
|
return True
|
2018-01-08 05:28:50 +03:00
|
|
|
if text.lower() in _ordinal_words:
|
|
|
|
return True
|
2017-05-12 16:37:39 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
LEX_ATTRS = {
|
|
|
|
LIKE_NUM: like_num
|
|
|
|
}
|