(tf: Map<string, number>)
| 116 | const N = base.length; |
| 117 | const idf = (t: string): number => Math.log((N + 1) / ((df.get(t) ?? 0) + 1)); // smoothed; token in all docs → ~0 |
| 118 | const weight = (tf: Map<string, number>): Map<string, number> => { |
| 119 | const w = new Map<string, number>(); |
| 120 | for (const [t, f] of tf) { const iw = idf(t); if (iw > 0) w.set(t, f * iw); } |
| 121 | return w; |
| 122 | }; |
| 123 | |
| 124 | const prepared = base |
| 125 | // Weighted vector; fall back to raw tf if weighting empties it (degenerate all-tokens-universal case). |
no test coverage detected