Normalize whitespace + strip corporate suffix in Wikidata search#20
Merged
Conversation
Yesterday's prod log surfaced REP.MC's wikidata miss: "no wikidata entity for \"REPSOL, S.A.\"" Two structural problems with names coming through from Yahoo: - whitespace can be doubled (\"REPSOL, S.A.\") - corporate suffix + uppercasing tank Wikidata's fuzzy match score Live-tested both forms against the Wikidata API: - \"REPSOL, S.A.\" → 0 results - \"REPSOL, S.A.\" → Q174747 (Repsol) - \"Repsol\" → Q174747 (Repsol) So a whitespace collapse alone unblocks Repsol. As a secondary fallback, stripping a known list of corporate suffixes (S.A., Inc., plc, Ltd, AG, GmbH, N.V., Corp., Co., …) catches the cases where the as-is search still misses. Two queries worst case — cheap against Wikidata's free API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2 tasks
fleveque
added a commit
that referenced
this pull request
May 16, 2026
Yesterday's normalization fix (#20) helped REPSOL, but DGE.L's company_name from Yahoo arrived as the full security descriptor: "DIAGEO PLC ORD 28 101/108P" (Diageo plc, Ordinary shares, par value 28 101/108 pence.) My previous suffix-strip only handled trailing corporate forms ("plc" at the END), so it left this string unchanged and Wikidata couldn't match. Replace the two helpers (normalizeWhitespace + stripCorporateSuffix with a single companyNameVariants function that scans for the corporate form as a *word inside* the name and returns up to three search variants in decreasing fidelity: "DIAGEO PLC ORD 28 101/108P" ─► ["DIAGEO PLC ORD 28 101/108P", "DIAGEO PLC", "DIAGEO"] "REPSOL, S.A." ─► ["REPSOL, S.A.", "REPSOL"] "Apple Inc." ─► ["Apple Inc.", "Apple"] "Berkshire Hathaway" ─► ["Berkshire Hathaway"] Search now tries each variant in order, stopping at the first hit. Three Wikidata queries worst case — still cheap against their free API. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Yesterday's prod log (after #19 surfaced the wikidata-miss reason) showed REP.MC failing here:
```
"wikidata provider miss" symbol=REP.MC company_name="REPSOL, S.A."
error="wikidata search: no wikidata entity for "REPSOL, S.A.""
```
Two structural problems with names coming through from Yahoo:
Live-tested against the real Wikidata API:
So a whitespace collapse alone unblocks Repsol. As a secondary fallback, stripping a known list of corporate suffixes (`S.A.`, `Inc.`, `plc`, `Ltd`, `AG`, `GmbH`, `N.V.`, `Corp.`, `Co.`, …) catches the cases where the as-is search still misses.
Two Wikidata queries worst case — cheap against their free API.
Test plan
🤖 Generated with Claude Code