mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-05 04:40:20 +03:00
move warning to get_lang_class
This commit is contained in:
parent
8b4415f29b
commit
60314f20f6
|
@ -543,6 +543,7 @@ def test_spacy_blank():
|
||||||
assert nlp.config["training"]["dropout"] == 0.2
|
assert nlp.config["training"]["dropout"] == 0.2
|
||||||
assert nlp.meta["name"] == "my_custom_model"
|
assert nlp.meta["name"] == "my_custom_model"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"lang,target",
|
"lang,target",
|
||||||
[
|
[
|
||||||
|
@ -566,11 +567,8 @@ def test_language_matching(lang, target):
|
||||||
Test that we can look up languages by equivalent or nearly-equivalent
|
Test that we can look up languages by equivalent or nearly-equivalent
|
||||||
language codes.
|
language codes.
|
||||||
"""
|
"""
|
||||||
if target is None:
|
assert find_matching_language(lang) == target
|
||||||
assert find_matching_language(lang) == target
|
|
||||||
else:
|
|
||||||
with pytest.warns(UserWarning):
|
|
||||||
assert find_matching_language(lang) == target
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"lang,target",
|
"lang,target",
|
||||||
|
|
|
@ -283,7 +283,6 @@ def find_matching_language(lang: str) -> Optional[str]:
|
||||||
import spacy.lang # noqa: F401
|
import spacy.lang # noqa: F401
|
||||||
|
|
||||||
if lang == "xx":
|
if lang == "xx":
|
||||||
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang="mul"))
|
|
||||||
return "mul"
|
return "mul"
|
||||||
|
|
||||||
# Find out which language modules we have
|
# Find out which language modules we have
|
||||||
|
@ -302,8 +301,6 @@ def find_matching_language(lang: str) -> Optional[str]:
|
||||||
# is labeled that way is probably trying to be distinct from 'zh' and
|
# is labeled that way is probably trying to be distinct from 'zh' and
|
||||||
# shouldn't automatically match.
|
# shouldn't automatically match.
|
||||||
match = langcodes.closest_supported_match(lang, possible_languages, max_distance=9)
|
match = langcodes.closest_supported_match(lang, possible_languages, max_distance=9)
|
||||||
if match is not None:
|
|
||||||
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang=match))
|
|
||||||
return match
|
return match
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,6 +327,8 @@ def get_lang_class(lang: str) -> Type["Language"]:
|
||||||
match = None
|
match = None
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
|
if match != lang:
|
||||||
|
warnings.warn(Warnings.W124.format(lang=lang, renamed_lang=match))
|
||||||
lang = match
|
lang = match
|
||||||
module = importlib.import_module(f".lang.{lang}", "spacy")
|
module = importlib.import_module(f".lang.{lang}", "spacy")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user