Skip to content

Fix 13 wrong REE/INDIUM CHEBI enum groundings - #207

Merged
realmarcin merged 1 commit into
mainfrom
fix/ree-indium-chebi-groundings
Jul 19, 2026
Merged

Fix 13 wrong REE/INDIUM CHEBI enum groundings#207
realmarcin merged 1 commit into
mainfrom
fix/ree-indium-chebi-groundings

Conversation

@realmarcin

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #206 (PALLADIUM). Auditing the full MetalElementEnum +
RareEarthElementEnum (each meaning: id vs its current ChEBI label) found the
palladium bug was not isolated13 more wrong groundings, almost all in
the rare-earth block. The ids had drifted off-by-one within the CHEBI:333xx
lanthanide range, plus a couple of digit transpositions:

enum was resolved to now
INDIUM CHEBI:49464 aluminium trifluoride CHEBI:49664 indium(3+)
LANTHANUM CHEBI:32359 dodecanoyl group CHEBI:49701 lanthanum(3+)
CERIUM CHEBI:32998 (not in build) CHEBI:48782 cerium(3+)
PRASEODYMIUM CHEBI:49648 holmium atom CHEBI:229784 praseodymium(3+)
SAMARIUM CHEBI:33376 terbium atom CHEBI:49890 samarium(3+)
EUROPIUM CHEBI:30688 (not in build) CHEBI:49591 europium(3+)
TERBIUM CHEBI:33374 samarium atom CHEBI:49902 terbium(3+)
DYSPROSIUM CHEBI:49782 (not in build) CHEBI:33377 dysprosium atom¹
HOLMIUM CHEBI:49649 (not in build) CHEBI:49650 holmium(3+)
ERBIUM CHEBI:49650 holmium(3+) CHEBI:33379 erbium¹
THULIUM CHEBI:33377 dysprosium atom CHEBI:33380 thulium atom¹
YTTERBIUM CHEBI:33378 (not in build) CHEBI:49980 ytterbium(3+)
YTTRIUM CHEBI:49976 zinc dichloride CHEBI:49962 yttrium(3+)

¹ ChEBI has no (3+) cation term for Dy/Er/Tm — grounded to the atom, description annotated.

Decision

Ground REEs as the (3+) cation to match every enum description: "X(3+)
cation". This also normalises the four entries that happened to already resolve
(Nd/Gd/Lu/Sc) from the atom form to their cation ids, making the enum internally
consistent.

Why it drifted undetected

Enum meaning: groundings are not covered by validate-products, which only
checks record-level term.{id,label} pairs. The shipped REE records ground via
their own (correct) term pairs — e.g. Ion_Adsorption_REE_Indigenous_Community.yaml
uses CHEBI:33377/CHEBI:49962 — so the KGX export was unaffected; the bug
lived purely in the schema enum + the metal_extraction.py mirror map. Closing
that gate gap (a test validating enum meanings against canonical labels) is logged
as a deferred follow-up in NEXT_TASKS.md §0 item 2.

Changes

  • schema/communitymech.yaml — 13 REE + INDIUM meaning: ids repointed
  • datamodel/communitymech.py — regenerated (just gen-python)
  • metal_extraction.pyREE_CHEBI_MAP + METAL_CHEBI_MAP (INDIUM) mirror
  • NEXT_TASKS.md — finding logged; this fix marked done, guard-test follow-up deferred

Verification

  • Re-audit of both enums vs ChEBI: 0 mismatches
  • linkml-validate on all REE-using records: clean
  • just test — 197 passed

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 19, 2026 02:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…tion)

