Skip to content

lookup(): trim the prefix and remainder as MATLAB does - #17

Merged
stevevanhooser merged 1 commit into
mainfrom
claude/lookup-trim-remainder
Oct 21, 2026
Merged

stevevanhooser merged 1 commit into
mainfrom
claude/lookup-trim-remainder

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

getOntologyNameFromPrefix (ontology.m:493, read at ndi-ontology-matlab 44efcec) trims both halves of the lookup string. It does this before it maps the prefix and before it calls lookupTermOrID.

Python did neither:

  • It matched the prefix untrimmed.
  • It passed the remainder to the provider untrimmed.

As a result, CL: 0000540, CL:0000540 and NDIC :8 failed in Python but resolved in MATLAB. This affects every provider.

Change

  • lookup() now trims both parts right after the split.
  • result.prefix = prefix.strip() becomes result.prefix = prefix, since the prefix is already trimmed.
  • The cache is still keyed on the string as typed, which is what MATLAB does.
  • The bridge lookup entry records the fix. Its sync hash is unchanged because I examined only this path of ontology.m, not the whole file.

Tests

  • Two new tests:
    • The provider receives the trimmed remainder (mocked).
    • Four whitespace variants of NDIC:8 resolve, with no network needed.
  • All five cases failed before the change and pass after it.
  • black, ruff and pytest -m "not live" pass: 171 passed.

Generated by Claude Code

getOntologyNameFromPrefix (ontology.m:493) strtrims both halves of the
lookup string before mapping the prefix and calling lookupTermOrID.
Python matched the untrimmed prefix and passed the untrimmed remainder,
so 'CL: 0000540' and ' CL:0000540' failed in Python and resolved in
MATLAB. The cache stays keyed on the string as typed, as MATLAB's is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UaMQ8AiBeK9Bj7tZ7U1CS2
@stevevanhooser
stevevanhooser merged commit a6e44de into main Oct 21, 2026
6 checks passed
@stevevanhooser
stevevanhooser deleted the claude/lookup-trim-remainder branch October 21, 2026 17:20
stevevanhooser pushed a commit that referenced this pull request Oct 21, 2026
…ed helpers

main brought #14 (EMPTY), #15 (NCIT codes by obo_id), #17 (lookup
trimming, the same fix as this branch's) and #18 (known_gaps).

#15's NCITProvider.lookup_term called OLSProvider._search_ols, which this
branch replaces; git merged it cleanly, and every NCIT lookup would have
raised AttributeError. It now does what NCIT.m does on the ported
helpers: preprocessLookupInput, then searchOLSAndPerformIRILookup on
obo_id for ['NCIT:', search_query]. Its tests move to FakeOLS, plus one
for the prefixed and numeric forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017iFBFMQmEZaz21d9ZFJbiH
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