relative imports in __init__.py

This commit is contained in:
Henning Peters 2016-03-26 11:44:53 +01:00
parent db095a162c
commit c90d4a6f17
2 changed files with 9 additions and 9 deletions

View File

@ -1,15 +1,15 @@
from . import util
from .util import set_lang_class, get_lang_class, get_package, get_package_by_name
from .en import English
from .de import German
util.register_lang(English.lang, English)
util.register_lang(German.lang, German)
set_lang_class(English.lang, English)
set_lang_class(German.lang, German)
def load(name, vectors=None, via=None):
package = util.get_package_by_name(name, via=via)
vectors_package = util.get_package_by_name(vectors, via=via)
cls = util.get_lang(name)
package = get_package_by_name(name, via=via)
vectors_package = get_package_by_name(vectors, via=via)
cls = get_lang_class(name)
return cls(package=package, vectors_package=vectors_package)

View File

@ -17,12 +17,12 @@ from .attrs import TAG, HEAD, DEP, ENT_IOB, ENT_TYPE
LANGUAGES = {}
def register_lang(name, cls):
def set_lang_class(name, cls):
global LANGUAGES
LANGUAGES[name] = cls
def get_lang(name):
def get_lang_class(name):
lang = re.split('[^a-zA-Z0-9_]', name, 1)[0]
if lang not in LANGUAGES:
raise RuntimeError('Language not supported: %s' % lang)
@ -37,7 +37,7 @@ def get_package(data_dir):
def get_package_by_name(name=None, via=None):
package_name = name or about.__models__[about.__default_lang__]
lang = get_lang(package_name)
lang = get_lang_class(package_name)
try:
return sputnik.package(about.__title__, about.__version__,
package_name, data_path=via)