mirror of
https://github.com/explosion/spaCy.git
synced 2025-10-29 15:07:54 +03:00
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
32 lines
934 B
Python
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: ...
|