2018-09-25 21:38:08 +03:00
|
|
|
import pytest
|
2023-06-14 18:48:41 +03:00
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
from spacy.morphology import Morphology
|
|
|
|
from spacy.strings import StringStore, get_string_id
|
2018-09-25 21:38:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def morphology():
|
2020-08-07 16:27:13 +03:00
|
|
|
return Morphology(StringStore())
|
2018-09-25 21:38:08 +03:00
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
|
2018-09-25 21:38:08 +03:00
|
|
|
def test_init(morphology):
|
|
|
|
pass
|
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
|
2018-09-25 22:07:48 +03:00
|
|
|
def test_add_morphology_with_string_names(morphology):
|
2020-01-24 00:01:54 +03:00
|
|
|
morphology.add({"Case": "gen", "Number": "sing"})
|
2018-09-25 21:38:08 +03:00
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
|
2018-09-25 22:07:48 +03:00
|
|
|
def test_add_morphology_with_int_ids(morphology):
|
2020-01-24 00:01:54 +03:00
|
|
|
morphology.strings.add("Case")
|
|
|
|
morphology.strings.add("gen")
|
|
|
|
morphology.strings.add("Number")
|
|
|
|
morphology.strings.add("sing")
|
2020-02-18 17:38:18 +03:00
|
|
|
morphology.add(
|
|
|
|
{
|
|
|
|
get_string_id("Case"): get_string_id("gen"),
|
|
|
|
get_string_id("Number"): get_string_id("sing"),
|
|
|
|
}
|
|
|
|
)
|
2018-09-25 21:38:08 +03:00
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
|
2018-09-25 22:07:48 +03:00
|
|
|
def test_add_morphology_with_mix_strings_and_ints(morphology):
|
2020-01-24 00:01:54 +03:00
|
|
|
morphology.strings.add("PunctSide")
|
|
|
|
morphology.strings.add("ini")
|
2020-02-18 17:38:18 +03:00
|
|
|
morphology.add(
|
|
|
|
{get_string_id("PunctSide"): get_string_id("ini"), "VerbType": "aux"}
|
|
|
|
)
|
2018-09-25 21:38:08 +03:00
|
|
|
|
|
|
|
|
2018-09-25 22:07:48 +03:00
|
|
|
def test_morphology_tags_hash_distinctly(morphology):
|
2020-01-24 00:01:54 +03:00
|
|
|
tag1 = morphology.add({"PunctSide": "ini", "VerbType": "aux"})
|
|
|
|
tag2 = morphology.add({"Case": "gen", "Number": "sing"})
|
2018-09-25 22:07:48 +03:00
|
|
|
assert tag1 != tag2
|
|
|
|
|
2019-03-08 15:28:53 +03:00
|
|
|
|
2018-09-25 22:07:48 +03:00
|
|
|
def test_morphology_tags_hash_independent_of_order(morphology):
|
2020-01-24 00:01:54 +03:00
|
|
|
tag1 = morphology.add({"Case": "gen", "Number": "sing"})
|
|
|
|
tag2 = morphology.add({"Number": "sing", "Case": "gen"})
|
2018-09-25 22:07:48 +03:00
|
|
|
assert tag1 == tag2
|