mirror of https://github.com/explosion/spaCy.git
Update deprecated methods and add warnings
This commit is contained in:
parent
260cb37224
commit
9659391944
|
@ -8,8 +8,14 @@ from . import util
|
||||||
|
|
||||||
|
|
||||||
def load(name, **overrides):
|
def load(name, **overrides):
|
||||||
from .deprecated import resolve_load_name
|
depr_path = overrides.get('path')
|
||||||
name = resolve_load_name(name, **overrides)
|
if depr_path not in (True, False, None):
|
||||||
|
util.deprecated(
|
||||||
|
"As of spaCy v2.0, the keyword argument `path=` is deprecated. "
|
||||||
|
"You can now call spacy.load with the path as its first argument, "
|
||||||
|
"and the model's meta.json will be used to determine the language "
|
||||||
|
"to load. For example:\nnlp = spacy.load('{}')".format(depr_path),
|
||||||
|
'error')
|
||||||
return util.load_model(name, **overrides)
|
return util.load_model(name, **overrides)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,40 +1,4 @@
|
||||||
# coding: utf8
|
# coding: utf8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .util import prints
|
|
||||||
from .cli import download
|
|
||||||
from . import about
|
|
||||||
|
|
||||||
|
|
||||||
PRON_LEMMA = "-PRON-"
|
PRON_LEMMA = "-PRON-"
|
||||||
|
|
||||||
|
|
||||||
def depr_model_download(lang):
|
|
||||||
"""Replace en/de download modules within, warn and ownload default models.
|
|
||||||
|
|
||||||
lang (unicode): Language shortcut, 'en' or 'de'.
|
|
||||||
"""
|
|
||||||
prints("The spacy.%s.download command is now deprecated. Please use "
|
|
||||||
"spacy download [model name or shortcut] instead. For "
|
|
||||||
"more info, see the documentation:" % lang,
|
|
||||||
about.__docs_models__,
|
|
||||||
"Downloading default '%s' model now..." % lang,
|
|
||||||
title="Warning: deprecated command")
|
|
||||||
download(lang)
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_load_name(name, **overrides):
|
|
||||||
"""Resolve model loading if deprecated path kwarg in overrides.
|
|
||||||
|
|
||||||
name (unicode): Name of model to load.
|
|
||||||
**overrides: Overrides specified in spacy.load().
|
|
||||||
RETURNS: Model name or value of path kwarg.
|
|
||||||
"""
|
|
||||||
if overrides.get('path') not in (None, False, True):
|
|
||||||
name = overrides.get('path')
|
|
||||||
prints("To load a model from a path, you can now use the first "
|
|
||||||
"argument. The model meta is used to load the Language class.",
|
|
||||||
"OLD: spacy.load('en', path='/some/path')",
|
|
||||||
"NEW: spacy.load('/some/path')",
|
|
||||||
title="Warning: deprecated argument 'path'")
|
|
||||||
return name
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
# coding: utf8
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from ..deprecated import depr_model_download
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
depr_model_download('de')
|
|
|
@ -1,8 +0,0 @@
|
||||||
# coding: utf8
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from ..deprecated import depr_model_download
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
depr_model_download('en')
|
|
|
@ -62,7 +62,11 @@ cdef class Tokenizer:
|
||||||
return (self.__class__, args, None, None)
|
return (self.__class__, args, None, None)
|
||||||
|
|
||||||
cpdef Doc tokens_from_list(self, list strings):
|
cpdef Doc tokens_from_list(self, list strings):
|
||||||
# TODO: deprecation warning
|
util.deprecated(
|
||||||
|
"Tokenizer.from_from list is now deprecated. Create a new Doc "
|
||||||
|
"object instead and pass in the strings as the `words` keyword "
|
||||||
|
"argument, for example:\nfrom spacy.tokens import Doc\n"
|
||||||
|
"doc = Doc(nlp.vocab, words=[...])")
|
||||||
return Doc(self.vocab, words=strings)
|
return Doc(self.vocab, words=strings)
|
||||||
|
|
||||||
@cython.boundscheck(False)
|
@cython.boundscheck(False)
|
||||||
|
|
|
@ -842,7 +842,10 @@ cdef class Doc:
|
||||||
"""
|
"""
|
||||||
cdef unicode tag, lemma, ent_type
|
cdef unicode tag, lemma, ent_type
|
||||||
if len(args) == 3:
|
if len(args) == 3:
|
||||||
# TODO: Warn deprecation
|
util.deprecated(
|
||||||
|
"Positional arguments to Doc.merge are deprecated. Instead, "
|
||||||
|
"use the keyword arguments, for example tag=, lemma= or "
|
||||||
|
"ent_type=.")
|
||||||
tag, lemma, ent_type = args
|
tag, lemma, ent_type = args
|
||||||
attributes[TAG] = tag
|
attributes[TAG] = tag
|
||||||
attributes[LEMMA] = lemma
|
attributes[LEMMA] = lemma
|
||||||
|
|
|
@ -19,6 +19,7 @@ from ..attrs cimport IS_OOV, IS_TITLE, IS_UPPER, LIKE_URL, LIKE_NUM, LIKE_EMAIL
|
||||||
from ..attrs cimport IS_STOP, ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX
|
from ..attrs cimport IS_STOP, ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX
|
||||||
from ..attrs cimport LENGTH, CLUSTER, LEMMA, POS, TAG, DEP
|
from ..attrs cimport LENGTH, CLUSTER, LEMMA, POS, TAG, DEP
|
||||||
from ..compat import is_config
|
from ..compat import is_config
|
||||||
|
from .. import util
|
||||||
from .. import about
|
from .. import about
|
||||||
from .underscore import Underscore
|
from .underscore import Underscore
|
||||||
|
|
||||||
|
@ -330,8 +331,14 @@ cdef class Token:
|
||||||
return self.c.r_kids
|
return self.c.r_kids
|
||||||
|
|
||||||
property sent_start:
|
property sent_start:
|
||||||
# TODO deprecation warning
|
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
|
util.deprecated(
|
||||||
|
"Token.sent_start is now deprecated. Use Token.is_sent_start "
|
||||||
|
"instead, which returns a boolean value or None if the answer "
|
||||||
|
"is unknown – instead of a misleading 0 for False and 1 for "
|
||||||
|
"True. It also fixes a quirk in the old logic that would "
|
||||||
|
"always set the property to 0 for the first word of the "
|
||||||
|
"document.")
|
||||||
# Handle broken backwards compatibility case: doc[0].sent_start
|
# Handle broken backwards compatibility case: doc[0].sent_start
|
||||||
# was False.
|
# was False.
|
||||||
if self.i == 0:
|
if self.i == 0:
|
||||||
|
|
Loading…
Reference in New Issue