Skip to content

Commit 7208cb2

Browse files
committed
refactor: improve concept resolution from NidTextRecord
- Add entity type validation using EntityHandle.get() with Optional handling - Handle both ConceptEntity and SemanticEntity cases with proper type checking - Add error handling for semantics not pointing to concepts - Remove incomplete EntityHandle check that was left in code - Keep backward compatibility with existing Entity.getFast() logic
1 parent d86ca70 commit 7208cb2

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

rules/src/main/java/dev/ikm/komet/rules/actions/axiom/ChangeToConceptFromObjectAbstract.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public abstract class ChangeToConceptFromObjectAbstract extends AbstractAxiomAction {
2929

30-
final ConceptFacade conceptFacade;
30+
ConceptFacade conceptFacade;
3131

3232
@SuppressWarnings("removal")
3333
public ChangeToConceptFromObjectAbstract(String text, Object object, AxiomSubjectRecord axiomSubjectRecord, ViewCalculator viewCalculator, EditCoordinate editCoordinate) {
@@ -44,6 +44,20 @@ public ChangeToConceptFromObjectAbstract(String text, Object object, AxiomSubjec
4444
this.conceptFacade = (ConceptFacade) semantic.topEnclosingComponent();
4545
}
4646
case SearchPanelController.NidTextRecord nidTextRecord -> {
47+
48+
EntityHandle.get(nidTextRecord.nid()).ifPresent((Entity<?> entity) -> {
49+
switch (entity) {
50+
case ConceptEntity<?> c -> this.conceptFacade = c;
51+
case SemanticEntity<?> s when EntityHandle.get(s.referencedComponentNid()).isConcept() ->
52+
this.conceptFacade = EntityHandle.get(s.referencedComponentNid()).expectConcept();
53+
case SemanticEntity<?> s -> throw new IllegalStateException("Expecting semantic pointing to a concept. Found: " + entity);
54+
default -> throw new IllegalStateException("Expecting a concept. Found: " + entity);
55+
}
56+
});
57+
58+
EntityHandle entityHandle = EntityHandle.get(nidTextRecord.nid());
59+
if (entityHandle.isConcept())
60+
4761
switch (Entity.getFast(nidTextRecord.nid())) {
4862
case ConceptEntity conceptEntity -> this.conceptFacade = conceptEntity;
4963
case SemanticEntity semanticFacade -> this.conceptFacade = (ConceptFacade) semanticFacade.topEnclosingComponent();

0 commit comments

Comments
 (0)