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. 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.
Name | Description |
---|---|
i | The item index. int |
RETURNS | The span at the given index. Span |
SpanGroup.__setitem__ methodv3.3
Set a span in the span group.
Name | Description |
---|---|
i | The item index. int |
span | The new value. Span |
SpanGroup.__delitem__ methodv3.3
Delete a span from the span group.
Name | Description |
---|---|
i | The 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.
Name | Description |
---|---|
other | The span group or spans to concatenate. Union[SpanGroup, Iterable[Span]] |
RETURNS | The new span group. SpanGroup |
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.
Name | Description |
---|---|
other | The span group or spans to append. Union[SpanGroup, Iterable[Span]] |
RETURNS | The span group. SpanGroup |
SpanGroup.__iter__ methodv3.5
Iterate over the spans in this span group.
Name | Description |
---|---|
YIELDS | A span in this span group. 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 or contents of another SpanGroup
to
the group. All spans must refer to the same Doc
object as the span
group.
Name | Description |
---|---|
spans | The spans to add. Union[SpanGroup, Iterable[“Span”]] |
SpanGroup.copy methodv3.3
Return a copy of the span group.
Name | Description |
---|---|
doc | The document to which the copy is bound. Defaults to None for the current doc. Optional[Doc] |
RETURNS | A copy of the SpanGroup object. SpanGroup |
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 |