Update resolve_model_name

This commit is contained in:
ines 2017-03-17 19:26:28 +01:00
parent aedefef49d
commit e01fbacf81
1 changed files with 15 additions and 6 deletions

View File

@ -88,10 +88,11 @@ def fix_glove_vectors_loading(overrides):
def resolve_model_name(name): def resolve_model_name(name):
"""If spaCy is loaded with 'en' or 'de', check if symlink already exists. If """If spaCy is loaded with 'de', check if symlink already exists. If
not, user have upgraded from older version and have old models installed. not, user have upgraded from older version and have old models installed.
Check if old model directory exists and if so, return that instead and create Check if old model directory exists and if so, return that instead and create
shortcut link. shortcut link. If English model is found and no shortcut exists, raise error
and tell user to install new model.
""" """
if name == 'en' or name == 'de': if name == 'en' or name == 'de':
@ -99,11 +100,19 @@ def resolve_model_name(name):
data_path = Path(util.get_data_path()) data_path = Path(util.get_data_path())
model_path = data_path / name model_path = data_path / name
v_model_paths = [data_path / Path(name + '-' + v) for v in versions] v_model_paths = [data_path / Path(name + '-' + v) for v in versions]
if not model_path.exists():
if not model_path.exists(): # no shortcut found
for v_path in v_model_paths: for v_path in v_model_paths:
if v_path.exists(): if v_path.exists(): # versioned model directory found
if name == 'de':
link(v_path, name) link(v_path, name)
return name return name
else:
raise ValueError(
"Found English model at {p}. This model is not "
"compatible with the current version. See "
"https://spacy.io/docs/usage/models to download the "
"new model.".format(p=v_path))
return name return name