From 9a0d2fdef1b7577db9f6d5b988891808a1feea2c Mon Sep 17 00:00:00 2001 From: ines Date: Mon, 8 May 2017 23:50:45 +0200 Subject: [PATCH] Add load_lang_class() util function --- spacy/__init__.py | 3 +-- spacy/util.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) 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