Skip to content

Deduplicate TDL_refinement.fit() against TDL via shared template-method hooks - #616

Merged
Demirrr merged 2 commits into
developfrom
worktree-fix-tree-learner-refinement-dup
Aug 10, 2026
Merged

Demirrr merged 2 commits into
developfrom
worktree-fix-tree-learner-refinement-dup

Conversation

@Demirrr

@Demirrr Demirrr commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

  • TDL_refinement.fit() (tree_learner_refinement_inherit.py) copy-pasted most of TDL.fit() (tree_learner.py) — grid search, classifier training, classification reporting, plotting, and final OWL-expression construction — with only the SHAP-based refinement loop spliced in; create_training_data() was likewise a byte-for-byte duplicate.
  • Extracted the shared steps into _maybe_plot_embeddings/_fit_decision_tree/_report_and_plot/_finalize_predictions hooks on the base TDL class; TDL_refinement now inherits create_training_data instead of redefining it, and its refinement loop is factored into its own _refine_features_with_shap method.
  • Side effect: fixes TDL_refinement.classification_report always raising AttributeError — fit() previously set self.__classification_report from within TDL_refinement's own class body, which Python name-mangles to a different attribute than the classification_report property (defined on TDL) reads. Both classes now go through the same _report_and_plot, so they agree on the mangled name. Re-enabled tests/test_tdl_refinement.py::TestTDLTraining::test_classification_report, which had been commented out because of this bug.
  • Prunes the corresponding item from Improvements.md (§2 Code duplication) and adds a CHANGELOG.md entry.

Test plan

  • pytest tests/test_tdl.py tests/test_tdl_refinement.py — 77 passed
  • ruff check ontolearn/learners --exclude ontolearn/learners/spell_kit --line-length=200 — clean
  • python -c "import ontolearn.executor" — sanity import check

🤖 Generated with Claude Code

https://claude.ai/code/session_01H4NxQxE3vqNs2DQBWVaFeM

Demirrr and others added 2 commits August 10, 2026 11:30
…od hooks

TDL_refinement.fit() (tree_learner_refinement_inherit.py) copy-pasted most of
TDL.fit() (tree_learner.py) — grid search, classifier training, classification
reporting, plotting, and final OWL-expression construction — with only the
SHAP-based refinement loop spliced in; create_training_data() was likewise a
byte-for-byte duplicate. Extracted the shared steps into
_maybe_plot_embeddings/_fit_decision_tree/_report_and_plot/_finalize_predictions
hooks on the base TDL class, and TDL_refinement now inherits
create_training_data instead of redefining it.

As a side effect, this fixes TDL_refinement.classification_report always
raising AttributeError: fit() set self.__classification_report from within
TDL_refinement's own class body, which Python name-mangles to a different
attribute than the classification_report property (defined on TDL) reads.
Both classes now go through the same _report_and_plot method, so they agree
on the mangled name. Re-enabled the test that had been commented out because
of this bug.

Prunes the corresponding Improvements.md item and adds a CHANGELOG.md entry.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H4NxQxE3vqNs2DQBWVaFeM
@Demirrr
Demirrr merged commit 0055643 into develop Aug 10, 2026
2 checks passed
@Demirrr
Demirrr deleted the worktree-fix-tree-learner-refinement-dup branch August 10, 2026 11:57
@Demirrr Demirrr mentioned this pull request Oct 16, 2026
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.

1 participant