Skip to content

Truncate Yahoo's security descriptor before Wikidata search#23

Merged
fleveque merged 1 commit into
mainfrom
fix/wikidata-truncate-at-corp-form
May 16, 2026
Merged

Truncate Yahoo's security descriptor before Wikidata search#23
fleveque merged 1 commit into
mainfrom
fix/wikidata-truncate-at-corp-form

Conversation

@fleveque

Copy link
Copy Markdown
Owner

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:

Input Variants returned
`DIAGEO PLC ORD 28 101/108P` as-is → `DIAGEO PLC` → `DIAGEO`
`REPSOL, S.A.` `REPSOL, S.A.` → `REPSOL`
`Apple Inc.` as-is → `Apple`
`Berkshire Hathaway` as-is only

Search tries each in order, stopping at the first hit. Three queries worst case against Wikidata's free API.

Test plan

  • `go test ./internal/provider/` — 11 wikidata tests pass, including new cases for the Yahoo descriptor and the variant generator itself.
  • After deploy, hit DGE.L — expect Wikidata to find Diageo at Q161140 on the bare-name variant. Log: `found logo via Wikidata` with `source=wikidata:Q161140`.

🤖 Generated with Claude Code

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>
@fleveque fleveque merged commit fa3b3e6 into main May 16, 2026
2 checks passed
@fleveque fleveque deleted the fix/wikidata-truncate-at-corp-form branch May 16, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant