Tidy up __init__.py

This commit is contained in:
Ines Montani 2020-07-25 12:14:37 +02:00
parent 8d9d28eb8b
commit a063a82c40
2 changed files with 34 additions and 17 deletions

View File

@ -104,7 +104,6 @@ exclude =
.git,
__pycache__,
_tokenizer_exceptions_list.py,
spacy/__init__.py
[tool:pytest]
markers =

View File

@ -1,32 +1,50 @@
from typing import Union, Iterable, Dict, Any
from pathlib import Path
import warnings
import sys
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
warnings.filterwarnings("ignore", message="numpy.dtype size changed") # noqa
warnings.filterwarnings("ignore", message="numpy.ufunc size changed") # noqa
# These are imported as part of the API
from thinc.api import prefer_gpu, require_gpu
from thinc.api import prefer_gpu, require_gpu # noqa: F401
from . import pipeline
from .cli.info import info
from .glossary import explain
from .about import __version__
from .errors import Errors, Warnings
from . import pipeline # noqa: F401
from .cli.info import info # noqa: F401
from .glossary import explain # noqa: F401
from .about import __version__ # noqa: F401
from .util import registry # noqa: F401
from .errors import Errors
from .language import Language
from . import util
from .util import registry
if sys.maxunicode == 65535:
raise SystemError(Errors.E130)
config = registry
def load(
name: Union[str, Path],
disable: Iterable[str] = tuple(),
component_cfg: Dict[str, Dict[str, Any]] = util.SimpleFrozenDict(),
) -> Language:
"""Load a spaCy model from an installed package or a local path.
name (str): Package name or model path.
disable (Iterable[str]): Names of pipeline components to disable.
component_cfg (Dict[str, dict]): Config overrides for pipeline components,
keyed by component names.
RETURNS (Language): The loaded nlp object.
"""
return util.load_model(name, disable=disable, component_cfg=component_cfg)
def load(name, **overrides):
return util.load_model(name, **overrides)
def blank(name: str, **overrides) -> Language:
"""Create a blank nlp object for a given language code.
def blank(name, **kwargs):
name (str): The language code, e.g. "en".
**overrides: Keyword arguments passed to language subclass on init.
RETURNS (Language): The nlp object.
"""
LangClass = util.get_lang_class(name)
return LangClass(**kwargs)
return LangClass(**overrides)