2017-04-06 16:48:45 +00:00
|
|
|
import pytest
|
2020-04-30 09:13:23 +00:00
|
|
|
from spacy.lang.es.lex_attrs import like_num
|
2017-04-06 16:48:45 +00:00
|
|
|
|
|
|
|
|
2018-07-24 21:38:44 +00:00
|
|
|
def test_es_tokenizer_handles_long_text(es_tokenizer):
|
2017-04-06 16:48:45 +00:00
|
|
|
text = """Cuando a José Mujica lo invitaron a dar una conferencia
|
|
|
|
|
|
|
|
en Oxford este verano, su cabeza hizo "crac". La "más antigua" universidad de habla
|
|
|
|
|
|
|
|
inglesa, esa que cobra decenas de miles de euros de matrícula a sus alumnos
|
|
|
|
|
|
|
|
y en cuyos salones han disertado desde Margaret Thatcher hasta Stephen Hawking,
|
|
|
|
|
|
|
|
reclamaba los servicios de este viejo de 81 años, formado en un colegio público
|
|
|
|
|
|
|
|
en Montevideo y que pregona las bondades de la vida austera."""
|
|
|
|
tokens = es_tokenizer(text)
|
|
|
|
assert len(tokens) == 90
|
|
|
|
|
|
|
|
|
2018-11-27 00:09:36 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"text,length",
|
|
|
|
[
|
|
|
|
("¿Por qué José Mujica?", 6),
|
|
|
|
("“¿Oh no?”", 6),
|
|
|
|
("""¡Sí! "Vámonos", contestó José Arcadio Buendía""", 11),
|
|
|
|
("Corrieron aprox. 10km.", 5),
|
|
|
|
("Y entonces por qué...", 5),
|
|
|
|
],
|
|
|
|
)
|
2018-07-24 21:38:44 +00:00
|
|
|
def test_es_tokenizer_handles_cnts(es_tokenizer, text, length):
|
2017-04-06 16:48:45 +00:00
|
|
|
tokens = es_tokenizer(text)
|
|
|
|
assert len(tokens) == length
|
2020-04-30 09:13:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"text,match",
|
|
|
|
[
|
|
|
|
("10", True),
|
|
|
|
("1", True),
|
|
|
|
("10.000", True),
|
|
|
|
("1000", True),
|
|
|
|
("999,0", True),
|
|
|
|
("uno", True),
|
|
|
|
("dos", True),
|
|
|
|
("billón", True),
|
|
|
|
("veintiséis", True),
|
|
|
|
("perro", False),
|
|
|
|
(",", False),
|
|
|
|
("1/2", True),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_lex_attrs_like_number(es_tokenizer, text, match):
|
|
|
|
tokens = es_tokenizer(text)
|
|
|
|
assert len(tokens) == 1
|
|
|
|
assert tokens[0].like_num == match
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("word", ["once"])
|
|
|
|
def test_es_lex_attrs_capitals(word):
|
|
|
|
assert like_num(word)
|
2020-05-21 12:14:01 +00:00
|
|
|
assert like_num(word.upper())
|