(refText: string, otherText: string, cap = 8)
| 30 | |
| 31 | /** Vocabulary diff of `other` against `ref`, compared by stem, displayed as surface words. PURE. */ |
| 32 | export function termDiff(refText: string, otherText: string, cap = 8): TermDiff { |
| 33 | const ref = surfaceByStem(refText); |
| 34 | const other = surfaceByStem(otherText); |
| 35 | const shared: string[] = [], added: string[] = [], missing: string[] = []; |
| 36 | for (const [s, w] of other) (ref.has(s) ? shared : added).push(w); |
| 37 | for (const [s, w] of ref) if (!other.has(s)) missing.push(w); |
| 38 | return { shared: shared.slice(0, cap), added: added.slice(0, cap), missing: missing.slice(0, cap) }; |
| 39 | } |
| 40 | |
| 41 | /** Classic LCS line diff → unified-style lines (' ctx' / '- old' / '+ new'). PURE. */ |
| 42 | export function lineDiff(a: string, b: string): string[] { |
no test coverage detected