(sources: { galaxy?: GalaxyEvidence; texts: readonly string[]; names: readonly string[] })
| 181 | * word, unless it is exactly the selection's own name: "test" went to the model whenever the |
| 182 | * open file contained it (B5). */ |
| 183 | export function knownNames(sources: { galaxy?: GalaxyEvidence; texts: readonly string[]; names: readonly string[] }): (word: string) => boolean { |
| 184 | const words = new Set<string>(); |
| 185 | const add = (text: string) => { for (const word of text.match(/[\p{L}\p{N}_][\p{L}\p{N}_.-]*/gu) ?? []) words.add(word.toLowerCase()); }; |
| 186 | sources.texts.forEach(add); |
| 187 | const lastPart = (name: string) => (name.split(/[/.:]/).filter(Boolean).pop() ?? name).toLowerCase(); |
| 188 | sources.names.forEach(name => { words.add(name.toLowerCase()); words.add(lastPart(name)); }); |
| 189 | const galaxy = sources.galaxy; |
| 190 | if (galaxy) for (const group of [...galaxy.relationships.incoming, ...galaxy.relationships.outgoing]) for (const file of group.files) file.symbols.forEach(symbol => words.add(symbol.name.toLowerCase())); |
| 191 | const own = sources.names.map(name => name.toLowerCase()).filter(name => name.length >= 4); |
| 192 | const ownNames = new Set(sources.names.flatMap(name => [name.toLowerCase(), lastPart(name)])); |
| 193 | return word => { |
| 194 | const lower = word.toLowerCase(); |
| 195 | if (GREETINGS.has(lower)) return ownNames.has(lower); |
| 196 | return words.has(lower) || own.some(name => withinEdits(lower, name, typoBudget(name))); |
| 197 | }; |
| 198 | } |
no test coverage detected