Truncate Yahoo's security descriptor before Wikidata search#23
Merged
Conversation
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.
What just happened
After #22 deployed, REP.MC succeeded via Wikidata (1.2s end-to-end 🎉). DGE.L did not:
```
wikidata provider miss symbol=DGE.L
company_name="DIAGEO PLC ORD 28 101/108P"
error="no wikidata entity for "DIAGEO PLC ORD 28 101/108P""
```
The `company_name` Yahoo returns for DGE.L is the full security descriptor — "Diageo plc, Ordinary shares, par value 28 101/108 pence". My previous strip only peeled trailing suffixes, so it left this string unchanged.
Fix
Replace `normalizeWhitespace` + `stripCorporateSuffix` with a single `companyNameVariants` that scans for the corporate form as a word inside the name and returns up to three search variants in decreasing fidelity:
Search tries each in order, stopping at the first hit. Three queries worst case against Wikidata's free API.
Test plan
🤖 Generated with Claude Code