Follow-up to my reply above: I landed #387, which adds examples/cleaning_and_detect_spans.py. It demonstrates the full pattern: clean with StreamCleaner, segment the cleaned output, then map every sentence back to spans in the unmodified input via a deterministic index map and (-1, -1) for anything unlocatable. Core will no longer get the offset map. The example covers the annotation/highlighting use case without touching the stable API, and the costs I mentioned earlier aren't worth paying until exactness demand shows up in practice.
Thank you, I’m aware of this. That’s why I deliberately avoided PySBD’s approach of bundling cleaning with the Segmenter class behind a flag. Even PySBD raises an error when both has_span and clean are enabled. I can try exposing an offset map through init by accepting a dict and mutating it as the stream progresses. Returning the map directly would require changing the existing API, which is already stable. For a streaming API, it gets even trickier: the map must remain consistent as new paragraphs arrive, previously processed text is removed from the buffer, and offsets transition between local and absolute coordinate spaces.