ductus.base¶
The data model: where a finding lives, what it claims, and how much it weighs.
Four types, and they are the whole contract every other module speaks in.
A Span says where. It carries character offsets and the W3C Web
Annotation redundant selectors (quote, prefix, suffix) so a finding can be
re-anchored after the text is edited, which plain offsets cannot survive.
A Signal is one piece of evidence: a direction, a weight, who produced
it, and a human-readable reason. Signals are never merged or averaged away –
the reason a passage scored the way it did is always recoverable.
A Segment is a unit of text plus the signals that landed on it and the
lean derived from them. A Report is the document-level roll-up.
>>> text = "The cat sat. It was a fine evening."
>>> span = Span.of(text, 4, 7)
>>> span.quote, span.prefix
('cat', 'The ')
>>> Signal("test", "machine", 0.5, "demo", note="an example").direction
'machine'
Module Attributes
Bumped when the serialized shape of a Report changes incompatibly. |
|
What a signal can argue for. |
|
The coarse vocabulary a segment is labelled with. |
Classes
|
Everything a downstream consumer needs, and nothing it has to guess at. |
|
A unit of text, the signals on it, and the lean they add up to. |
|
One piece of evidence about one span. |
|
A character range, with redundant selectors so it survives an edit. |
- ductus.base.DIRECTIONS = ('machine', 'human', 'neutral')¶
What a signal can argue for.
neutralrecords evidence that is real but does not discriminate – it is kept because hiding it would be dishonest.
- ductus.base.LABELS = ('leans-machine', 'leans-human', 'mixed-signals', 'uncertain', 'no-evidence')¶
The coarse vocabulary a segment is labelled with. Deliberately not a percentage: see
docs/why-no-percentage.md.
- class ductus.base.Report(text_sha256, n_chars, document, segments, detectors, segmenter, schema_version='1', calibration='uncalibrated', meta=dict())[source]¶
Bases:
objectEverything a downstream consumer needs, and nothing it has to guess at.
- ductus.base.SCHEMA_VERSION = '1'¶
Bumped when the serialized shape of a Report changes incompatibly.
- class ductus.base.Segment(span, signals=(), lean=0.0, strength=0.0, label='no-evidence')[source]¶
Bases:
objectA unit of text, the signals on it, and the lean they add up to.
leanruns from -1 (every signal argues human) to +1 (every signal argues machine).strengthis how much evidence there is at all – a lean of +1.0 from a single weak signal is not the same claim as +1.0 from six.
- class ductus.base.Signal(name, direction, weight, detector, value=None, note='', span=None)[source]¶
Bases:
objectOne piece of evidence about one span.
weightis how much this moves the needle, in0..1. It is a weight, not a probability: two 0.5 signals pointing the same way are stronger than one, and nothing here claims to be calibrated.>>> Signal("em-dash", "machine", 0.2, "forensic", value=3).name 'em-dash'
- class ductus.base.Span(start, end, quote, prefix='', suffix='', level='segment')[source]¶
Bases:
objectA character range, with redundant selectors so it survives an edit.
Offsets count code points (Python
strindices), not bytes and not UTF-16 units – a JavaScript client must convert after any astral character.start/endare aTextPositionSelector;quotewithprefixandsuffixis aTextQuoteSelector. Keeping both is what lets a viewer re-find a finding after the text around it changed.>>> s = Span.of("one two three", 4, 7, level="sentence") >>> (s.start, s.end, s.quote, s.level) (4, 7, 'two', 'sentence') >>> s.length 3