Skip to content

Add slot() function and hide gating for derived slot bindings#200

Open
amc-corey-cox wants to merge 2 commits intomainfrom
slot-fn-and-hide
Open

Add slot() function and hide gating for derived slot bindings#200
amc-corey-cox wants to merge 2 commits intomainfrom
slot-fn-and-hide

Conversation

@amc-corey-cox
Copy link
Copy Markdown
Contributor

@amc-corey-cox amc-corey-cox commented Apr 9, 2026

Summary

  • Expressions can now call slot('name') to reference previously computed slot values, enabling multi-stage derivations where value_mappings handles declarative lookups and expr handles computation
  • Slots with hide: true are computed (available to downstream slot() calls) but excluded from output
  • Hidden slots skip target-schema post-processing (cardinality coercion, range mapping) since they don't exist in the target schema

Motivation

Without slot(), combining value_mappings with expr is impossible — users are forced to inline everything into case() expressions that are unreadable and structurally irreversible:

# Before: unreadable inline case()
visit_site:
  expr: "case({visit_code} == '1', 'SCREENING', ...) + ' at ' + case({site_code} == 'A', 'Boston', ...)"

# After: declarative lookups + expression composition
_visit_label:
  hide: true
  populated_from: visit_code
  value_mappings:
    "1": "SCREENING"
    "7": "BASELINE"
visit_site:
  expr: "slot('_visit_label') + ' at ' + slot('_site_label')"

Design decisions

  • Insertion order: Slot derivations are evaluated in declaration order. slot() references must appear after the referenced slot. No topological sort — YAML authors naturally write top-to-bottom.
  • Compute-then-filter: All slots (including hidden) are computed into tgt_attrs, then hidden slots are stripped before returning. This keeps slot() uniform regardless of whether the referenced slot is hidden.
  • Injection via functions param: slot is a lambda closing over tgt_attrs, threaded through existing functions plumbing in eval_expr_with_mapping. No changes to Bindings.

Test plan

  • slot() basic: reference a previously derived slot value
  • Hidden slot suppression: hidden slots computed but excluded from output
  • Hidden slot with value_mappings: declarative lookup → slot() reference pattern
  • slot() for missing name returns None
  • Integration test: all features compose correctly
  • Full test suite: 592 passed, no regressions

Closes #164

Expressions can now call slot('name') to reference previously computed
slot values, enabling multi-stage derivations where value_mappings
handles lookups and expr handles computation. Slots with hide: true
are computed but excluded from output, serving as intermediates.

Closes #164
Copilot AI review requested due to automatic review settings April 9, 2026 16:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for referencing previously-derived target slot values during object transformation by introducing a slot('name') expression function, and implements hide: true for slot derivations so intermediate computed slots can be used internally but excluded from output.

Changes:

  • Extend expression evaluation to accept caller-injected functions (used to provide slot()).
  • Evaluate slot derivations in declaration order and support hidden (non-output) derived slots.
  • Add unit/integration tests covering slot() and hidden-slot output suppression.

Reviewed changes

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

File Description
src/linkml_map/transformer/object_transformer.py Injects slot() into expression evaluation, computes hidden slots for downstream use, and strips hidden slots from final output.
src/linkml_map/utils/eval_utils.py Adds optional functions parameter to eval_expr_with_mapping to merge caller functions with built-ins.
tests/test_transformer/test_object_transformer_new.py Adds test scaffolds and assertions for slot() behavior and hide: true output exclusion.

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.

Support derived slot bindings and hide for intermediate computations

2 participants