Skip to content

Restrict label demotion to chemicals only - #725

Merged
gaurav merged 10 commits into
mainfrom
fix-label-limit
May 18, 2026
Merged

gaurav merged 10 commits into
mainfrom
fix-label-limit

Conversation

@gaurav

@gaurav gaurav commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator

The previous config had a single global demote_labels_longer_than: 25 that applied to every Biolink type. This caused legitimate disease and phenotype labels like "postural orthostatic tachycardia syndrome" and "Failure to thrive" to be dropped in favour of shorter, less informative alternatives from UMLS.

Change demote_labels_longer_than to a per-type dict (same pattern as preferred_name_boost_prefixes). Only biolink:ChemicalEntity: 25 is set, so demotion now applies only to chemicals and their subtypes via ancestor traversal. Types with no entry are never demoted.

Extract the inline label-selection block from write_compendium() into a standalone _select_preferred_label() helper and add unit tests in tests/babel_utils/test_write_compendia.py with regression cases from the linked issues.

Fixes #597, fixes #711, fixes #714, fixes #723.

Also (unrelatedly) adds information about the DuckDB export to CLAUDE.md.

The previous config had a single global `demote_labels_longer_than: 25` that
applied to every Biolink type. This caused legitimate disease and phenotype
labels like "postural orthostatic tachycardia syndrome" and "Failure to thrive"
to be dropped in favour of shorter, less informative alternatives from UMLS.

Change `demote_labels_longer_than` to a per-type dict (same pattern as
`preferred_name_boost_prefixes`). Only `biolink:ChemicalEntity: 25` is set, so
demotion now applies only to chemicals and their subtypes via ancestor traversal.
Types with no entry are never demoted.

Extract the inline label-selection block from `write_compendium()` into a
standalone `_select_preferred_label()` helper and add unit tests in
`tests/babel_utils/test_write_compendia.py` with regression cases from the
linked issues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gaurav added a commit that referenced this pull request Apr 18, 2026
Drives write_compendium() against curated cliques and asserts on the
JSONL output's preferred_name. Covers the regressions fixed in PR #725
(#711, #714, #723) and the chemical demotion path. Tests run offline
by patching bmt.Toolkit to read pinned local Biolink Model files; a
network freshness test fails loudly when the fixture and config.yaml's
biolink_version drift apart.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Base automatically changed from add-pipeline-tests-for-shared-identifiers to master April 27, 2026 05:56
@gaurav gaurav moved this from Backlog to In progress in Babel sprints Apr 28, 2026
@gaurav
gaurav requested a review from Copilot April 30, 2026 02:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Babel’s preferred-label selection to stop globally demoting long labels, restricting length-based demotion to chemicals only (to avoid dropping legitimate long disease/phenotype names).

Changes:

  • Changes demote_labels_longer_than from a global integer to a per-Biolink-type dict (configured only for biolink:ChemicalEntity, applied to chemical subtypes via ancestor traversal).
  • Extracts label selection from write_compendium() into _select_preferred_label() for clearer, testable logic.
  • Adds focused unit tests with regression cases from reported issues and documents the new test module in tests/README.md.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/babel_utils.py Adds _select_preferred_label() and routes write_compendium() label selection through it; reads new per-type demotion config.
config.yaml Replaces scalar demote_labels_longer_than with per-type mapping (only biolink:ChemicalEntity: 25).
tests/babel_utils/test_write_compendia.py New unit tests covering disease/phenotype non-demotion, chemical demotion (including via ancestors), and boost-prefix interaction.
tests/babel_utils/__init__.py Makes tests/babel_utils a package for test organization/imports.
tests/README.md Documents the new babel_utils/ unit test module and what it covers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/babel_utils/test_write_compendia.py Outdated
gaurav and others added 2 commits April 30, 2026 17:49
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Records two architectural facts that are hard to rediscover: the DuckDB
Edge/Clique/Node tables (and the one-line query for clique membership) and
that the per-compendium metadata YAMLs carry aggregate prefix_counts, not
per-CURIE provenance.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@gaurav
gaurav marked this pull request as ready for review May 17, 2026 23:55
gaurav and others added 4 commits May 17, 2026 19:55
- Merge the two separate ancestor-type loops into one pass
- Remove the append loop that tried to add "remaining" labels after
  boost-sorting — sort_identifiers_with_boosted_prefixes already
  returns all identifiers, so the loop was always a no-op
- Replace map(lambda ...) with list comprehensions
- Trim multi-line docstring and step comments (explain WHAT, not WHY)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace hardcoded "biolink:..." strings with named constants from
src/categories.py per project convention. Intermediate ancestor types
that have no constant (DiseaseOrPhenotypicFeature, NamedThing, etc.)
remain as strings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gaurav
gaurav requested a review from Copilot May 18, 2026 00:09
…mment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Comment thread src/babel_utils.py
Comment thread tests/babel_utils/test_write_compendia.py Outdated
Comment thread tests/README.md Outdated
gaurav and others added 2 commits May 17, 2026 23:34
…referred_name

Update module docstring and tests/README.md to match the current function name.
Rename test_chemical_demotion_via_drug_ancestor to clarify it exercises the
within-limit (no-demotion) path, not the demotion path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gaurav
gaurav merged commit b834886 into main May 18, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Babel sprints May 18, 2026
@gaurav
gaurav deleted the fix-label-limit branch May 18, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

2 participants