mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-27 17:54:39 +03:00
relative imports in __init__.py
This commit is contained in:
parent
db095a162c
commit
c90d4a6f17
|
@ -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 .en import English
|
||||||
from .de import German
|
from .de import German
|
||||||
|
|
||||||
|
|
||||||
util.register_lang(English.lang, English)
|
set_lang_class(English.lang, English)
|
||||||
util.register_lang(German.lang, German)
|
set_lang_class(German.lang, German)
|
||||||
|
|
||||||
|
|
||||||
def load(name, vectors=None, via=None):
|
def load(name, vectors=None, via=None):
|
||||||
package = util.get_package_by_name(name, via=via)
|
package = get_package_by_name(name, via=via)
|
||||||
vectors_package = util.get_package_by_name(vectors, via=via)
|
vectors_package = get_package_by_name(vectors, via=via)
|
||||||
cls = util.get_lang(name)
|
cls = get_lang_class(name)
|
||||||
return cls(package=package, vectors_package=vectors_package)
|
return cls(package=package, vectors_package=vectors_package)
|
||||||
|
|
|
@ -17,12 +17,12 @@ from .attrs import TAG, HEAD, DEP, ENT_IOB, ENT_TYPE
|
||||||
LANGUAGES = {}
|
LANGUAGES = {}
|
||||||
|
|
||||||
|
|
||||||
def register_lang(name, cls):
|
def set_lang_class(name, cls):
|
||||||
global LANGUAGES
|
global LANGUAGES
|
||||||
LANGUAGES[name] = cls
|
LANGUAGES[name] = cls
|
||||||
|
|
||||||
|
|
||||||
def get_lang(name):
|
def get_lang_class(name):
|
||||||
lang = re.split('[^a-zA-Z0-9_]', name, 1)[0]
|
lang = re.split('[^a-zA-Z0-9_]', name, 1)[0]
|
||||||
if lang not in LANGUAGES:
|
if lang not in LANGUAGES:
|
||||||
raise RuntimeError('Language not supported: %s' % lang)
|
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):
|
def get_package_by_name(name=None, via=None):
|
||||||
package_name = name or about.__models__[about.__default_lang__]
|
package_name = name or about.__models__[about.__default_lang__]
|
||||||
lang = get_lang(package_name)
|
lang = get_lang_class(package_name)
|
||||||
try:
|
try:
|
||||||
return sputnik.package(about.__title__, about.__version__,
|
return sputnik.package(about.__title__, about.__version__,
|
||||||
package_name, data_path=via)
|
package_name, data_path=via)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user