Skip to content

feat(people): an organization's sector from a Wikidata domain list - #3350

Merged
leemour merged 2 commits into
mainfrom
feat/organization-categories
Nov 25, 2026
Merged

leemour merged 2 commits into
mainfrom
feat/organization-categories

Conversation

@leemour

@leemour leemour commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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.ts queries the Wikidata SPARQL endpoint (https://query.wikidata.org/sparql), one class after another, and writes src/domain/organization-sectors.generated.ts. Header: CC0 1.0 and the export date (2026-11-25). The file is 358 KB, 25,639 domains:

    sector domains Wikidata items classes (with subclasses unless noted)
    airline 1,695 1,867 Q46970
    bank 3,571 3,796 Q22687
    financial 3,488 7,826 insurance Q2143354, payment provider Q1956140, crypto exchange Q25401607, stock exchange Q11691, financial institution Q650241
    telecom 718 752 Q2401749, Q1941618, ISP Q11371
    social 651 677 Q3220391
    shop 3,754 3,704 Q4382945, Q3390477, Q507619, Q18043413, Q216107; 2+ sitelinks
    delivery 120 126 postal service Q1529128
    news 7,592 9,651 Q1193236, Q11032, Q192283, Q17232649, Q1153191, Q15265344, Q2001305; 3+ sitelinks
    government 4,050 6,039 ministry Q192350, revenue service Q573607, government agency Q327333 (direct instances only); 2+ sitelinks
  • 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 registrableOf reads mail. The User-Agent is WireCat-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 for Retry-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 gets metadata.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 pass companyDomainOf are 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 had mail.ru as social. KIND_RULES goes to 9, so existing stores get the pass on their next list.

  • Exposed: Organization.sector: Sector | null on every organization row the store returns. The organization entity (src/entities/knowledge-lists.ts, also used by organization_context) has sector, nullable. Organization moved next to its mapper in organizations.ts; knowledge.ts re-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 (the organizations doc names metadata.sector), THIRD_PARTY_NOTICES (Wikidata, CC0), a changelog fragment.

Left open:

  • A sector is never cleared. It stays when a later export drops the domain or the organization stops holding it.
  • A pass with no company mail skips the sector step: groupByDomain returns early.
  • The owner cannot set or clear a sector, and memo and Desktop do not show or filter by it yet.
  • DKIM-domain matching (plan) is not built.

Decisions I made (owner asleep):

  • Named sector, not category. Category already exists (src/domain/categories.ts): client / supplier / partner / employer, derived from relationships, and it is organizations({ category })'s filter. One word for two meanings would confuse every caller. Renaming is cheap now if the owner prefers category.
  • Best rank, not preferred only. Preferred-only statements keep 227 of 3,796 banks. Best rank is the preferred statement where one exists, else the normal one.
  • Only home pages. A URL with a path other than / or a language folder is dropped, and so is a host other than the domain itself or www. Without this rule, banks' Facebook pages made facebook.com a bank, YouTube TV made youtube.com news, and blogs made wordpress.com news.
  • A notability floor (Wikipedia sitelinks) for shop, news and government. Without it the file was 1.6 MB and about 90,000 domains, mostly local newspapers. Government agency's subclass tree also pulls in about 50,000 towns, so only its direct instances count.
  • Precedence is the table order, most specific first. A domain claimed by 3 or more sectors is dropped (a conglomerate or a host).
  • UT1 is not included (CC BY-SA). That is left to the owner.

Testing

All runs used --maxWorkers=1.

  • New src/domain/organization-sectors.test.ts: every domain appears once, in lower case, and is registrable.
  • New integration test in src/store/domain-organizations.test.ts:
    • a bot at mail.hsbc.com → organization HSBC with sector: "bank";
    • a company outside the table → null;
    • an organization holding a mail.ru address (free mail) → null. This guards against a later export listing it; today's table does not;
    • a second full pass changes no organizations row.
  • Passed: domain-organizations, knowledge, organization-erase, owner-labels, mail-findings, people-list, sender-bots, people-kinds-stored, crm, records-matching, business-review, areas, mail/score.
    • Some store tests timed out at 15 s on one run. That happened on unchanged main too (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.
  • The 40 test files that read organizations (398 tests) and entities.test.ts passed; the entity samples have sector.
  • pnpm typecheck, pnpm lint (no new warnings), pnpm docs:check, pnpm schema:check.
  • Cost: loading the table takes 4 ms, and building the lookup map on first use takes 13 ms (from dist, Node 24).

🤖 Generated with Claude Code

leemour and others added 2 commits November 25, 2026 06:10
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>
@leemour
leemour merged commit 192f941 into main Nov 25, 2026
39 of 42 checks passed
@leemour
leemour deleted the feat/organization-categories branch November 25, 2026 05:25
leemour added a commit that referenced this pull request Nov 25, 2026
#3350 stores the sector in organization metadata as `sector`, since
`category` already means client, supplier or partner. #3349 made the
throwaway-domain check one prebuilt set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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