SpanGroup
A group of arbitrary, potentially overlapping Span
objects that
all belong to the same Doc
object. The group can be named, and you
can attach additional attributes to it. Span groups are generally accessed via
the Doc.spans
attribute, which will convert lists of spans
into a SpanGroup
object for you automatically on assignment. SpanGroup
objects behave similar to list
s, so you can append Span
objects to them or
access a member at a given index.
SpanGroup.__init__ method
Create a SpanGroup
.
Name | Description |
---|---|
doc | The document the span group belongs to. Doc |
keyword-only | |
name | The name of the span group. If the span group is created automatically on assignment to doc.spans , the key name is used. Defaults to "" . str |
attrs | Optional JSON-serializable attributes to attach to the span group. Dict[str, Any] |
spans | The spans to add to the span group. Iterable[Span] |
SpanGroup.doc property
The Doc
object the span group is referring to.
Name | Description |
---|---|
RETURNS | The reference document. Doc |
SpanGroup.has_overlap property
Check whether the span group contains overlapping spans.
Name | Description |
---|---|
RETURNS | Whether the span group contains overlaps. bool |
SpanGroup.__len__ method
Get the number of spans in the group.
Name | Description |
---|---|
RETURNS | The number of spans in the group. int |
SpanGroup.__getitem__ method
Get a span from the group.
Name | Description |
---|---|
i | The item index. int |
RETURNS | The span at the given index. Span |
SpanGroup.append method
Add a Span
object to the group. The span must refer to the same
Doc
object as the span group.
Name | Description |
---|---|
span | The span to append. Span |
SpanGroup.extend method
Add multiple Span
objects to the group. All spans must refer to
the same Doc
object as the span group.
Name | Description |
---|---|
spans | The spans to add. Iterable[Span] |
SpanGroup.to_bytes method
Serialize the span group to a bytestring.
Name | Description |
---|---|
RETURNS | The serialized SpanGroup . bytes |
SpanGroup.from_bytes method
Load the span group from a bytestring. Modifies the object in place and returns it.
Name | Description |
---|---|
bytes_data | The data to load from. bytes |
RETURNS | The SpanGroup object. SpanGroup |