2018-09-25 18:38:08 +00:00
|
|
|
import pytest
|
2023-06-14 15:48:41 +00:00
|
|
|
|
2019-03-08 12:28:53 +00:00
|
|
|
from spacy.morphology import Morphology
|
|
|
|
from spacy.strings import StringStore, get_string_id
|
2018-09-25 18:38:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def morphology():
|
2020-08-07 13:27:13 +00:00
|
|
|
return Morphology(StringStore())
|
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
|