ductus.segment¶
Cutting a text into the units that get scored – the segmenter= seam.
Two segmenters ship. paragraph is the default because it is the unit a
reader actually perceives as “a part of the text”, and because scores over very
short spans are noise. sentence is there for finer localisation.
Both are pure generators over exact character offsets: a segmenter never copies or normalises the text, so every offset it yields indexes the original.
>>> list(spans_of("One two.\n\nThree four.", "paragraph"))[1].quote
'Three four.'
>>> [s.quote for s in spans_of("A short one. And a second.", "sentence")]
['A short one.', 'And a second.']
Module Attributes
The registry the |
Functions
|
Yield one span per paragraph. |
|
Yield one span per sentence, never crossing a paragraph boundary. |
|
Resolve |
- ductus.segment.SEGMENTERS: dict[str, Callable[[str], Iterator[Span]]] = {'document': <function document_spans>, 'paragraph': <function paragraph_spans>, 'sentence': <function sentence_spans>}¶
The registry the
segmenter=seam resolves names against.
- ductus.segment.paragraph_spans(text)[source]¶
Yield one span per paragraph.
>>> [ (s.start, s.end) for s in paragraph_spans("ab\n\ncd") ] [(0, 2), (4, 6)]