Repository navigation
feat(people): an organization's sector from a Wikidata domain list - #3350
Merged
Merged
Conversation
An organization holding a company mail domain now gets metadata.sector (airline, bank, financial, telecom, social, shop, delivery, news, government), exposed as Organization.sector on the rows the store returns. The domain table is built into the package: scripts/organization-sectors.ts queries the Wikidata SPARQL endpoint per class at release and writes src/domain/organization-sectors.generated.ts (CC0, 25,639 domains, 358 KB). Nothing is looked up at run time, so no third party learns who writes to the owner. - The rule runs at the end of groupByDomain over every organization that holds a company domain, writes only a changed value, and skips free mail, throwaway mail and sending platforms through companyDomainOf. - KIND_RULES goes to 9 so stores that already exist get the pass once. - Named sector, not category: Category is already client / supplier / partner / employer, what an organization is to the owner. - Organization moves next to its row mapper in organizations.ts; knowledge.ts re-exports it (that file is at the 1,000-line limit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <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.
Task
Contact-kinds plan, "Domain lists" (plan step 5, second half): an organization gets what it does (bank, airline, shop, news, government, …) from a domain list built into the package. Open question 4 is answered with the default: the list is built into the package at release, with no network at run time. Part of #3314.
Why
After #3347, a bank's no-reply bots and mailboxes are one organization, but nothing says it is a bank. Desktop's Bots and Organizations tabs need that for their filter. A lookup per sender (a category API, DNS) would tell a third party who writes to the owner, so the table ships with the package.
What
Data:
scripts/organization-sectors.tsqueries the Wikidata SPARQL endpoint (https://query.wikidata.org/sparql), one class after another, and writessrc/domain/organization-sectors.generated.ts. Header: CC0 1.0 and the export date (2026-11-25). The file is 358 KB, 25,639 domains:Query rules: the official website (P856) at its best rank, no end date (P582), of an item not dissolved (P576). The registrable domain comes from tldts, the same way
registrableOfreads mail. The User-Agent isWireCat-build/1.0 (https://github.com/WireCatLabs/cli-core); the query sends class ids only. Queries run one at a time with 1 s between them, inside the limits the WDQS manual describes (60 s per query, 5 parallel). A 429 waits forRetry-After. A 502/503/504 is tried again, and a timeout splits the query into the class's direct subclasses. A full run takes about 10 minutes.Apply: at the end of
groupByDomain, every organization holding a company domain getsmetadata.sector(the JSON column already exists, so there is no migration and no cli-core: merges into main and release runs — announce here first (continues #849) #3157 reservation). It is written only when the value changes. Only domains that passcompanyDomainOfare looked up, so free mail, throwaway mail and sending platforms never give a sector. None of them is in today's table: an earlier export without the host rule hadmail.ruas social.KIND_RULESgoes to 9, so existing stores get the pass on their next list.Exposed:
Organization.sector: Sector | nullon every organization row the store returns. Theorganizationentity (src/entities/knowledge-lists.ts, also used byorganization_context) hassector, nullable.Organizationmoved next to its mapper inorganizations.ts;knowledge.tsre-exports it because that file is at the 1,000-line lint limit.Docs: ARCHITECTURE (organizations from mail domains), the schema spec and
schema.md(theorganizationsdoc namesmetadata.sector), THIRD_PARTY_NOTICES (Wikidata, CC0), a changelog fragment.Left open:
groupByDomainreturns early.Decisions I made (owner asleep):
sector, notcategory.Categoryalready exists (src/domain/categories.ts): client / supplier / partner / employer, derived from relationships, and it isorganizations({ category })'s filter. One word for two meanings would confuse every caller. Renaming is cheap now if the owner preferscategory./or a language folder is dropped, and so is a host other than the domain itself orwww. Without this rule, banks' Facebook pages madefacebook.coma bank, YouTube TV madeyoutube.comnews, and blogs madewordpress.comnews.Testing
All runs used
--maxWorkers=1.src/domain/organization-sectors.test.ts: every domain appears once, in lower case, and is registrable.src/store/domain-organizations.test.ts:mail.hsbc.com→ organizationHSBCwithsector: "bank";null;mail.ruaddress (free mail) →null. This guards against a later export listing it; today's table does not;organizationsrow.domain-organizations, knowledge, organization-erase, owner-labels, mail-findings, people-list, sender-bots, people-kinds-stored, crm, records-matching, business-review, areas,mail/score.maintoo (crm.test.ts took 30 s on main against 1.4 s on this branch, one after the other), so it was machine load. They passed when run alone.entities.test.tspassed; the entity samples havesector.pnpm typecheck,pnpm lint(no new warnings),pnpm docs:check,pnpm schema:check.dist, Node 24).🤖 Generated with Claude Code