mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Add util function to resolve arg to model path
1. check if in data dir or shortcut link 2. check if installed as a pip package 3. check if string is path to model 4. check if Path or Path-like object
This commit is contained in:
parent
a7801e7342
commit
326746eb15
|
@ -108,6 +108,22 @@ def read_json(location):
|
|||
return ujson.load(f)
|
||||
|
||||
|
||||
def resolve_model_path(name):
|
||||
data_path = get_data_path()
|
||||
if not data_path or not data_path.exists():
|
||||
raise IOError("Can't find spaCy data path: %s" % path2str(data_path))
|
||||
if isinstance(name, basestring_):
|
||||
if (data_path / name).exists(): # in data dir or shortcut link
|
||||
return (data_path / name)
|
||||
if is_package(name): # installed as a package
|
||||
return get_model_package_path(name)
|
||||
if Path(name).exists(): # path to model
|
||||
return Path(name)
|
||||
elif hasattr(name, 'exists'): # Path or Path-like object
|
||||
return name
|
||||
raise IOError("Can't find model '%s'" % name)
|
||||
|
||||
|
||||
def is_package(origin):
|
||||
"""
|
||||
Check if string maps to a package installed via pip.
|
||||
|
|
Loading…
Reference in New Issue
Block a user