fix(validate): tighten duplicate-detection threshold + refresh stale docs

foundation-validate.ts was flagging 3,181 false-positive duplicate
warnings because it used a flat edit-distance ≤3 over normalized
names. Short normalized names (3-letter acronyms like "bsz" vs
"bsd" — different foundations) sit within distance 1-2 of each
other purely by virtue of being short. Output was unusable for
quality control.

New rule:
- Skip the fuzzy check entirely for normalized names <5 chars
  (acronyms can never be reliably matched by edit distance).
- For names 5-7 chars, require distance ≤1 (catches single-char
  typos but rejects "zusem" vs "rudem"-style false positives).
- For names ≥8 chars, allow distance ≤2.

Result: 3,761 issues → 600. The remaining 321 duplicate warnings
are real candidates including 9 distance=0 pairs that share UIDs
(actual same-foundation entered twice via different naming
conventions: HASLER STIFTUNG vs Hasler Stiftung, Jacobs Foundation
vs Jacobs Stiftung, Stiftung Denk an mich vs Denk an mich, etc.).
These will be merged in a follow-up commit.

Also refreshed CLAUDE.md "Known Issues":
- Removed reference to 4 enrichment scripts deleted in commit 98f3b58
  (enrich-addresses, enrich-contacts-llm, enrich-contacts-spheriq,
  deep-enrich)
- Corrected "6 P3 applicationUrl gaps" → audit shows only 1
  (alice-ackermann); the other 5 were resolved with method='email'
- Replaced obsolete "audit now separates these correctly" note
  with current 65-issue gesuch-audit summary

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.7 committed 2026-04-25 18:10:21 +02:00
1 parent e5384d7b36
commit 4a98076b4b
2 files changed
+27 -17

No files matched your search

+5 -5
View File
@@ -443,11 +443,11 @@ guessed URLs from slugs — 54% were wrong (car garages, restaurants, bands).
- Generated TS file (`stiftungen-generated.ts`) is a second copy of DB data — moving to
server components would eliminate the sync layer (not urgent, but architecturally cleaner)
- 1 P3 truly unreachable (alice-ackermann: phone-only, no appUrl, no email) — audit EMAIL GAPS section
- 6 P3 applicationUrl gaps (structural: no website/defunct/no public access) — audit APPLICATION URL GAPS section
- Many P1-P3 show "missing email" in raw count but ARE reachable via appUrl/online forms — audit now separates these correctly
- Enrichment scripts (`enrich-addresses.ts`, `enrich-contacts-llm.ts`, `enrich-contacts-spheriq.ts`,
`deep-enrich.ts`) write directly to DB without provenance tracking — need staging/review workflow
- 1 P3 truly unreachable (alice-ackermann: phone-only, no appUrl, no email) — also the only
remaining APPLICATION URL gap. Run `npm run audit` for the live list.
- 65 Gesuch documents have data-quality issues per `gesuch-audit` (~30 thin researchNotes
<250 chars, ~10 thin purposeSummary <150 chars, 10 missing email/phone, 5 registry-only
websiteUrl) — needs per-foundation research enrichment, not a code fix
---
+22 -12
View File
@@ -236,19 +236,29 @@ function validateDuplicates(foundations: Foundation[]) {
uids.add(foundation.uid);
}
// Check fuzzy name matches
// Check fuzzy name matches.
// Use a length-aware threshold: short normalized names (3-letter acronyms
// like BSZ, BSD, EHW) have fundamentally low edit distance to each other
// even when they identify completely different foundations, so a flat
// distance ≤3 produced thousands of false positives. Skip names <5 chars
// and tighten the threshold for short-but-reasonable names.
const normalized = normalizeName(foundation.name);
for (const [existingNormalized, existing] of names.entries()) {
const distance = levenshteinDistance(normalized, existingNormalized);
if (distance <= 3) {
addIssue({
slug: foundation.slug,
name: foundation.name,
severity: 'warning',
category: 'duplicate',
message: `Possible duplicate of "${existing.name}" (edit distance: ${distance})`,
fix: 'Verify these are different foundations, or merge if duplicate',
});
if (normalized.length >= 5) {
for (const [existingNormalized, existing] of names.entries()) {
const minLen = Math.min(normalized.length, existingNormalized.length);
if (minLen < 5) continue;
const maxDistance = minLen <= 7 ? 1 : 2;
const distance = levenshteinDistance(normalized, existingNormalized);
if (distance <= maxDistance) {
addIssue({
slug: foundation.slug,
name: foundation.name,
severity: 'warning',
category: 'duplicate',
message: `Possible duplicate of "${existing.name}" (edit distance: ${distance})`,
fix: 'Verify these are different foundations, or merge if duplicate',
});
}
}
}
names.set(normalized, foundation);