Skip to main content

fair-ly accurate text synonyms for data cleaning

fairly collapses spelling and format variants of FAIR / DataCite metadata field values onto a single canonical form — fairly accurately — so that Univ. of California, Berkeley, University of California-Berkeley and UC Berkeley all become one publisher/affiliation, while genuinely different entities (University of Washington vs Washington University) stay apart.

It packages four cooperating strategies, each earning its place against a real failure mode:

Strategy What it does Guards against
Synonym-lustre embed distinct values (gte-large) → cluster (HDBSCAN) → map each cluster to its most-frequent member spelling/format/punctuation variants
Abbreviation holdout keep acronyms and < 4-char tokens out of clustering ZHAW → Z, LUH → HU over-merges
ROR authority split split a cluster that spans two real institutions using a local ROR dump University of Washington vs Washington University
Identity guard never map a variant to a canonical that drops or adds an identifying word, swaps a place name or number, or leaves only generic words (stopwords, address words, abbreviations and dropped place names don't count) Library & Researcher Information Services -> Library, Hockaday School -> Hotchkiss School, Ohio State -> Iowa State, Columbia University -> University
Geocoding for place fields, geocode and group by (country, city) → "City, Country"; a result counts only when it is a place the text names, in any country the text names Graz merging into Vienna ("city in Austria"), CERN geocoded to Chern, Russia
Controlled vocab for fixed-vocabulary fields (licenses, codes), deterministically fold + alias-resolve to a canonical id CC-BY-SA collapsing into CC-BY-NC — clustering can't tell them apart
Acronym resolution read the definitions authors write ("Bruton tyrosine kinase (BTK)") out of the corpus's own text and map an acronym to its long form only when one meaning dominates BTK and its expansion staying two values; AMP mapped to one of its several meanings

Quality is measured, not assumed: a V-measure harness tunes the clustering threshold per field against a small gold set.

Method background and per-field recommendations: docs/methods.md.

Install

pip install fair-ly-accurate                 # core (cleaners, ROR index, I/O, V-measure math)
pip install "fair-ly-accurate[cluster]"      # + embeddings & HDBSCAN (semantic clustering)
pip install "fair-ly-accurate[geo]"          # + geopy (place geocoding)
pip install "fair-ly-accurate[ror]"          # + requests (faster ROR dump auto-download)
pip install "fair-ly-accurate[all]"          # everything

(The distribution installs as fair-ly-accurate; the import name is fairly: from fairly import Normalizer.)

The heavy ML/geo dependencies are optional extras, so the deterministic cleaners, ROR index and field-path I/O install light.

Quickstart (CLI)

# 0. (once, for institution fields) build a ROR index.
#    --latest auto-downloads the newest ROR v2 dump from Zenodo:
fairly build-ror-index --latest --out ror_index.pickle
#    ...or point at a dump you already have:
fairly build-ror-index --dump v2-ror-data.json --out ror_index.pickle

# 1. tune the threshold for a field against a gold set (variant<TAB>true_canonical)
fairly validate --gold affiliation_gold.tsv --preset affiliation --field affiliation

# 2. build + apply a synonym map to a DataCite-shaped field, with review + ROR split
fairly normalize \
  --input records.jsonl \
  --field-path 'creators[].affiliation[].name' \
  --preset affiliation \
  --ror-index ror_index.pickle \
  --review affiliation_review.tsv \
  --output records.normalized.jsonl

The --field-path understands dotted paths through nested dicts and lists, e.g. publisher.name, fundingReferences[].funderName, subjects[].subject, creators[].affiliation[].name. Tabular inputs use the column name as the path.

Always eyeball the --review TSV before trusting an apply — especially for homogeneous fields like funders, where over-merge is easy. Add --dry-run to build the map and review without writing.

Quickstart (library)

from fairly import Normalizer, get_preset
from fairly.authorities.ror import RorIndex
from fairly.io import collect_counts, read_records, map_values

records = read_records("records.jsonl")
counts  = collect_counts(records, "fundingReferences[].funderName")

norm = Normalizer(get_preset("funderName"), cache_dir=".cache")
smap = norm.build(counts, authority=RorIndex.load("ror_index.pickle"))
smap.write_review("funder_review.tsv", counts)     # review gate

for rec in records:
    map_values(rec, "fundingReferences[].funderName", lambda v: norm.normalize(v, smap))

Text a PDF extraction damaged can be repaired without a model, from the record's own repository text or from a vocabulary of typed words (fairly.repair):

from fairly.repair import repair_from_reference, repair_ligatures, word_counts

repair_from_reference("Analise epidemiologica das fraturas de fragilidade",
                      ["An\u00e1lise epidemiol\u00f3gica das fraturas de fragilidade"])
# 'Análise epidemiológica das fraturas de fragilidade'
vocab = word_counts(deposit_titles_and_descriptions)
repair_ligatures("Federa\ufffdon University", vocab)        # 'Federation University'

Held-out acronyms can be resolved from the corpus itself (fairly.acronyms): authors define an acronym the first time they use it, so titles, abstracts or descriptions are their own acronym lexicon. An acronym with more than one common meaning is left alone:

from fairly.acronyms import count_definitions, acronym_map
from fairly.presets import TERM_CLEANER

defs = count_definitions(abstracts)        # Counter{("BTK", "Bruton tyrosine kinase"): 812, ...}
amap = acronym_map(defs, counts=counts, clean=TERM_CLEANER)
amap.apply("BTK")                          # 'Bruton tyrosine kinase'

TERM_CLEANER is the subject cleaner plus fold_possessive, which turns "Alzheimer's disease" into "Alzheimer disease" (MeSH's form) before anything is embedded. Keep it off organization names: "King's College London" is a name.

The identity guard also works on its own, with place and generic words built from a ROR dump:

from fairly.authorities.ror import identity_words_from_dump
from fairly.identity import changes_identity

place, generic = identity_words_from_dump("v2-ror-data.json")
changes_identity("Ohio State University", "Iowa State University", place, generic)    # True
changes_identity("University of Antwerp, Antwerp, Belgium", "University of Antwerp",
                 place, generic)                                                      # False

Field presets

Built-in FieldConfig presets for common DataCite/FAIR fields (fairly presets):

Field Strategy eps Holdout Authority
publisher semantic 0.30 yes ROR
funderName semantic 0.07 yes ROR
affiliation semantic 0.07 yes ROR
subject semantic 0.10 yes —
rights controlled — — SPDX/CC vocab
geoLocationPlace geocode — — —

These eps values are V-measure validated against the curated gold sets in gold/ — each sits on its field's optimal plateau (funder/subject 1.00, publisher 0.99, affiliation 0.96; rights 0.82, so prefer a controlled vocabulary for licenses). Re-tune for your data with fairly validate — see docs/methods.md for the full sweep and why each field wants a different threshold.

Why these choices

  • Most-frequent canonical gives clean, recognizable labels (the common form wins), with centroid-closeness only breaking ties.
  • Holdout exists because short/all-caps tokens carry too little signal for an embedding to place; left in, they become spurious join keys.
  • Authority split is what lets us cluster aggressively for coverage without paying for it in precision: the embedding proposes merges, ROR/geocoding vetoes the wrong ones.
  • V-measure turns "did we over-merge?" into a number: homogeneity penalizes over-merge (the costly direction), completeness penalizes under-merge.

License

MIT — see LICENSE.

Metadata

Release files for fair-ly-accurate 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fair-ly-accurate 0.7.0
File Size Uploaded Provenance Actions
fair_ly_accurate-0.7.0.tar.gz 86.1 kB With provenance Details for fair_ly_accurate-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fair-ly-accurate 0.7.0
File Interpreter ABI Platform Actions
fair_ly_accurate-0.7.0-py3-none-any.whl Python 3 none any Details for fair_ly_accurate-0.7.0-py3-none-any.whl

Total release size: 147.4 kB

Release files / fair_ly_accurate-0.7.0.tar.gz

Download URL fair_ly_accurate-0.7.0.tar.gz
Size 86.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9f15ca12a221e7b20f84dd906509dc91475cedb84fe8fa2f9c628f3df9bef375
BLAKE2b-256 checksum
How to use checksums
d122e9d1360659f21ea7be3ef354516ec25dcafdd3ee2eedbe017f8604078a6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / fair_ly_accurate-0.7.0-py3-none-any.whl

Download URL fair_ly_accurate-0.7.0-py3-none-any.whl
Size 61.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07e0c32f7346332cf9b3a1454286f5831008954a1ebb8bea22ad7b5a374d6719
BLAKE2b-256 checksum
How to use checksums
b121ce49e5cae114ba06e686c5e523b1d15af90726b7b243e421a9465c915c40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for fair-ly-accurate 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fair_ly_accurate-0.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page