Map stem → first surface form, preserving first-seen order.
(text: string)
| 20 | |
| 21 | /** Map stem → first surface form, preserving first-seen order. */ |
| 22 | function surfaceByStem(text: string): Map<string, string> { |
| 23 | const m = new Map<string, string>(); |
| 24 | for (const w of tokenize(text)) { |
| 25 | const s = stem(w); |
| 26 | if (!m.has(s)) m.set(s, w); |
| 27 | } |
| 28 | return m; |
| 29 | } |
| 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 { |