Repository navigation
Count a word by box and country in the fielded local corpora - #933
Merged
Merged
Conversation
name_usage.py --boxes adds a row for orcid-researchers and patentsview-inventors: the people whose given box and whose family box write the word, counted over the whole extract rather than the capped corpus, and the countries with the most of them, each as a share of that country's people (the records with no country last; --country CC adds a country, implying --boxes). PatentsView weighs a name by the inventors filing under it, ORCID one holder a record. The counts come from a second index, local_corpora.cached_box_index, built from a Source's new extract and boxes readers and cached as boxindex.json.gz, keyed to the extract's sha256 and a fingerprint of the reader and the fold. Building ORCID's took 2 min 19 s; a lookup with both cached costs about 5 s more than one without, so the rows are asked for. An extract or a cached index that cannot be read fails its row or is built over, never the run. 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.
Summary
PR 2 of the PatentsView plan (#931 added the corpus).
name_usage.py --boxesadds a row for each fielded local corpus whose extract keeps every record uncapped:orcid-researchersandpatentsview-inventors. The row gives:--countries Ncountries with the most of them in each box, each as a share of that country's people, with the records stating no country last;--country CC(repeatable; implies--boxes), listed even outside the top N.PatentsView counts the inventors filing under a name; ORCID counts one holder per record. A country is where they work or live, so the counts describe researchers and US-patent inventors, not a country's population. The docstring and README say so.
For
del(ORCID, 2026-10-28):María del Carmen.So
delis written in the given box more often than the family box in the Spanish-speaking countries, a measurement a Spanish pack's particle rule can start from.How
local_core.Sourcegainsextractandboxes: the extract's path, and a reader yielding (given, family, country, weight).local_orcid.orcid_boxesandlocal_patentsview.pv_boxesread the existing extracts and refuse one of another release.local_corpora.cached_box_indexbuilds aBoxIndex: per country the people in all, and per word and country the people whose box writes it, once per record per box, with the word index's own fold. It is cached asboxindex.json.gzbeside the corpus.box_indexcalls.--boxesagainst 5.3 s without, nearly all of the difference spent reading the two indexes. That's why the rows are opt-in.Review
A code review found five problems, all fixed:
_attemptdoes not catch. It now fails only its row, naming the refresh.zlib.error). It is now rebuilt.--boxes.--countrycould list a country twice. It now drops duplicates and blanks.Negative controls: each of seven behaviours made its test fail when switched off. That includes the once-per-record count, whose first test fixture couldn't detect it and was strengthened.
Notes
--jsonnow carries emptygiven_sharesandfamily_shareson every row (asdict).--boxesis asked.🤖 Generated with Claude Code