mostlyright.finance.transcripts.fact_builder
Earnings fact-row builder + fail-closed Kalshi filter.
Assembles schema.finance.fact.v1-shaped rows from STT mention counts (
mostlyright.finance.transcripts.stt.count_mentions()) joined to role-parser
turns (mostlyright.finance.transcripts.role_parser.RoleParser), then
applies the fail-closed Kalshi-count filter.
The two venues resolve the same fact rows through different filters:
- Kalshi counts only occurrences spoken by a transcript-anchored company rep
—
kalshi_counted = validate_kalshi_counted_occurrence(role_source, speaker_role). An un-anchorable occurrence (analyst Q&A, or adiarization_advisoryrole_source) is excluded from the Kalshi count, which costs recall but protects against mis-settlement, and is retained in the rows. - Polymarket counts any speaker: every row contributes to the Polymarket
tally regardless of
kalshi_counted.
The builder is the only place kalshi_counted is set, and it always derives the
value from the canonical schema hook rather than accepting a hand-set one, so a
settlement can never trust a stored boolean the row’s provenance does not support.
Functions
Section titled “Functions”| Function | Description |
|---|---|
apply_kalshi_filter(rows) | Set kalshi_counted on every row via the fail-closed rule. |
build_fact_rows(stt_counts, turns, …[, …]) | Build schema.finance.fact.v1 rows — one per (ticker, call_id, term, occurrence). |
closed_candidate_count(rows) | Sum of mention_count over closed-compound candidate rows. |
kalshi_boolean_settles(rows) | Boolean Kalshi settlement: `sum(mention_count |
polymarket_count(rows) | Polymarket any-speaker auto tally over auto-countable compound types. |
polymarket_threshold_met(rows, threshold_n) | Polymarket "say X N+ times" bracket: auto count >= threshold_n. |
resolve_polymarket_status(rows, threshold_n) | Fail-loud Polymarket resolution over the compound-type axis. |
resolve_status(rows, *, venue[, threshold_n]) | Return a resolution_status for the venue given the counted rows. |
mostlyright.finance.transcripts.fact_builder.apply_kalshi_filter(rows)
Section titled “mostlyright.finance.transcripts.fact_builder.apply_kalshi_filter(rows)”Set kalshi_counted on every row via the fail-closed rule.
kalshi_counted = validate_kalshi_counted_occurrence(role_source, speaker_role) — True only when both the role_source and the speaker_role
are Kalshi-anchorable. Un-anchorable occurrences (analyst Q&A,
diarization_advisory role_source, unknown speaker) get False but
are retained in the returned rows for the Polymarket any-speaker count.
Returns new row dicts and does not mutate the inputs.
mostlyright.finance.transcripts.fact_builder.build_fact_rows(stt_counts, turns, market_terms, , ticker, call_id, event_time=None)
Section titled “mostlyright.finance.transcripts.fact_builder.build_fact_rows(stt_counts, turns, market_terms, , ticker, call_id, event_time=None)”Build schema.finance.fact.v1 rows — one per (ticker, call_id, term, occurrence).
stt_counts is a sequence of per-term occurrence records from the STT
counter, each carrying at minimum term (the canonical market term),
matched_surface_form (the actually-spoken string), and a turn_index
linking the occurrence to the turns list (so its speaker role is known).
Optional per-occurrence keys: offset_seconds, segment, confidence.
turns are role-parser Turn records (index-aligned with the
transcript). market_terms is the per-term market spec carrying
counting_mode, threshold_n, window_scope, term_match_rule,
term_accepted_forms (JSON string), term_canonical — used to populate
the venue-rule fields on each row.
Returns the rows with kalshi_counted already derived via
apply_kalshi_filter() (fail-closed). Every occurrence is retained for
the Polymarket any-speaker count; only kalshi_counted distinguishes the
Kalshi-countable subset.
mostlyright.finance.transcripts.fact_builder.closed_candidate_count(rows)
Section titled “mostlyright.finance.transcripts.fact_builder.closed_candidate_count(rows)”Sum of mention_count over closed-compound candidate rows.
These are not auto-counted for Polymarket, but they could flip an outcome
under Polymarket’s “distinct component” wording, so resolve_status()
raises them for human review rather than settling resolved_no when they
straddle the threshold.
mostlyright.finance.transcripts.fact_builder.kalshi_boolean_settles(rows)
Section titled “mostlyright.finance.transcripts.fact_builder.kalshi_boolean_settles(rows)”Boolean Kalshi settlement: sum(mention_count | kalshi_counted) >= 1.
Only the Kalshi-counted (transcript-anchored company-rep) occurrences whose
compound_type is auto-countable on Kalshi
(standalone/open/hyphenated — KALSHI_AUTOCOUNT_COMPOUND_TYPES)
contribute. A closed compound (wildfire for fire) is Kalshi-No and
never flips a boolean Kalshi market; an affix_derivation counts for
neither venue. This restriction applies on top of the speaker-scope
kalshi_counted gate, which already excludes analyst and un-anchorable
occurrences.
mostlyright.finance.transcripts.fact_builder.polymarket_count(rows)
Section titled “mostlyright.finance.transcripts.fact_builder.polymarket_count(rows)”Polymarket any-speaker auto tally over auto-countable compound types.
Every occurrence counts regardless of kalshi_counted, because Polymarket’s
rule is speaker-blind, but only a compound_type in
POLYMARKET_AUTOCOUNT_COMPOUND_TYPES (standalone/open/
hyphenated) auto-counts in v1. A closed compound is a candidate-only
type, raised for human review by resolve_status() rather than
auto-counted; an affix_derivation counts for neither venue.
mostlyright.finance.transcripts.fact_builder.polymarket_threshold_met(rows, threshold_n)
Section titled “mostlyright.finance.transcripts.fact_builder.polymarket_threshold_met(rows, threshold_n)”Polymarket "say X N+ times" bracket: auto count >= threshold_n.
Uses the auto-countable polymarket_count() (closed candidates excluded).
A closed-candidate straddle is handled by resolve_status() (fail-loud),
not here.
mostlyright.finance.transcripts.fact_builder.resolve_polymarket_status(rows, threshold_n)
Section titled “mostlyright.finance.transcripts.fact_builder.resolve_polymarket_status(rows, threshold_n)”Fail-loud Polymarket resolution over the compound-type axis.
auto >= threshold->"resolved_yes"(closed candidates irrelevant).auto < thresholdbutauto + closed >= threshold-> the closed candidates could flip the outcome, so return the review status (_POLYMARKET_REVIEW_STATUS=="disputed") rather than a silent"resolved_no". A human adjudicates whether the closed compounds count.auto + closed < threshold->"resolved_no"(candidates cannot change the outcome, so no review is needed).
auto is polymarket_count() (standalone/open/hyphenated);
affix_derivation rows count for neither venue and are ignored here.
mostlyright.finance.transcripts.fact_builder.resolve_status(rows, , venue, threshold_n=None)
Section titled “mostlyright.finance.transcripts.fact_builder.resolve_status(rows, , venue, threshold_n=None)”Return a resolution_status for the venue given the counted rows.
venue is "kalshi" (boolean >=1 on Kalshi-counted, auto-countable
compound-type rows) or "polymarket" (delegates to
resolve_polymarket_status() — fail-loud on closed candidates). Returns
"resolved_yes" / "resolved_no" per the venue’s published rules, plus
"disputed" for a Polymarket closed-candidate straddle. When there are no
rows at all it returns "no_qualifying_event".
Kalshi resolution applies the compound-type restriction: a closed-only
mention resolves Kalshi-No.