* 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,
)
| 1120 | * the LIMIT on vocab-heavy repos (#1146). |
| 1121 | */ |
| 1122 | getSegmentCoOccurrence( |
| 1123 | variants: Array<{ segment: string; word: string }>, |
| 1124 | minWords: number, |
| 1125 | limit: number, |
| 1126 | ): Array<{ name: string; matches: number }> { |
| 1127 | if (variants.length === 0 || !this.hasSchema('name_segment_vocab')) return []; |
| 1128 | const placeholders = variants.map(() => '?').join(', '); |
| 1129 | const whens = variants.map(() => 'WHEN ? THEN ?').join(' '); |
| 1130 | const rows = this.db |
| 1131 | .prepare( |
| 1132 | `SELECT name, COUNT(DISTINCT CASE segment ${whens} END) AS matches |
| 1133 | FROM name_segment_vocab |
| 1134 | WHERE segment IN (${placeholders}) |
| 1135 | GROUP BY name |
| 1136 | HAVING matches >= ? |
| 1137 | ORDER BY matches DESC, length(name) ASC |
| 1138 | LIMIT ?`, |
| 1139 | ) |
| 1140 | .all( |
| 1141 | ...variants.flatMap((v) => [v.segment, v.word]), |
| 1142 | ...variants.map((v) => v.segment), |
| 1143 | minWords, |
| 1144 | limit, |
| 1145 | ) as Array<{ name: string; matches: number }>; |
| 1146 | return rows; |
| 1147 | } |
| 1148 | |
| 1149 | /** How many distinct names each segment appears in — the rarity signal that |
| 1150 | * separates a discriminative word ("checkout") from a ubiquitous one ("state"). */ |
no test coverage detected