AnnoSpan

class epitator.annospan.AnnoSpan(start, end, doc, label=None, metadata=None)[source]

Bases: object

A span of text with an annotation applied to it.

adjacent_to(other_span, max_dist=1)[source]

Return true if the span comes before or after other_span with at most max_dist charaters between them.

base_spans
comes_before(other_span, max_dist=1, allow_overlap=False)[source]

Return True if the span comes before the other_span and there are max_dist or fewer charaters between them.

>>> from .annotier import AnnoTier
>>> from .annodoc import AnnoDoc
>>> doc = AnnoDoc('one two three')
>>> tier = AnnoTier([AnnoSpan(0, 3, doc), AnnoSpan(4, 7, doc)])
>>> tier.spans[0].comes_before(tier.spans[1])
True
>>> tier.spans[1].comes_before(tier.spans[0])
False
contains(other_span)[source]

Return true if the span completely contains other_span.

distance(other_span)[source]

The number of characters between this span and the other one. If the spans overlap the distance is the negative length of their overlap.

>>> from .annotier import AnnoTier
>>> from .annodoc import AnnoDoc
>>> doc = AnnoDoc('one two three')
>>> tier = AnnoTier([AnnoSpan(0, 3, doc), AnnoSpan(8, 13, doc)])
>>> tier.spans[0].distance(tier.spans[1])
5
doc
end
extended_through(other_span)[source]

Create a new span that includes this one and the other span.

groupdict()[source]

Return a dict with all the labeled matches.

>>> from .annodoc import AnnoDoc
>>> doc = AnnoDoc('one two wolf')
>>> number_span_g = SpanGroup([AnnoSpan(0, 3, doc, 'number'),
...                            AnnoSpan(4, 7, doc, 'number'),
...                            AnnoSpan(8, 12, doc, 'animal')])
>>> number_span_g.groupdict()['number']
[AnnoSpan(0-3, number), AnnoSpan(4-7, number)]
>>> number_span_g.groupdict()['animal']
[AnnoSpan(8-12, animal)]
iterate_base_spans()[source]

Recursively iterate over all base_spans including base_spans of child SpanGroups.

iterate_leaf_base_spans()[source]

Return the leaf base spans in a SpanGroup tree.

label
metadata
overlaps(other_span)[source]

Return true if the span overlaps other_span.

start
text
to_dict()[source]

Return a json serializable dictionary.

trimmed()[source]

Create a new AnnoSpan based on this one with the offsets adjusted so that there is no white space at the beginning or end.

>>> from .annodoc import AnnoDoc
>>> doc = AnnoDoc('one two three')
>>> original_span = AnnoSpan(3, 8, doc)
>>> original_span.trimmed()
AnnoSpan(4-7, two)
class epitator.annospan.SpanGroup(base_spans, label=None, metadata=None)[source]

Bases: epitator.annospan.AnnoSpan

A AnnoSpan that extends through a group of AnnoSpans.