spaCy/spacy/tokens/span_group.pyi
Adriane Boyd 31cd5141bd TEST: Doc.ents as SpanGroup
Overview of required changes to support `SpanGroup` rather than
`Tuple[Span]`:

* implement slice for `SpanGroup`
* return `SpanGroup` for `SpanGroup + x` or `x + SpanGroup` rather than
refusing to concatenate (currently without good error handling)

Side effects:

* if appending to `Doc.ents`, only `Iterable[Span]` is supported rather
than other formats like raw entity tuples from matcher results, but you
can still assign mixed data in any of the currently supported formats to
`Doc.ents`
  * for the `Matcher` case, `as_spans` provides a good alternative
2023-03-07 16:26:02 +01:00

32 lines
934 B
Python

from typing import Any, Dict, Iterable, Optional, Union, overload
from .doc import Doc
from .span import Span
class SpanGroup:
name: str
attrs: Dict[str, Any]
def __init__(
self,
doc: Doc,
*,
name: str = ...,
attrs: Dict[str, Any] = ...,
spans: Iterable[Span] = ...
) -> None: ...
def __repr__(self) -> str: ...
@property
def doc(self) -> Doc: ...
@property
def has_overlap(self) -> bool: ...
def __iter__(self): ...
def __len__(self) -> int: ...
def append(self, span: Span) -> None: ...
def extend(self, spans: Iterable[Span]) -> None: ...
@overload
def __getitem__(self, i: int) -> Span: ...
@overload
def __getitem__(self, i: slice) -> SpanGroup: ...
def to_bytes(self) -> bytes: ...
def from_bytes(self, bytes_data: bytes) -> SpanGroup: ...
def copy(self, doc: Optional[Doc] = ...) -> SpanGroup: ...