mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-11 08:42:28 +03:00
Literal True for first/last options
This commit is contained in:
parent
b615964be7
commit
915245ab8e
|
@ -979,6 +979,7 @@ class Errors(metaclass=ErrorsWithCodes):
|
||||||
E4007 = ("Span {var} {value} must be {op} Span {existing_var} "
|
E4007 = ("Span {var} {value} must be {op} Span {existing_var} "
|
||||||
"{existing_value}.")
|
"{existing_value}.")
|
||||||
E4008 = ("Span {pos}_char {value} does not correspond to a token {pos}.")
|
E4008 = ("Span {pos}_char {value} does not correspond to a token {pos}.")
|
||||||
|
E4009 = ("The '{attr}' parameter should be 'None' or 'True', but found '{value}'.")
|
||||||
|
|
||||||
|
|
||||||
RENAMED_LANGUAGE_CODES = {"xx": "mul", "is": "isl"}
|
RENAMED_LANGUAGE_CODES = {"xx": "mul", "is": "isl"}
|
||||||
|
|
|
@ -757,8 +757,8 @@ class Language:
|
||||||
*,
|
*,
|
||||||
before: Optional[Union[str, int]] = None,
|
before: Optional[Union[str, int]] = None,
|
||||||
after: Optional[Union[str, int]] = None,
|
after: Optional[Union[str, int]] = None,
|
||||||
first: Optional[bool] = None,
|
first: Optional[Literal[True]] = None,
|
||||||
last: Optional[bool] = None,
|
last: Optional[Literal[True]] = None,
|
||||||
source: Optional["Language"] = None,
|
source: Optional["Language"] = None,
|
||||||
config: Dict[str, Any] = SimpleFrozenDict(),
|
config: Dict[str, Any] = SimpleFrozenDict(),
|
||||||
raw_config: Optional[Config] = None,
|
raw_config: Optional[Config] = None,
|
||||||
|
@ -777,8 +777,8 @@ class Language:
|
||||||
component directly before.
|
component directly before.
|
||||||
after (Union[str, int]): Name or index of the component to insert new
|
after (Union[str, int]): Name or index of the component to insert new
|
||||||
component directly after.
|
component directly after.
|
||||||
first (bool): If True, insert component first in the pipeline.
|
first (True or None): If True, insert component first in the pipeline.
|
||||||
last (bool): If True, insert component last in the pipeline.
|
last (True or None): If True, insert component last in the pipeline.
|
||||||
source (Language): Optional loaded nlp object to copy the pipeline
|
source (Language): Optional loaded nlp object to copy the pipeline
|
||||||
component from.
|
component from.
|
||||||
config (Dict[str, Any]): Config parameters to use for this component.
|
config (Dict[str, Any]): Config parameters to use for this component.
|
||||||
|
@ -823,18 +823,22 @@ class Language:
|
||||||
self,
|
self,
|
||||||
before: Optional[Union[str, int]] = None,
|
before: Optional[Union[str, int]] = None,
|
||||||
after: Optional[Union[str, int]] = None,
|
after: Optional[Union[str, int]] = None,
|
||||||
first: Optional[bool] = None,
|
first: Optional[Literal[True]] = None,
|
||||||
last: Optional[bool] = None,
|
last: Optional[Literal[True]] = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Determine where to insert a pipeline component based on the before/
|
"""Determine where to insert a pipeline component based on the before/
|
||||||
after/first/last values.
|
after/first/last values.
|
||||||
|
|
||||||
before (str): Name or index of the component to insert directly before.
|
before (str): Name or index of the component to insert directly before.
|
||||||
after (str): Name or index of component to insert directly after.
|
after (str): Name or index of component to insert directly after.
|
||||||
first (bool): If True, insert component first in the pipeline.
|
first (True or None): If True, insert component first in the pipeline.
|
||||||
last (bool): If True, insert component last in the pipeline.
|
last (True or None): If True, insert component last in the pipeline.
|
||||||
RETURNS (int): The index of the new pipeline component.
|
RETURNS (int): The index of the new pipeline component.
|
||||||
"""
|
"""
|
||||||
|
if first is not None and first is not True:
|
||||||
|
raise ValueError(Errors.E4009.format(attr="first", value=first))
|
||||||
|
if last is not None and last is not True:
|
||||||
|
raise ValueError(Errors.E4009.format(attr="last", value=last))
|
||||||
all_args = {"before": before, "after": after, "first": first, "last": last}
|
all_args = {"before": before, "after": after, "first": first, "last": last}
|
||||||
if sum(arg is not None for arg in [before, after, first, last]) >= 2:
|
if sum(arg is not None for arg in [before, after, first, last]) >= 2:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user