MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getSegmentCoOccurrence

Method getSegmentCoOccurrence

src/db/queries.ts:1120–1145  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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

Calls 5

hasSchemaMethod · 0.95
mapMethod · 0.80
allMethod · 0.65
prepareMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected