Reference implementation for the Phoenix Architecture. Work in progress. aicoding.leaflet.pub/
ai coding crazy
at main 50 lines 1.8 kB view raw
1/** 2 * Dedup Eval — tests dedup quality on specs with known near-duplicates. 3 */ 4import { readFileSync } from 'node:fs'; 5import { resolve } from 'node:path'; 6import { parseSpec } from '../src/spec-parser.js'; 7import { extractCanonicalNodes } from '../src/canonicalizer.js'; 8import { GOLD_SPECS } from '../tests/eval/gold-standard.js'; 9 10const ROOT = resolve(import.meta.dirname, '..'); 11 12let totalNodes = 0; 13let totalUniqueStatements = 0; 14 15console.log('Dedup Quality Eval\n'); 16 17for (const spec of GOLD_SPECS) { 18 const text = readFileSync(resolve(ROOT, spec.path), 'utf8'); 19 const clauses = parseSpec(text, spec.docId); 20 const nodes = extractCanonicalNodes(clauses); 21 22 // Check for near-duplicate statements 23 const stmts = nodes.map(n => n.statement.toLowerCase().trim()); 24 const unique = new Set(stmts); 25 const exactDupes = stmts.length - unique.size; 26 27 // Check for high-similarity pairs (token Jaccard > 0.6) 28 let nearDupes = 0; 29 for (let i = 0; i < stmts.length; i++) { 30 for (let j = i + 1; j < stmts.length; j++) { 31 const a = new Set(stmts[i].split(/\s+/)); 32 const b = new Set(stmts[j].split(/\s+/)); 33 let shared = 0; 34 for (const t of a) if (b.has(t)) shared++; 35 const jaccard = shared / (a.size + b.size - shared); 36 if (jaccard > 0.6) nearDupes++; 37 } 38 } 39 40 totalNodes += stmts.length; 41 totalUniqueStatements += unique.size; 42 43 if (exactDupes > 0 || nearDupes > 0) { 44 console.log(` ${spec.name}: ${stmts.length} nodes, ${exactDupes} exact dupes, ${nearDupes} near-dupes (Jaccard>0.6)`); 45 } 46} 47 48const dedupRate = totalNodes > 0 ? (1 - totalUniqueStatements / totalNodes) * 100 : 0; 49console.log(`\nTotal: ${totalNodes} nodes, ${totalUniqueStatements} unique, dedup rate: ${dedupRate.toFixed(1)}%`); 50console.log(`val_score=${(1 - dedupRate/100).toFixed(4)}`);