Auditing MetalElementEnum + RareEarthElementEnum after the PALLADIUM fix
(#206) found 13 more wrong `meaning:` groundings — the ids had drifted off-by-one
within the CHEBI:333xx lanthanide block, plus a couple of digit transpositions
(e.g. INDIUM CHEBI:49464 = aluminium trifluoride; YTTRIUM CHEBI:49976 = zinc
dichloride; SAMARIUM<->TERBIUM and THULIUM<->DYSPROSIUM swaps). Same class of
copy/paste error as PALLADIUM.

Ground every rare-earth element to its (3+) cation, matching each enum
`description:` "X(3+) cation" (this also normalises the previously atom-grounded
Nd/Gd/Lu/Sc to their cation ids). Dy/Er/Tm have no (3+) term in ChEBI, so they
stay atom-grounded with descriptions annotated to say so.

- schema/communitymech.yaml: 13 REE + INDIUM meanings repointed
- datamodel/communitymech.py: regenerated (just gen-python)
- metal_extraction.py: REE_CHEBI_MAP + METAL_CHEBI_MAP (INDIUM) mirror fixed
- NEXT_TASKS.md: log the finding; item 1 (this fix) done, item 2 (a guard test
  validating enum meanings against canonical labels) left deferred

Shipped records ground REEs via their own term.{id,label} pairs and were already
correct, so the KGX export was unaffected; the bug lived in the schema enum + the
mirror map. Re-audit: 0 mismatches. validate-all clean; 197 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@realmarcin
realmarcin force-pushed the fix/ree-indium-chebi-groundings branch from d345f10 to b627208 Compare July 19, 2026 02:49
@realmarcin
realmarcin merged commit a2ad0f5 into main Jul 19, 2026
4 checks passed
@realmarcin
realmarcin deleted the fix/ree-indium-chebi-groundings branch July 19, 2026 03:23
realmarcin added a commit that referenced this pull request Jul 19, 2026
Enum `meaning:` groundings aren't covered by validate-products (which only checks
record-level term.{id,label} pairs), which is why PALLADIUM→promethium (#206) and
13 REE/INDIUM mis-groundings (#207) drifted undetected.

Add tests/test_element_enum_groundings.py, which runs in the validate-strict
pytest step (already a blocking CI gate) with no network:
- freezes the verified meaning: ids for MetalElementEnum + RareEarthElementEnum
  so a bad hand-edit fails;
- asserts no two element PVs share a CHEBI id (catches the swap/dup pattern);
- resolves each id against its canonical ChEBI label (element name must appear),
  but only when the ChEBI sqlite is already cached locally, so it never forces a
  multi-GB download in CI.

Verified the label check flags all three historical bugs (PALLADIUM CHEBI:33373
promethium, INDIUM CHEBI:49464 aluminium trifluoride, YTTRIUM CHEBI:49976 zinc
dichloride). A KB-wide guard over every enum via linkml-term-validator remains
deferred (same no-exceptions blocker as validate-terms-all) — noted in NEXT_TASKS.

201 tests pass (was 197); lint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
realmarcin added a commit that referenced this pull request Jul 19, 2026
… (#208)

Enum `meaning:` groundings aren't covered by validate-products (which only checks
record-level term.{id,label} pairs), which is why PALLADIUM→promethium (#206) and
13 REE/INDIUM mis-groundings (#207) drifted undetected.

Add tests/test_element_enum_groundings.py, which runs in the validate-strict
pytest step (already a blocking CI gate) with no network:
- freezes the verified meaning: ids for MetalElementEnum + RareEarthElementEnum
  so a bad hand-edit fails;
- asserts no two element PVs share a CHEBI id (catches the swap/dup pattern);
- resolves each id against its canonical ChEBI label (element name must appear),
  but only when the ChEBI sqlite is already cached locally, so it never forces a
  multi-GB download in CI.

Verified the label check flags all three historical bugs (PALLADIUM CHEBI:33373
promethium, INDIUM CHEBI:49464 aluminium trifluoride, YTTRIUM CHEBI:49976 zinc
dichloride). A KB-wide guard over every enum via linkml-term-validator remains
deferred (same no-exceptions blocker as validate-terms-all) — noted in NEXT_TASKS.

201 tests pass (was 197); lint clean.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants