diff --git a/spacy/__init__.py b/spacy/__init__.py index dd8af47ac..6723c2be4 100644 --- a/spacy/__init__.py +++ b/spacy/__init__.py @@ -15,8 +15,7 @@ def load(name, **overrides): meta = util.parse_package_meta(model_path) if 'lang' not in meta: raise IOError('No language setting found in model meta.') - module = importlib.import_module('.%s' % meta['lang'], 'spacy') - cls = getattr(module, module.__all__[0]) + cls = util.load_lang_class(meta['lang']) overrides['meta'] = meta overrides['path'] = model_path return cls(**overrides) diff --git a/spacy/util.py b/spacy/util.py index 0429904c0..8baa70952 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -31,6 +31,11 @@ def get_lang_class(name): 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): if not require_exists: return _data_path