Add load_lang_class() util function

This commit is contained in:
ines 2017-05-08 23:50:45 +02:00
parent 614aa09582
commit 9a0d2fdef1
2 changed files with 6 additions and 2 deletions

View File

@ -15,8 +15,7 @@ def load(name, **overrides):
meta = util.parse_package_meta(model_path) meta = util.parse_package_meta(model_path)
if 'lang' not in meta: if 'lang' not in meta:
raise IOError('No language setting found in model meta.') raise IOError('No language setting found in model meta.')
module = importlib.import_module('.%s' % meta['lang'], 'spacy') cls = util.load_lang_class(meta['lang'])
cls = getattr(module, module.__all__[0])
overrides['meta'] = meta overrides['meta'] = meta
overrides['path'] = model_path overrides['path'] = model_path
return cls(**overrides) return cls(**overrides)

View File

@ -31,6 +31,11 @@ def get_lang_class(name):
return LANGUAGES[lang] return LANGUAGES[lang]
def load_lang_class(lang, depth='.'):
module = importlib.import_module('.lang.%s' % lang, 'spacy')
return getattr(module, module.__all__[0])
def get_data_path(require_exists=True): def get_data_path(require_exists=True):
if not require_exists: if not require_exists:
return _data_path return _data_path