spaCy/spacy/tests/morphology/test_morph_features.py

49 lines
1.3 KiB
Python
Raw Normal View History

2019-03-08 15:28:53 +03:00
# coding: utf-8
2018-09-25 21:38:08 +03:00
from __future__ import unicode_literals
2019-03-08 15:28:53 +03:00
2018-09-25 21:38:08 +03:00
import pytest
2019-03-08 15:28:53 +03:00
from spacy.morphology import Morphology
from spacy.strings import StringStore, get_string_id
from spacy.lemmatizer import Lemmatizer
2018-09-25 21:38:08 +03:00
@pytest.fixture
def morphology():
return Morphology(StringStore(), {}, Lemmatizer())
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):
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):
2019-03-07 19:14:57 +03:00
morphology.add({get_string_id("Case_gen"), get_string_id("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_mix_strings_and_ints(morphology):
2019-03-08 15:28:53 +03:00
morphology.add({get_string_id("PunctSide_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):
2019-03-08 15:28:53 +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):
2019-03-08 15:28:53 +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
2019-03-08 15:28:53 +03:00
2018-09-25 22:07:48 +03:00
def test_update_morphology_tag(morphology):
tag1 = morphology.add({"Case_gen"})
tag2 = morphology.update(tag1, {"Number_sing"})
assert tag1 != tag2
2019-03-08 15:28:53 +03:00
tag3 = morphology.add({"Number_sing", "Case_gen"})
2018-09-25 22:07:48 +03:00
assert tag2 == tag3