Restrict label demotion to chemicals only - #725
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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_thanfrom a global integer to a per-Biolink-type dict (configured only forbiolink: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.
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
marked this pull request as ready for review
May 17, 2026 23: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>
…mment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…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>
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.
The previous config had a single global
demote_labels_longer_than: 25that 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_thanto a per-type dict (same pattern aspreferred_name_boost_prefixes). Onlybiolink:ChemicalEntity: 25is 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 intests/babel_utils/test_write_compendia.pywith 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.