Skip to content

termIndex: index equivalents and synonyms for readers (NDI-matlab#1332) - #558

Merged
jesshaley merged 3 commits into
V2from
claude/search-resolves-terms
Nov 30, 2026
Merged

jesshaley merged 3 commits into
V2from
claude/search-resolves-terms

Conversation

@jesshaley

Copy link
Copy Markdown
Collaborator

The DID-matlab step of VH-Lab/NDI-matlab#1332 ([entity search resolves a term through the registry], decided by Jess Haley on 2026-11-30 and recorded in did-schema #406). It is paired with an NDI-matlab PR on the same branch name, claude/search-resolves-terms. NDI-matlab's No Cloud workflow picks this DID-matlab branch by that name. Merge order: this PR first, then the NDI-matlab PR (siblings first).

Why

did2.schema.termIndex keys byNode only on each row's own node, and byName only on its own name. It keeps equivalent on each entry, but nothing indexes it. It never reads synonyms at all. NDI's searches need to look a term up by an equivalent node or a synonym. Without this change, NDI would have to parse the registry a second time.

What changed

  • src/did/+did2/+schema/termIndex.m:
    • New map byEquivalent: curieKey(id) for each id in a row's equivalent list.
    • New map bySynonym: termNameKey(s) for each entry in a row's synonyms list.
    • Each entry now also carries synonyms (a cellstr).
    • A row's own node or name always wins: a key already in byNode or byName is not added to the new maps.
  • termRegistered and registeredTerm do not read the new maps, so the writer's rule is unchanged: an equivalent node or a synonym is still not the registered term.
  • tests/+did2/+unittest/testBuildTermRegistry.m: new test testEquivalentsAndSynonymsAreIndexedForAReader, on a registry written in the test (carbogen CHEBI:757169 with equivalent NCIm:CL1445492 and one synonym).
    • Checks: lookup by the equivalent (prefix by key and case) and by the synonym (spacing ignored).
    • Controls:
      • The equivalent is not in byNode and the synonym is not in byName.
      • When another row lists a row's own node as an equivalent, or its name as a synonym, the row's own entry wins.
      • A row with no lists has empty ones.
      • termRegistered still refuses the equivalent node.

This was written without MATLAB (Octave cannot parse arguments blocks), so this PR's runs are the first execution.

Proposed (not decided)

  • When two rows list the same equivalent or synonym, the first row wins. did-schema's check_term_registry does not refuse that today.

Generated by Claude Code

did2.schema.termIndex gains byEquivalent (curieKey of each `equivalent` id)
and bySynonym (termNameKey of each `synonyms` entry), and each registered
term carries `synonyms`. A row's own node or name wins over another row's
equivalent or synonym. termRegistered and registeredTerm do not read the new
maps, so a writer's rule is unchanged.

For VH-Lab/NDI-matlab#1332 ([entity search resolves a term through the
registry], Jess Haley, 2026-11-30): NDI's searches resolve a term through
this index instead of parsing the registry a second time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxKLA8Tbf9cpvDe7fuVeKf
testEquivalentsAndSynonymsAreIndexedForAReader checked 'body midpoint' for
empty lists, but the fixture gives that row CHEBI:15379 and 'dioxygen' on
purpose (the own-row-wins control). Check dioxygen's empty lists instead, and
that body midpoint keeps its own list. The index code was correct.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxKLA8Tbf9cpvDe7fuVeKf
@jesshaley
jesshaley marked this pull request as ready for review November 30, 2026 15:43
@jesshaley
jesshaley merged commit 47c96f4 into V2 Nov 30, 2026
12 checks passed
@jesshaley
jesshaley deleted the claude/search-resolves-terms branch December 2, 2026 17:30
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