From 80c2ad77d5a82e05c6151f8c153572037282fbf8 Mon Sep 17 00:00:00 2001
From: mmopitz <45235611+mmopitz@users.noreply.github.com>
Date: Sun, 6 Oct 2024 13:57:44 +0200
Subject: [PATCH] sort of data-/objectproperty assertion axioms (#1235)
This commit addresses the sorting of data-/object-propertyAssertion in the individual views.
Analogous to the sorting of classAssertionAxioms the assertions are sorted in following order
1. inferred/not inferred
2. the 'displayName' of the property (using the owlObjectComparator)
3. the 'displayName' of the object (using the owlObjectComparator)
Sorting is added to the following sections:
* dataPropertyAssertionAxioms
* objectPropertyAssertionAxioms
* negativeDataPropertyAssertionAxioms
* negativeObjectPropertyAssertionAxioms
---
.../ui/OWLPropertyAssertionRowComparator.java | 42 ++++++++
...ataPropertyAssertionAxiomFrameSection.java | 3 +-
...tiveDataPropertyAssertionFrameSection.java | 3 +-
...veObjectPropertyAssertionFrameSection.java | 3 +-
...ectPropertyAssertionAxiomFrameSection.java | 3 +-
...opertyAssertionRowComparator_TestCase.java | 95 +++++++++++++++++++
6 files changed, 145 insertions(+), 4 deletions(-)
create mode 100644 protege-editor-owl/src/main/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator.java
create mode 100644 protege-editor-owl/src/test/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator_TestCase.java
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator.java
new file mode 100644
index 000000000..3dfd47579
--- /dev/null
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator.java
@@ -0,0 +1,42 @@
+package org.protege.editor.owl.ui;
+
+import org.protege.editor.owl.ui.frame.OWLFrameSectionRow;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLObject;
+import org.semanticweb.owlapi.model.OWLPropertyAssertionAxiom;
+
+import java.util.Comparator;
+
+/**
+ * Compares rows of type {@link OWLPropertyAssertionAxiom}.
+ * Comparison priority is as follows:
+ * inference > property > object
+ *
+ * Author: Michael Opitz
+ * https://github.com/mmopitz
+ * Date: 30-Sep-2024
+ */
+public class OWLPropertyAssertionRowComparator, PAIR> implements
+ Comparator> {
+ private final Comparator delegate;
+
+ public OWLPropertyAssertionRowComparator(Comparator delegate) {
+ this.delegate = delegate;
+ }
+
+
+ @Override
+ public int compare(OWLFrameSectionRow o1, OWLFrameSectionRow o2) {
+ if (o1.isInferred() && !o2.isInferred()) {
+ return 1;
+ }
+ else if (o2.isInferred() && !o1.isInferred()) {
+ return -1;
+ }
+ int comparison = delegate.compare(o1.getAxiom().getProperty(), o2.getAxiom().getProperty());
+ if (comparison != 0) {
+ return comparison;
+ }
+ return delegate.compare(o1.getAxiom().getObject(), o2.getAxiom().getObject());
+ }
+}
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLDataPropertyAssertionAxiomFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLDataPropertyAssertionAxiomFrameSection.java
index d1b0ff072..4cfccda20 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLDataPropertyAssertionAxiomFrameSection.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLDataPropertyAssertionAxiomFrameSection.java
@@ -2,6 +2,7 @@
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.model.inference.ReasonerPreferences.OptionalInferenceTask;
+import org.protege.editor.owl.ui.OWLPropertyAssertionRowComparator;
import org.protege.editor.owl.ui.editor.OWLDataPropertyRelationshipEditor;
import org.protege.editor.owl.ui.editor.OWLObjectEditor;
import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection;
@@ -106,7 +107,7 @@ public OWLObjectEditor getObjectEditor() {
* or null
if the rows shouldn't be sorted.
*/
public Comparator> getRowComparator() {
- return null;
+ return new OWLPropertyAssertionRowComparator<>(getOWLModelManager().getOWLObjectComparator());
}
@Override
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeDataPropertyAssertionFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeDataPropertyAssertionFrameSection.java
index 6e2383098..c49e98912 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeDataPropertyAssertionFrameSection.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeDataPropertyAssertionFrameSection.java
@@ -1,6 +1,7 @@
package org.protege.editor.owl.ui.frame.individual;
import org.protege.editor.owl.OWLEditorKit;
+import org.protege.editor.owl.ui.OWLPropertyAssertionRowComparator;
import org.protege.editor.owl.ui.editor.OWLDataPropertyRelationshipEditor;
import org.protege.editor.owl.ui.editor.OWLObjectEditor;
import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection;
@@ -73,7 +74,7 @@ public OWLObjectEditor getObjectEditor() {
* or null
if the rows shouldn't be sorted.
*/
public Comparator> getRowComparator() {
- return null;
+ return new OWLPropertyAssertionRowComparator<>(getOWLModelManager().getOWLObjectComparator());
}
@Override
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeObjectPropertyAssertionFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeObjectPropertyAssertionFrameSection.java
index ce8c07186..cd14b8750 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeObjectPropertyAssertionFrameSection.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLNegativeObjectPropertyAssertionFrameSection.java
@@ -1,6 +1,7 @@
package org.protege.editor.owl.ui.frame.individual;
import org.protege.editor.owl.OWLEditorKit;
+import org.protege.editor.owl.ui.OWLPropertyAssertionRowComparator;
import org.protege.editor.owl.ui.editor.OWLObjectEditor;
import org.protege.editor.owl.ui.editor.OWLObjectPropertyIndividualPairEditor2;
import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection;
@@ -70,7 +71,7 @@ public OWLObjectEditor getObjectEditor() {
* or null
if the rows shouldn't be sorted.
*/
public Comparator> getRowComparator() {
- return null;
+ return new OWLPropertyAssertionRowComparator<>(getOWLModelManager().getOWLObjectComparator());
}
@Override
diff --git a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLObjectPropertyAssertionAxiomFrameSection.java b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLObjectPropertyAssertionAxiomFrameSection.java
index 790b63fae..98d874633 100644
--- a/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLObjectPropertyAssertionAxiomFrameSection.java
+++ b/protege-editor-owl/src/main/java/org/protege/editor/owl/ui/frame/individual/OWLObjectPropertyAssertionAxiomFrameSection.java
@@ -2,6 +2,7 @@
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.model.inference.ReasonerPreferences.OptionalInferenceTask;
+import org.protege.editor.owl.ui.OWLPropertyAssertionRowComparator;
import org.protege.editor.owl.ui.editor.OWLObjectEditor;
import org.protege.editor.owl.ui.editor.OWLObjectPropertyIndividualPairEditor2;
import org.protege.editor.owl.ui.frame.AbstractOWLFrameSection;
@@ -106,7 +107,7 @@ public OWLObjectEditor getObjectEditor() {
* or null
if the rows shouldn't be sorted.
*/
public Comparator> getRowComparator() {
- return null;
+ return new OWLPropertyAssertionRowComparator<>(getOWLModelManager().getOWLObjectComparator());
}
@Override
diff --git a/protege-editor-owl/src/test/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator_TestCase.java b/protege-editor-owl/src/test/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator_TestCase.java
new file mode 100644
index 000000000..ee57746b3
--- /dev/null
+++ b/protege-editor-owl/src/test/java/org/protege/editor/owl/ui/OWLPropertyAssertionRowComparator_TestCase.java
@@ -0,0 +1,95 @@
+package org.protege.editor.owl.ui;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.protege.editor.owl.ui.frame.OWLFrameSectionRow;
+import org.semanticweb.owlapi.model.*;
+
+import java.util.Comparator;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class OWLPropertyAssertionRowComparator_TestCase {
+
+ @Mock
+ Comparator delegate;
+ @Mock
+ OWLFrameSectionRow o1;
+ @Mock
+ OWLFrameSectionRow o2;
+ @Mock
+ OWLObjectPropertyAssertionAxiom opa1;
+ @Mock
+ OWLObjectPropertyAssertionAxiom opa2;
+ @Mock
+ OWLObjectProperty op1;
+ @Mock
+ OWLObjectProperty op2;
+ @Mock
+ OWLIndividual i1;
+ @Mock
+ OWLIndividual i2;
+
+ OWLPropertyAssertionRowComparator comparator;
+
+ @Before
+ public void setUp() {
+ comparator = new OWLPropertyAssertionRowComparator<>(delegate);
+ }
+
+ @Test
+ public void testInferred1() {
+ when(o1.isInferred()).thenReturn(true);
+ when(o2.isInferred()).thenReturn(false);
+ assertEquals(1, comparator.compare(o1, o2));
+ }
+
+ @Test
+ public void testInferred2() {
+ when(o1.isInferred()).thenReturn(false);
+ when(o2.isInferred()).thenReturn(true);
+ assertEquals(-1, comparator.compare(o1, o2));
+ }
+
+ @Test
+ public void testDifferentProperty() {
+ when(o1.getAxiom()).thenReturn(opa1);
+ when(o2.getAxiom()).thenReturn(opa2);
+ when(opa1.getProperty()).thenReturn(op1);
+ when(opa2.getProperty()).thenReturn(op2);
+ when(delegate.compare(op1, op2)).thenReturn(-2);
+ assertEquals(-2, comparator.compare(o1, o2));
+ }
+
+ @Test
+ public void testDifferentIndividuals() {
+ when(o1.getAxiom()).thenReturn(opa1);
+ when(o2.getAxiom()).thenReturn(opa2);
+ when(opa1.getProperty()).thenReturn(op1);
+ when(opa2.getProperty()).thenReturn(op2);
+ when(opa1.getObject()).thenReturn(i1);
+ when(opa2.getObject()).thenReturn(i2);
+ when(delegate.compare(op1, op2)).thenReturn(0);
+ when(delegate.compare(i1, i2)).thenReturn(-2);
+ assertEquals(-2, comparator.compare(o1, o2));
+ }
+
+ @Test
+ public void testSame() {
+ when(o1.getAxiom()).thenReturn(opa1);
+ when(o2.getAxiom()).thenReturn(opa2);
+ when(opa1.getProperty()).thenReturn(op1);
+ when(opa2.getProperty()).thenReturn(op2);
+ when(opa1.getObject()).thenReturn(i1);
+ when(opa2.getObject()).thenReturn(i2);
+ when(delegate.compare(op1, op2)).thenReturn(0);
+ when(delegate.compare(i1, i2)).thenReturn(0);
+ assertEquals(0, comparator.compare(o1, o2));
+ }
+
+}
\ No newline at end of file