2020-08-07 16:27:13 +03:00
|
|
|
import pytest
|
|
|
|
from spacy import registry
|
|
|
|
from spacy.lookups import Lookups
|
|
|
|
from spacy.util import get_lang_class
|
|
|
|
|
|
|
|
|
|
|
|
# fmt: off
|
|
|
|
# Only include languages with no external dependencies
|
|
|
|
# excluded: ru, uk
|
|
|
|
# excluded for custom tables: pl
|
|
|
|
LANGUAGES = ["el", "en", "fr", "nl"]
|
|
|
|
# fmt: on
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("lang", LANGUAGES)
|
|
|
|
def test_lemmatizer_initialize(lang, capfd):
|
2020-09-03 18:31:14 +03:00
|
|
|
@registry.misc("lemmatizer_init_lookups")
|
2020-08-07 16:27:13 +03:00
|
|
|
def lemmatizer_init_lookups():
|
|
|
|
lookups = Lookups()
|
|
|
|
lookups.add_table("lemma_lookup", {"cope": "cope"})
|
|
|
|
lookups.add_table("lemma_index", {"verb": ("cope", "cop")})
|
|
|
|
lookups.add_table("lemma_exc", {"verb": {"coping": ("cope",)}})
|
|
|
|
lookups.add_table("lemma_rules", {"verb": [["ing", ""]]})
|
|
|
|
return lookups
|
|
|
|
|
|
|
|
"""Test that languages can be initialized."""
|
|
|
|
nlp = get_lang_class(lang)()
|
2020-09-03 18:31:14 +03:00
|
|
|
nlp.add_pipe("lemmatizer", config={"lookups": {"@misc": "lemmatizer_init_lookups"}})
|
2020-08-07 16:27:13 +03:00
|
|
|
# Check for stray print statements (see #3342)
|
|
|
|
doc = nlp("test") # noqa: F841
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
assert not captured.out
|