mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
fdb8815ef5
* `MorphAnalysis.get` returns only the field values * Move `_normalize_props` inside `Morphology` as `Morphology.normalize_attrs` and simplify * Simplify POS field detection/conversion * Convert all non-POS features to strings * `Morphology` returns an empty string for a missing morph to align with the FEATS string returned for an existing morph * Remove unused `list_to_feats`
22 lines
856 B
Python
22 lines
856 B
Python
from spacy.morphology import Morphology
|
|
|
|
|
|
def test_feats_converters():
|
|
feats = "Case=dat,gen|Number=sing"
|
|
feats_dict = {"Case": "dat,gen", "Number": "sing"}
|
|
|
|
# simple conversions
|
|
assert Morphology.dict_to_feats(feats_dict) == feats
|
|
assert Morphology.feats_to_dict(feats) == feats_dict
|
|
|
|
# roundtrips
|
|
assert Morphology.dict_to_feats(Morphology.feats_to_dict(feats)) == feats
|
|
assert Morphology.feats_to_dict(Morphology.dict_to_feats(feats_dict)) == feats_dict
|
|
|
|
# unsorted input is normalized
|
|
unsorted_feats = "Number=sing|Case=gen,dat"
|
|
unsorted_feats_dict = {"Case": "gen,dat", "Number": "sing"}
|
|
assert Morphology.feats_to_dict(unsorted_feats) == feats_dict
|
|
assert Morphology.dict_to_feats(unsorted_feats_dict) == feats
|
|
assert Morphology.dict_to_feats(Morphology.feats_to_dict(unsorted_feats)) == feats
|