2018-09-25 18:38:08 +00:00
|
|
|
import pytest
|
2019-03-08 12:28:53 +00:00
|
|
|
from spacy.morphology import Morphology
|
|
|
|
from spacy.strings import StringStore, get_string_id
|
|
|
|
from spacy.lemmatizer import Lemmatizer
|
2019-10-01 19:36:04 +00:00
|
|
|
from spacy.lookups import Lookups
|
2018-09-25 18:38:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def morphology():
|
2019-10-01 19:36:04 +00:00
|
|
|
lemmatizer = Lemmatizer(Lookups())
|
|
|
|
return Morphology(StringStore(), {}, lemmatizer)
|
2018-09-25 18:38:08 +00:00
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
|
2018-09-25 18:38:08 +00:00
|
|
|
def test_init(morphology):
|
|
|
|
pass
|
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
|
2018-09-25 19:07:48 +00:00
|
|
|
def test_add_morphology_with_string_names(morphology):
|
2020-01-23 21:01:54 +00:00
|
|
|
morphology.add({"Case": "gen", "Number": "sing"})
|
2018-09-25 18:38:08 +00:00
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
|
2018-09-25 19:07:48 +00:00
|
|
|
def test_add_morphology_with_int_ids(morphology):
|
2020-01-23 21:01:54 +00:00
|
|
|
morphology.strings.add("Case")
|
|
|
|
morphology.strings.add("gen")
|
|
|
|
morphology.strings.add("Number")
|
|
|
|
morphology.strings.add("sing")
|
2020-02-18 14:38:18 +00:00
|
|
|
morphology.add(
|
|
|
|
{
|
|
|
|
get_string_id("Case"): get_string_id("gen"),
|
|
|
|
get_string_id("Number"): get_string_id("sing"),
|
|
|
|
}
|
|
|
|
)
|
2018-09-25 18:38:08 +00:00
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
|
2018-09-25 19:07:48 +00:00
|
|
|
def test_add_morphology_with_mix_strings_and_ints(morphology):
|
2020-01-23 21:01:54 +00:00
|
|
|
morphology.strings.add("PunctSide")
|
|
|
|
morphology.strings.add("ini")
|
2020-02-18 14:38:18 +00:00
|
|
|
morphology.add(
|
|
|
|
{get_string_id("PunctSide"): get_string_id("ini"), "VerbType": "aux"}
|
|
|
|
)
|
2018-09-25 18:38:08 +00:00
|
|
|
|
|
|
|
|
2018-09-25 19:07:48 +00:00
|
|
|
def test_morphology_tags_hash_distinctly(morphology):
|
2020-01-23 21:01:54 +00:00
|
|
|
tag1 = morphology.add({"PunctSide": "ini", "VerbType": "aux"})
|
|
|
|
tag2 = morphology.add({"Case": "gen", "Number": "sing"})
|
2018-09-25 19:07:48 +00:00
|
|
|
assert tag1 != tag2
|
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
|
2018-09-25 19:07:48 +00:00
|
|
|
def test_morphology_tags_hash_independent_of_order(morphology):
|
2020-01-23 21:01:54 +00:00
|
|
|
tag1 = morphology.add({"Case": "gen", "Number": "sing"})
|
|
|
|
tag2 = morphology.add({"Number": "sing", "Case": "gen"})
|
2018-09-25 19:07:48 +00:00
|
|
|
assert tag1 == tag2
|