Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit ae4eb5b30d1924fac50583cf9c2dc3f8b13f0241
parent 4211b45fc861d64078a9363690ec7904146a2cb9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 15 Oct 2026 17:21:08 -0400

common: the spoken poker numbers, calibrated on the first stream's transcript (read locally, nothing of it committed) — a lone "K" after a number is thousands, ordinals after a tens word ("eighty first") and teen/tens ordinals read as numbers, a buy-in said in dollars and the ASR's "buying is", a prize pool said before its number, the hero's place in the field ("I'm in Nth place", "moved up to Nth") and the field it is out of; a bare "level N" is no longer the blind level (a gaming streamer says "a level eighty character"); a stack, big-blind count or place said as a supposition ("once I'm down to…", "it's not like I'm sitting on…") is left out; a small stack is scaled by an average said up to half an hour away

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/lib/frames/numberWords.test.ts | 6++++++
Mcommon/lib/frames/numberWords.ts | 42++++++++++++++++++++++++++++++++++++------
Mcommon/lib/frames/pokerSpoken.test.ts | 37++++++++++++++++++++++++++++++++++++-
Mcommon/lib/frames/pokerSpoken.ts | 35++++++++++++++++++++++++++++-------
4 files changed, 106 insertions(+), 14 deletions(-)

diff --git a/common/lib/frames/numberWords.test.ts b/common/lib/frames/numberWords.test.ts @@ -21,6 +21,12 @@ const cases: [string, string][] = [ ["level 14, blinds 1,500/3,000 ante 3,000", "level 14, blinds 1500/3000 ante 3000"], ["thousand thousand", "1000 1000"], ["a cat", "a cat"], + ["the average is four hundred twelve K and I have", "the average is 412000 and I have"], + ["sixty k", "60000"], + ["a k of spades", "a k of spades"], + ["I climbed to seventy second", "I climbed to 72"], + ["first place gets the most, third place less", "first place gets the most, third place less"], + ["the fifteenth hand", "the 15 hand"], ]; test("normalizeNumbers: spoken and written numbers become plain digits, the rest is kept", () => { diff --git a/common/lib/frames/numberWords.ts b/common/lib/frames/numberWords.ts @@ -20,6 +20,15 @@ const TENS: Record<string, number> = { twenty: 20, thirty: 30, forty: 40, fourty: 40, fifty: 50, sixty: 60, seventy: 70, eighty: 80, ninety: 90, }; const SCALES: Record<string, number> = { thousand: 1_000, million: 1_000_000, billion: 1_000_000_000 }; +// Ordinals, read as their number: a unit ordinal only after a tens word +// ("eighty first" → 81; "first place" stays words), a teen or tens ordinal +// on its own ("thirteenth", "twentieth"). +const UNIT_ORDINALS: Record<string, number> = { first: 1, second: 2, third: 3, fourth: 4, fifth: 5, sixth: 6, seventh: 7, eighth: 8, ninth: 9 }; +const OWN_ORDINALS: Record<string, number> = { + tenth: 10, eleventh: 11, twelfth: 12, thirteenth: 13, fourteenth: 14, fifteenth: 15, sixteenth: 16, seventeenth: 17, + eighteenth: 18, nineteenth: 19, twentieth: 20, thirtieth: 30, fortieth: 40, fiftieth: 50, sixtieth: 60, seventieth: 70, + eightieth: 80, ninetieth: 90, +}; // A digit token: "2,750", "1.5", "233k", "$5", "10m". The `$` stays outside. const DIGITS = /^(\d{1,3}(?:,\d{3})+|\d+)(?:\.(\d+))?(k|m|mil|bn)?$/i; @@ -38,8 +47,9 @@ function digitValue(w: string): number | null { } // What kind of number word a token is, or null. -function kindOf(w: string): "unit" | "tens" | "hundred" | "scale" | "digits" | null { +function kindOf(w: string): "unit" | "tens" | "hundred" | "scale" | "digits" | "ordinal" | null { if (w in UNITS) return "unit"; + if (w in OWN_ORDINALS) return "ordinal"; if (w in TENS) return "tens"; if (w === "hundred") return "hundred"; if (w in SCALES) return "scale"; @@ -52,7 +62,7 @@ class Acc { total = 0; current = 0; decimal: string | null = null; - last: "unit" | "tens" | "hundred" | "scale" | "digits" | "a" | null = null; + last: "unit" | "tens" | "hundred" | "scale" | "digits" | "a" | "ordinal" | null = null; any = false; // The count before the last "hundred" ("fifteen hundred" → 15). hundredsCount = 0; @@ -62,8 +72,12 @@ class Acc { } // Whether `w` (of kind `k`) continues the number so far. - accepts(k: ReturnType<typeof kindOf> | "a" | "point", w: string): boolean { - if (!this.any) return k !== "point"; + accepts(k: ReturnType<typeof kindOf> | "a" | "point" | "unitOrdinal", w: string): boolean { + if (!this.any) return k !== "point" && k !== "unitOrdinal"; + // An ordinal ends a number. + if (this.last === "ordinal") return false; + if (k === "unitOrdinal") return this.last === "tens"; + if (k === "ordinal") return false; if (this.decimal !== null) return k === "unit" && UNITS[w] <= 9 ? true : k === "scale"; switch (k) { case "unit": @@ -94,8 +108,18 @@ class Acc { return this.scales.length ? Math.min(...this.scales) : 0; } - add(k: NonNullable<ReturnType<typeof kindOf>> | "a" | "point", w: string): void { + add(k: NonNullable<ReturnType<typeof kindOf>> | "a" | "point" | "unitOrdinal", w: string): void { this.any = true; + if (k === "unitOrdinal") { + this.current += UNIT_ORDINALS[w]; + this.last = "ordinal"; + return; + } + if (k === "ordinal") { + this.current += OWN_ORDINALS[w]; + this.last = "ordinal"; + return; + } if (k === "point") { this.decimal = ""; this.last = "unit"; @@ -205,7 +229,7 @@ export function normalizeNumbers(text: string): string { // "three hundred and five": "and" continues a number after hundred/scale. if (toks[n].word === "and" && (acc.last === "hundred" || acc.last === "scale") && n + 2 < toks.length && /^\s+$/.test(toks[n + 1].raw)) n += 2; const w = toks[n].word; - const nk = w === "point" ? "point" : kindOf(w); + const nk = w === "point" ? "point" : w in UNIT_ORDINALS ? "unitOrdinal" : kindOf(w); if (nk && acc.accepts(nk, w) && !splitsBefore(acc, nk, toks, n)) { if (nk === "point") { // "one point five": the point needs a unit after it. @@ -222,6 +246,12 @@ export function normalizeNumbers(text: string): string { // A digit group followed directly by a scale word with no space is not a thing; stop. break; } + // "three hundred eleven K", "50 k": a lone k after a number is thousands. + if (end + 2 < toks.length && /^ +$/.test(toks[end + 1].raw) && toks[end + 2].word === "k" && !/^[A-Za-z']/.test(toks[end + 3]?.raw ?? "")) { + out.push(fmt(acc.value() * 1000)); + i = end + 3; + continue; + } // A lone "oh" or "one" stays a word only when it is plainly not a number: // "oh" alone, never; "one" alone becomes 1 (the patterns need it). const prev = out.length ? (out[out.length - 1].trim() === "" ? out[out.length - 2] ?? "" : out[out.length - 1]).trim().toLowerCase() : ""; diff --git a/common/lib/frames/pokerSpoken.test.ts b/common/lib/frames/pokerSpoken.test.ts @@ -41,7 +41,7 @@ test("stack in big blinds, blinds, level, first prize", () => { const rs = pokerSpoken([ cue(100, "I'm down to six big blinds"), cue(200, "blinds are fifteen hundred three thousand"), - cue(300, "level fourteen"), + cue(300, "we're on level fourteen"), cue(400, "first place five hundred bucks"), ]); assert.deepEqual(pick(rs, "stackBB"), [[100, 6]]); @@ -66,3 +66,38 @@ test("no cues, no readings; the text is kept for a reader", () => { const [r] = pokerSpoken([cue(1, "eighty five players left")]); assert.equal(r.text, "eighty five players left"); }); + +test("calibrated phrasings: a k after a number, a buy-in said in dollars, the ASR's 'buying', a prize pool before its number", () => { + const rs = pokerSpoken([ + cue(10, "the average is four hundred twelve K I have three hundred eight K"), + cue(20, "no it's one thousand one hundred dollars buy in"), + cue(30, "tonight's buying is like four bucks"), + cue(40, "two million dollars in the prize pool"), + ]); + assert.deepEqual(pick(rs, "averageStack"), [[10, 412000]]); + assert.deepEqual(pick(rs, "stack"), [[10, 308000]]); + assert.deepEqual(pick(rs, "buyIn"), [[20, 1100], [30, 4]]); + assert.deepEqual(pick(rs, "prizePool"), [[40, 2000000]]); +}); + +test("the hero's place in the field, and the field it is out of", () => { + const rs = pokerSpoken([cue(10, "I'm in sixty fourth place out of seventy two people"), cue(100, "and I moved up to forty first")]); + assert.deepEqual(pick(rs, "position"), [[10, 64], [100, 41]]); + assert.deepEqual(pick(rs, "playersLeft"), [[10, 72]]); +}); + +test("a stack said as a supposition is not a reading; a bare 'level' of a game is not the blind level", () => { + const rs = pokerSpoken([ + cue(10, "once I'm down to sixty thousand chips I shove"), + cue(20, "it's not like I'm sitting on forty k"), + cue(30, "I'd buy a level sixty character"), + cue(40, "we're at level nine now"), + ]); + assert.deepEqual(pick(rs, "stack"), []); + assert.deepEqual(pick(rs, "level"), [[40, 9]]); +}); + +test("a stack said without 'thousand' is scaled by an average said up to half an hour away", () => { + const rs = pokerSpoken([cue(100, "the average stack is two hundred thousand"), cue(1500, "well I've got one hundred eighty")]); + assert.deepEqual(rs.filter((r) => r.field === "stack").map((r) => [r.value, r.approx]), [[180000, true]]); +}); diff --git a/common/lib/frames/pokerSpoken.ts b/common/lib/frames/pokerSpoken.ts @@ -40,11 +40,12 @@ const N = String.raw`(\d+(?:\.\d+)?)`; const SOFT = String.raw`(?:about |around |like |only |just |roughly |almost |nearly |over |under )?`; // One field's patterns: the first capture group is the value. -type Rule = { field: string; re: RegExp; min?: number; max?: number; scale?: (v: number, m: RegExpExecArray) => number }; +type Rule = { field: string; re: RegExp; min?: number; max?: number }; const RULES: Rule[] = [ { field: "playersLeft", re: new RegExp(String.raw`\b${N} (?:players|people|runners|entrants|left in the field|of us)(?: are)? (?:left|remaining)\b`, "g"), min: 1, max: 1_000_000 }, { field: "playersLeft", re: new RegExp(String.raw`\b(?:down to|we're at|we are at|there are|there's) ${SOFT}${N} (?:players )?(?:left|remaining)\b`, "g"), min: 1, max: 1_000_000 }, + { field: "playersLeft", re: new RegExp(String.raw`\bplace out of ${N} (?:people|players|left)\b`, "g"), min: 1, max: 1_000_000 }, { field: "totalPlayers", re: new RegExp(String.raw`\b${N} (?:entrants|entries|runners|players registered|players total|total players)\b`, "g"), min: 2, max: 1_000_000 }, { field: "averageStack", re: new RegExp(String.raw`\baverage(?: stack| chip stack)?(?: is| was| of|'s)? ${SOFT}${N}\b`, "g"), min: 100 }, // The hero's stack in big blinds: "I'm down to 6 big blinds", "I have 22 bigs". @@ -52,13 +53,28 @@ const RULES: Rule[] = [ // The hero's chips: "I have 233" (said without "thousand" beside an average // said with it: scaled below), "I've got 1500000 chips". { field: "stack", re: new RegExp(String.raw`\b(?:i have|i've got|i got|i'm at|i am at|i'm sitting on|i'm sitting at|my stack is|i'm up to|i'm down to) ${SOFT}${N}(?! (?:big blinds|bigs|bbs|bb|players|people|minutes|seconds|hours|dollars|bucks|percent|hands|cards|outs|times|kings|queens|jacks|aces|tens|nines|eights|sevens|sixes|fives|fours|threes|twos|of)\b)`, "g"), min: 100 }, - { field: "buyIn", re: new RegExp(String.raw`\$?${N} (?:dollar |buck )?buy[- ]?in\b`, "g"), min: 0.01 }, - { field: "buyIn", re: new RegExp(String.raw`\bbuy[- ]?in (?:is|was|of|for) \$?${N}\b`, "g"), min: 0.01 }, + { field: "buyIn", re: new RegExp(String.raw`\$?${N} (?:dollars? |bucks? )?buy[- ]?in\b`, "g"), min: 0.01 }, + // "the buy in is six bucks" — and the ASR's "buying is like five bucks". + { field: "buyIn", re: new RegExp(String.raw`\bbuy(?:[- ]?in|ing) (?:is|was|of|for) ${SOFT}\$?${N}\b`, "g"), min: 0.01 }, { field: "firstPrize", re: new RegExp(String.raw`\bfirst place (?:is |gets |pays |is worth |wins )?\$?${N}\b`, "g"), min: 1 }, - { field: "prizePool", re: new RegExp(String.raw`\b(?:prize pool|guarantee|guaranteed)(?: is| of)? \$?${N}\b`, "g"), min: 1 }, - { field: "level", re: new RegExp(String.raw`\blevel ${N}\b`, "g"), min: 1, max: 200 }, + { field: "prizePool", re: new RegExp(String.raw`\b(?:prize pool|guarantee)(?: is| of) \$?${N}\b`, "g"), min: 1 }, + { field: "prizePool", re: new RegExp(String.raw`\$?${N} (?:dollars? |bucks? )?(?:in the |for the )?(?:prize pool|guaranteed?)\b`, "g"), min: 1 }, + // The blind level, said as poker says it — never a bare "level N" (a + // streamer who games says "a level eighty character" too). + { field: "level", re: new RegExp(String.raw`\b(?:blind level|(?:we're|we are|it's|now|we're now) (?:at |on |in )?level) ${N}\b`, "g"), min: 1, max: 200 }, + { field: "level", re: new RegExp(String.raw`\blevel ${N} (?:blinds|of the tournament)\b`, "g"), min: 1, max: 200 }, + // The hero's place in the field: "I'm in 93rd place", "I moved up to 81st". + { field: "position", re: new RegExp(String.raw`\b(?:i'm|i am) (?:in )?${N}(?:st|nd|rd|th)? place\b`, "g"), min: 1, max: 1_000_000 }, + { field: "position", re: new RegExp(String.raw`\bmoved (?:up|down) to ${N}(?:st|nd|rd|th)?\b(?! (?:chips|big|bb|bbs|thousand|k)\b)`, "g"), min: 1, max: 1_000_000 }, ]; +// The hero's own numbers said as a supposition ("once I'm down to seventy +// thousand", "it's not like I'm sitting on fifty k") are not a reading: a +// stack, big-blind or place match with one of these words just before it in +// the same sentence is left out. +const HERO_FIELDS = new Set(["stack", "stackBB", "position"]); +const SUPPOSING = /\b(?:if|once|when|till|until|unless|by the time|not like|would|could|should|wanna|want to|gonna)\b[^.!?]*$/; + // "blinds are 1500 3000", "blinds 5 10", "1500 3000 blinds": both blinds. const BLINDS = [ new RegExp(String.raw`\bblinds (?:are |at |now |of |going up to |are going up to |up to )?${N}(?: ?/ ?| and | to | )${N}\b`, "g"), @@ -80,6 +96,7 @@ export function pokerSpoken(cues: readonly Cue[]): SpokenReading[] { if (!Number.isFinite(v)) continue; if (rule.min !== undefined && v < rule.min) continue; if (rule.max !== undefined && v > rule.max) continue; + if (HERO_FIELDS.has(rule.field) && SUPPOSING.test(text.slice(Math.max(0, m.index - 40), m.index))) continue; const p = at(m.index); out.push({ t: p.t, field: rule.field, value: v, text: words(p) }); } @@ -112,8 +129,12 @@ function dedupe(rs: SpokenReading[]): SpokenReading[] { return out; } +// The magnitude of the average decides only whether a small stack is +// thousands; a half hour away it still has the right number of digits. +const AVERAGE_WINDOW_S = 1800; + // "the average stack is three hundred seventy three thousand… I have two -// hundred thirty three": a stack said under 1000 within two minutes of an +// hundred thirty three": a stack said under 1000 within half an hour of an // average said in the thousands, and within 50× of it once scaled, is // thousands too (marked `approx`). One still under 1000 with no such average // is left out: a tournament stack is rarely that small, and the number is @@ -126,7 +147,7 @@ function scaleStacks(rs: SpokenReading[]): SpokenReading[] { continue; } const avg = rs - .filter((o) => o.field === "averageStack" && o.value >= 10_000 && Math.abs(o.t - r.t) <= 120) + .filter((o) => o.field === "averageStack" && o.value >= 10_000 && Math.abs(o.t - r.t) <= AVERAGE_WINDOW_S) .sort((a, b) => Math.abs(a.t - r.t) - Math.abs(b.t - r.t))[0]; const scaled = r.value * 1000; if (avg && scaled >= avg.value / 50 && scaled <= avg.value * 50) out.push({ ...r, value: scaled, approx: true });