Token-level Jaccard similarity of two lines (1 = identical token sets).
(a: string, b: string)
| 58 | |
| 59 | /** Token-level Jaccard similarity of two lines (1 = identical token sets). */ |
| 60 | function lineSim(a: string, b: string): number { |
| 61 | const ta = new Set(tokens(a)); |
| 62 | const tb = new Set(tokens(b)); |
| 63 | if (ta.size === 0 && tb.size === 0) return 1; |
| 64 | if (ta.size === 0 || tb.size === 0) return 0; |
| 65 | let inter = 0; |
| 66 | for (const t of ta) if (tb.has(t)) inter++; |
| 67 | return inter / (ta.size + tb.size - inter); |
| 68 | } |
| 69 | |
| 70 | /** Mean similarity between two equal-length line arrays. */ |
| 71 | function blockSim(a: string[], b: string[]): number { |