mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Merge pull request #5481 from explosion/feature/blank-shortcut-v2
Add blank:{lang} shortcut support to util.load_model
This commit is contained in:
commit
e1cb7e838b
|
@ -135,3 +135,14 @@ def test_ascii_filenames():
|
|||
root = Path(__file__).parent.parent
|
||||
for path in root.glob("**/*"):
|
||||
assert all(ord(c) < 128 for c in path.name), path.name
|
||||
|
||||
|
||||
def test_load_model_blank_shortcut():
|
||||
"""Test that using a model name like "blank:en" works as a shortcut for
|
||||
spacy.blank("en").
|
||||
"""
|
||||
nlp = util.load_model("blank:en")
|
||||
assert nlp.lang == "en"
|
||||
assert nlp.pipeline == []
|
||||
with pytest.raises(ImportError):
|
||||
util.load_model("blank:fjsfijsdof")
|
||||
|
|
|
@ -161,6 +161,8 @@ def load_model(name, **overrides):
|
|||
if not data_path or not data_path.exists():
|
||||
raise IOError(Errors.E049.format(path=path2str(data_path)))
|
||||
if isinstance(name, basestring_): # in data dir / shortcut
|
||||
if name.startswith("blank:"): # shortcut for blank model
|
||||
return get_lang_class(name.replace("blank:", ""))()
|
||||
if name in set([d.name for d in data_path.iterdir()]):
|
||||
return load_model_from_link(name, **overrides)
|
||||
if is_package(name): # installed as package
|
||||
|
|
Loading…
Reference in New Issue
Block a user