Containers

SpanGroup

classv3

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.

NameDescription
docThe document the span group belongs to. Doc
keyword-only
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.

NameDescription

SpanGroup.has_overlap property

Check whether the span group contains overlapping spans.

NameDescription

SpanGroup.__len__ method

Get the number of spans in the group.

NameDescription

SpanGroup.__getitem__ method

Get a span from the group. Note that a copy of the span is returned, so if any changes are made to this span, they are not reflected in the corresponding member of the span group. The item or group will need to be reassigned for changes to be reflected in the span group.

NameDescription
iThe item index. int

SpanGroup.__setitem__ methodv3.3

Set a span in the span group.

NameDescription
iThe item index. int
spanThe new value. Span

SpanGroup.__delitem__ methodv3.3

Delete a span from the span group.

NameDescription
iThe item index. int

SpanGroup.__add__ methodv3.3

Concatenate the current span group with another span group and return the result in a new span group. Any attrs from the first span group will have precedence over attrs in the second.

NameDescription
otherThe span group or spans to concatenate. Union[SpanGroup, Iterable[Span]]

SpanGroup.__iadd__ methodv3.3

Append an iterable of spans or the content of a span group to the current span group. Any attrs in the other span group will be added for keys that are not already present in the current span group.

NameDescription
otherThe span group or spans to append. Union[SpanGroup, Iterable[Span]]

SpanGroup.__iter__ methodv3.5

Iterate over the spans in this span group.

NameDescription

SpanGroup.append method

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

NameDescription
spanThe span to append. Span

SpanGroup.extend method

Add multiple Span objects or contents of another SpanGroup to the group. All spans must refer to the same Doc object as the span group.

NameDescription
spansThe spans to add. Union[SpanGroup, Iterable[“Span”]]

SpanGroup.copy methodv3.3

Return a copy of the span group.

NameDescription
docThe document to which the copy is bound. Defaults to None for the current doc. Optional[Doc]

SpanGroup.to_bytes method

Serialize the span group to a bytestring.

NameDescription

SpanGroup.from_bytes method

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

NameDescription
bytes_dataThe data to load from. bytes