Skip to content

Peel the #671 credential words off a glued name, except 部長; name_usage answers ends-with for CJK - #712

Merged
derek73 merged 7 commits into
masterfrom
claude/name-usage-script-707-ea608d
Oct 18, 2026
Merged

derek73 merged 7 commits into
masterfrom
claude/name-usage-script-707-ea608d

Conversation

@derek73

@derek73 derek73 commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #707.

What changes

tools/name_usage.py can now answer "does any name END in this word?" for a CJK word. That is the question the glued-honorific peel rests on (rules.md#W2). The Census and SSA rows now say they do not apply to a CJK word, and a new row, Wikidata people, name ends with, gives:

The #671 words peel off a glued name, except 部長/部长. 議員/议员, 国会議員/國會議員, 太平紳士/太平绅士, 医学博士/醫學博士, 二世, 社長/課長 and 社长/课长 join GLUED_HONORIFICS. 部長/部长 stay spaced-only on the 阿部 + 長 argument.

Input 2.4.2 Now
田中社長 family 田中社長 family 田中, suffix 社長
陳怡君二世 (locales.ZH) family 陳, given 怡君二世 family 陳, given 怡君, suffix 二世
エリザベス二世 family エリザベス二世 given エリザベス, suffix 二世
田中部長 family 田中部長 unchanged

How the tool answers it

Live SPARQL can't: STRENDS over every label of a name class timed out at WDQS's 60s limit even with no person join, and WDQS full-text search found 4 family names ending in 殿, matching only where its tokenizer split the character out. So:

  1. Each of eleven name-item classes is listed once, as CSV. The listing is held to a COUNT taken just before it, because 73MB of JSON was cut off mid-stream and CSV has no closing bracket to show a cut. Lexemes, which also carry P31 family name, are skipped.
  2. Labels are fetched by VALUES batch of 1,000 items, keeping CJK-script labels only. Slicing a class by Q-id suffix inside one query doesn't work, because it scans the whole class every time. A batch that overruns is halved. Finished batches are cached, so a stopped build resumes; 429 responses wait out Retry-After.
  3. Matching is local; only the matching items' bearers are counted live.

The first build took 33 minutes: 215,798 labels on 128,695 items, cached outside the repo. Later runs take seconds; --refresh-index rebuilds.

Measurements (2026-10-17)

  • The index is complete relative to Wikidata: it matched live STRENDS exactly on 20 class × word cells (five subclasses × 殿, 子, 郎, 田; the largest cell had 403 items).
  • Positive controls: 子 matches 439 items and 2,436 given-name bearers, 2,081 of them in Japan; the boundary shape 田 + 太郎 counts 22 people.
  • The Can 陳怡君二世 and 田中医学博士 lose their glued credential word? name_usage cannot answer for CJK words #707 words: no name item ends in any of the 15 spellings, except one mislabel: the given name Odo (Q18339792), whose Chinese label is 厄德二世, with 109 Western bearers. Every boundary pair that exists (二+世, 社+長, 社+长, 部+長, 部+长) counts 0 people.
  • The limit is Wikidata's coverage, not the index: 殿 ends 13 name items, where a surname dictionary lists about 90.
  • Corpus moves: the snapshot moved four CLDR renderings and 陳怡君二世, each losing the glued word to the suffix. cldr_agreement gains one agreeing suffix field (二世 醫學博士) and loses none. The JA locale view, run with the ja extra, doesn't move.

Docs

Commits

  1. 5faae975 the tool (its tests pass on their own)
  2. e70b8342 the vocabulary change, case rows, records and docs
  3. 41e0727a merge of master (Ivoi, Paul d' and Zaʿīm, Ḥusnī az-: a particle written after the given name isn't joined to the family #700); AGENTS.md conflict resolved keeping both additions
  4. 05087fe8, 567b9452 the review fixes above
  5. d6531ef7, 45e24510 the PR-review fixes below

PR review (code, tests, silent failures, comments, types)

Fixed in d6531ef7:

  • CI on 3.14/3.15: Python 3.14 warns when an HTTPError is left unclosed, and the 429 retry discarded errors without closing them. The retry loop and the overrun path now close each error. The tool tests pass under 3.14.7 and 3.15.0.
  • False zeros closed:
    • an empty class listing is refused, rather than cached as [];
    • corrupt cache files raise a ValueError that names the file and --refresh-index, rather than a KeyError that took every source's answer down;
    • each batch records the first and last item it covers and is re-fetched when the listing no longer matches;
    • a CSV listing cut mid-line is an error;
    • the character class takes supplementary-plane Han and 〇, and words are NFC-normalized;
    • the cache is versioned, and the old one was rebuilt.
  • Pairing counts: a failed pairing count no longer discards the row's item counts; it fails only that pairing, and the exit status is still 2. Pairings are counted in chunks over distinct people.
  • Role check: NAME_CLASSES roles are checked at import.
  • Tests: added for each fix above, and for the reviewers' coverage gaps (two classes in one build, every cut of a longer word, both edges of the count's slack, 429 exhaustion).
  • Docs: comment and doc corrections. One sentence was made false by this PR's own examples: "the corpora hold no compound office word".

The rebuilt index (215,820 entries) gives the same answers for 殿, every #707 word and the boundary pairs.

Design-docs review

The eleven-axis review ran on 41e0727a and found four doc problems, all fixed:

  • Compound office words split at the new tail (kept as an accepted cost). The vetting asked whether a name ends in each word, never whether a longer unlisted office word does. So 田中 副社長 reads given 副, suffix 社長, and 岸田文雄衆議院議員 reads family 岸田文雄衆議院, suffix 議員; 獣医学博士 and 副課長 split the same way. Before, the whole word stayed in the name, which was no more right. Recorded in rules.md W2 (a second Accepted clause), the Can 陳怡君二世 and 田中医学博士 lose their glued credential word? name_usage cannot answer for CJK words #707 decisions entry and suffixes.py. AGENTS.md's vetting recipe gains the question "does a common longer word end in it?". (567b9452)
  • 部長/部长 added to decisions.md's honorific_tails Excluded block. (05087fe8)
  • The release bullet now says 部長 is read after a comma and under locales.ZH after a listed surname. (05087fe8)
  • usage.rst no longer says no name in Wikidata ends in these words (厄德二世 does). (05087fe8)

🤖 Generated with Claude Code

derek73 and others added 2 commits October 17, 2026 18:54
A glued honorific peels only if no real name ends in it (rules.md#W2),
and the tool could not ask that: its US sources hold no CJK spelling and
its Wikidata arm matches labels exactly. Live SPARQL cannot ask it
either -- STRENDS over a name class's labels runs past WDQS's 60s limit
even with no person join, and full-text search finds a CJK word only
where its tokenizer split it out (4 of the family names ending in 殿).

So the CJK labels of eleven name-item classes are fetched once into the
cache (list each class's items, then their labels by VALUES batch of
1,000; a batch that overruns is halved, and a stopped build resumes),
matched locally, and only the matching items' bearers are counted live.
The new row also counts people whose family name ends in the word's
head and whose given name is its tail (阿部 + 長 for 部長), and shows
each matched item's Q-id so a transcription or mislabel can be traced.

The listing comes as CSV (73MB of JSON was cut off mid-stream) and is
held to a COUNT taken just before it; lexemes, which carry P31 family
name too, are skipped. 429s wait out Retry-After. The Census and SSA
rows now say they do not apply to a CJK word.

Checked against live STRENDS on 20 class x word cells: identical.

Refs #707

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
議員/议员, 国会議員/國會議員, 太平紳士/太平绅士, 医学博士/醫學博士, 二世,
社長/課長 and 社长/课长 join GLUED_HONORIFICS, so 田中社長 reads family
田中, suffix 社長 and 陳怡君二世 gives up 二世. Measured with
tools/name_usage.py's new ends-with row: no Wikidata name item ends in
any of them (二世's one hit is the given name Odo, mislabelled 厄德二世),
and no person pairs a family name ending in the word's head with a
given name equal to its tail.

部長/部长 stay spaced-only: 長 alone is a borne given name, so 阿部長 can
be 阿部 + 長, and the measured zero is a lower bound that does not
refute that.

Snapshot: four CLDR renderings and 陳怡君二世 lose the glued word to the
suffix; cldr_agreement gains one agreeing suffix field and loses none.
The JA locale view, measured with the ja extra, does not move.

Closes #707

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 self-assigned this Oct 18, 2026
@derek73 derek73 added this to the 2.5 milestone Oct 18, 2026
derek73 and others added 3 commits October 17, 2026 19:29
- decisions.md: list 部長/部长 in the honorific_tails Excluded block. Their
  measurement came back zero like the words that shipped, so without the
  entry a sweep of the list would add them; the exclusion rests on the
  阿部 + 長 argument.
- release log: 部長/部长 ARE read after a comma (田中,部長) and under
  locales.ZH after a listed surname (李部長); the bullet said "only as a
  separate word".
- usage.rst: "no name Wikidata records ends in one of them" was false
  (厄德二世, the given name Odo); say they are not known to end a name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The #707 vetting asked whether a NAME ends in each word and never
whether a longer, unlisted office word does. Common ones do, and the
peel matches the end of a token spaced or glued, so 衆議院議員, 副社長,
代表取締役社長 and 獣医学博士 split at the listed tail: 田中 副社長 reads
given 副, suffix 社長. Kept (Derek, 2026-10-17): before, the whole word
stayed in the name, which was no more right.

- rules.md W2: a second Accepted clause with two examples
- decisions.md#W2: the cost in the #707 entry, with the older 박사 case
  (김민준의학박사) it had left unrecorded
- suffixes.py: the cost beside the #707 entries
- AGENTS.md: a third vetting question, "does a common longer word end
  in it?", since the corpora hold no compound and the snapshot is silent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI: since 3.14 an HTTPError left unclosed warns, and the 429 retry
dropped each one; it and the overrun path now close the error.

False zeros and lost reports:
- A class listing no items is refused instead of cached as [], which
  had made every later ends-with row a silent zero.
- Cache files are read through one check: a corrupt or wrongly shaped
  file raises ValueError naming it and --refresh-index (it raised a
  KeyError past _attempt, losing every source's answer). A batch records
  the first and last item it covers and is fetched again when the class's
  listing no longer matches, rather than answering for other items.
- The character class takes supplementary-plane Han (Extension B on)
  and 〇, and drops the Yijing hexagrams; words are NFC-normalized, so
  decomposed hangul reaches the row. The cache carries a version and an
  older one is rebuilt.
- A CSV listing that ends mid-line is cut short, not a shorter Q-id.
- A failed pairing count fails that pairing (Split.error, exit 2)
  instead of discarding the row's item counts; pairings are counted in
  chunks over distinct people, and an empty answer is zero by
  construction rather than a default.
- NAME_CLASSES roles are checked at import; a typo had silently dropped
  a class from the pairing count.
- --refresh-index loads the index for a Latin word too.

Tests for each, plus the reviewers' gaps: two classes in one build,
every cut of a longer word, the count's slack at both edges, 429
exhaustion and date-form Retry-After, a non-429 error, chunked country
sums, 502 and IncompleteRead as overruns, the CSV Accept header.

Docs: the corpora now hold the two compound examples; NAME_CLASSES'
comment matched to the measured overlap; one build time; 長's item is a
Chinese given name; the #671 entry points to #707; index entries, not
labels; usage.rst says how 部長 and compounds read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.03%. Comparing base (8cd815c) to head (45e2451).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #712   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files          46       46           
  Lines        4557     4557           
=======================================
  Hits         4513     4513           
  Misses         44       44           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit 901ab66 into master Oct 18, 2026
12 checks passed
derek73 added a commit that referenced this pull request Oct 18, 2026
Stale whole batches no longer shadow their cached halves; batches are keyed by a digest of their whole membership; a failed --refresh-index is reported for Latin words; HTTPErrors are closed on every path; the CJK class reaches Extension H (INDEX_VERSION 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 deleted the claude/name-usage-script-707-ea608d branch October 18, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can 陳怡君二世 and 田中医学博士 lose their glued credential word? name_usage cannot answer for CJK words

1 participant