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 lists, so you can append Span objects to them or access a member at a given index.

SpanGroup.__init__ method

Create a SpanGroup.

docThe document the span group belongs to. Doc
nameThe 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
attrsOptional JSON-serializable attributes to attach to the span group. Dict[str, Any]
spansThe spans to add to the span group. Iterable[Span]

SpanGroup.doc property

The Doc object the span group is referring to.


SpanGroup.has_overlap property

Check whether the span group contains overlapping spans.


SpanGroup.__len__ method

Get the number of spans in the group.


SpanGroup.__getitem__ method

Get a span from the group.

iThe item index. int

SpanGroup.append method

Add a Span object to the group. The span must refer to the same Doc object as the span group.

spanThe 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.

spansThe spans to add. Iterable[Span]

SpanGroup.to_bytes method

Serialize the span group to a bytestring.


SpanGroup.from_bytes method

Load the span group from a bytestring. Modifies the object in place and returns it.

bytes_dataThe data to load from. bytes