2017-01-05 20:11:04 +03:00
|
|
|
import pytest
|
2023-06-26 12:41:03 +03:00
|
|
|
|
2018-07-25 00:38:44 +03:00
|
|
|
from spacy.lang.en.lex_attrs import like_num
|
2017-01-05 20:11:04 +03:00
|
|
|
|
|
|
|
|
2017-05-29 23:14:31 +03:00
|
|
|
def test_en_tokenizer_handles_long_text(en_tokenizer):
|
2017-01-05 20:11:04 +03:00
|
|
|
text = """Tributes pour in for late British Labour Party leader
|
|
|
|
|
|
|
|
Tributes poured in from around the world Thursday
|
|
|
|
to the late Labour Party leader John Smith, who died earlier from a massive
|
|
|
|
heart attack aged 55.
|
|
|
|
|
|
|
|
In Washington, the US State Department issued a statement regretting "the
|
|
|
|
untimely death" of the rapier-tongued Scottish barrister and parliamentarian.
|
|
|
|
|
|
|
|
"Mr. Smith, throughout his distinguished"""
|
|
|
|
tokens = en_tokenizer(text)
|
|
|
|
assert len(tokens) == 76
|
|
|
|
|
|
|
|
|
2018-11-27 03:09:36 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"text,length",
|
|
|
|
[
|
|
|
|
("The U.S. Army likes Shock and Awe.", 8),
|
|
|
|
("U.N. regulations are not a part of their concern.", 10),
|
|
|
|
("“Isn't it?”", 6),
|
|
|
|
("""Yes! "I'd rather have a walk", Ms. Comble sighed. """, 15),
|
|
|
|
("""'Me too!', Mr. P. Delaware cried. """, 11),
|
|
|
|
("They ran about 10km.", 6),
|
2020-07-20 15:48:51 +03:00
|
|
|
("But then the 6,000-year ice age came...", 10),
|
2018-11-27 03:09:36 +03:00
|
|
|
],
|
|
|
|
)
|
2017-05-29 23:14:31 +03:00
|
|
|
def test_en_tokenizer_handles_cnts(en_tokenizer, text, length):
|
2017-01-05 20:11:04 +03:00
|
|
|
tokens = en_tokenizer(text)
|
|
|
|
assert len(tokens) == length
|
2017-05-09 12:06:34 +03:00
|
|
|
|
|
|
|
|
2018-11-27 03:09:36 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"text,match",
|
|
|
|
[
|
|
|
|
("10", True),
|
|
|
|
("1", True),
|
|
|
|
("10,000", True),
|
|
|
|
("10,00", True),
|
|
|
|
("999.0", True),
|
|
|
|
("one", True),
|
|
|
|
("two", True),
|
|
|
|
("billion", True),
|
|
|
|
("dog", False),
|
|
|
|
(",", False),
|
|
|
|
("1/2", True),
|
|
|
|
],
|
|
|
|
)
|
2017-05-09 12:06:34 +03:00
|
|
|
def test_lex_attrs_like_number(en_tokenizer, text, match):
|
|
|
|
tokens = en_tokenizer(text)
|
|
|
|
assert len(tokens) == 1
|
|
|
|
assert tokens[0].like_num == match
|
2018-07-25 00:38:44 +03:00
|
|
|
|
|
|
|
|
2021-05-07 11:26:42 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"word", ["third", "Millionth", "100th", "Hundredth", "23rd", "52nd"]
|
|
|
|
)
|
2020-07-29 21:22:47 +03:00
|
|
|
def test_en_lex_attrs_like_number_for_ordinal(word):
|
|
|
|
assert like_num(word)
|
|
|
|
|
|
|
|
|
2018-11-27 03:09:36 +03:00
|
|
|
@pytest.mark.parametrize("word", ["eleven"])
|
2018-07-25 00:38:44 +03:00
|
|
|
def test_en_lex_attrs_capitals(word):
|
|
|
|
assert like_num(word)
|
|
|
|
assert like_num(word.upper())
|