* Names whose segments cover at least `minWords` distinct PROMPT WORDS — * the co-occurrence probe behind the prompt hook's medium tier: the words * "state" and "machine" both being segments of `OrderStateMachine` is strong * evidence the prompt names that symbol in prose. Ordered by covera
(
variants: Array<{ segment: string; word: string }>,
minWords: number,
limit: number,
)
| 704 | * the LIMIT on vocab-heavy repos (#1146). |
| 705 | */ |
| 706 | getSegmentCoOccurrence( |
| 707 | variants: Array<{ segment: string; word: string }>, |
| 708 | minWords: number, |
| 709 | limit: number, |
| 710 | ): Array<{ name: string; matches: number }> { |
| 711 | if (variants.length === 0) return []; |
| 712 | const placeholders = variants.map(() => '?').join(', '); |
| 713 | const whens = variants.map(() => 'WHEN ? THEN ?').join(' '); |
| 714 | const rows = this.db |
| 715 | .prepare( |
| 716 | `SELECT name, COUNT(DISTINCT CASE segment ${whens} END) AS matches |
| 717 | FROM name_segment_vocab |
| 718 | WHERE segment IN (${placeholders}) |
| 719 | GROUP BY name |
| 720 | HAVING matches >= ? |
| 721 | ORDER BY matches DESC, length(name) ASC |
| 722 | LIMIT ?`, |
| 723 | ) |
| 724 | .all( |
| 725 | ...variants.flatMap((v) => [v.segment, v.word]), |
| 726 | ...variants.map((v) => v.segment), |
| 727 | minWords, |
| 728 | limit, |
| 729 | ) as Array<{ name: string; matches: number }>; |
| 730 | return rows; |
| 731 | } |
| 732 | |
| 733 | /** How many distinct names each segment appears in — the rarity signal that |
| 734 | * separates a discriminative word ("checkout") from a ubiquitous one ("state"). */ |
no test coverage detected