fix for NIHVIVO-2685 (mostSpecificType inferred assertions going to the abox graph instead of the inference graph)
This commit is contained in:
parent
9cad90a4c0
commit
a39fbc7850
2 changed files with 36 additions and 28 deletions
|
@ -57,7 +57,6 @@ public class SimpleReasoner extends StatementListener {
|
|||
|
||||
private AnnotationProperty mostSpecificType = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createAnnotationProperty(mostSpecificTypePropertyURI);
|
||||
|
||||
|
||||
/**
|
||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||
* @param aboxModel - input. This model contains asserted ABox statements
|
||||
|
@ -679,8 +678,8 @@ public class SimpleReasoner extends StatementListener {
|
|||
*/
|
||||
public void setMostSpecificTypes(Resource individual, Model inferenceModel) {
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
inferenceModel.enterCriticalSection(Lock.READ);
|
||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||
aboxModel.enterCriticalSection(Lock.READ);
|
||||
tboxModel.enterCriticalSection(Lock.READ);
|
||||
|
||||
try {
|
||||
|
@ -763,12 +762,12 @@ public class SimpleReasoner extends StatementListener {
|
|||
|
||||
public void setMostSpecificTypes(Resource individual, HashSet<String> typeURIs, Model inferenceModel) {
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||
|
||||
try {
|
||||
Model retractions = ModelFactory.createDefaultModel();
|
||||
// remove obsolete most-specific-type assertions
|
||||
StmtIterator iter = aboxModel.listStatements(individual, mostSpecificType, (RDFNode) null);
|
||||
StmtIterator iter = inferenceModel.listStatements(individual, mostSpecificType, (RDFNode) null);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
|
@ -783,7 +782,7 @@ public class SimpleReasoner extends StatementListener {
|
|||
}
|
||||
}
|
||||
|
||||
aboxModel.remove(retractions);
|
||||
inferenceModel.remove(retractions);
|
||||
|
||||
// add new most-specific-type assertions
|
||||
Iterator<String> typeIter = typeURIs.iterator();
|
||||
|
@ -792,12 +791,12 @@ public class SimpleReasoner extends StatementListener {
|
|||
String typeURI = typeIter.next();
|
||||
Resource mstResource = ResourceFactory.createResource(typeURI);
|
||||
|
||||
if (!aboxModel.contains(individual, mostSpecificType, mstResource)) {
|
||||
aboxModel.add(individual, mostSpecificType, mstResource);
|
||||
if (!inferenceModel.contains(individual, mostSpecificType, mstResource)) {
|
||||
inferenceModel.add(individual, mostSpecificType, mstResource);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
inferenceModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -38,7 +38,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
@Before
|
||||
public void suppressErrorOutput() {
|
||||
suppressSyserr();
|
||||
// Turn off log messages to console
|
||||
//Turn off log messages to console
|
||||
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1011,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
aBox.add(ind_x, RDF.type, classD);
|
||||
|
||||
// Verify ind_x mostSpecificType annotation for D
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
|
||||
// Verify ind_x doesn't have a mostSpecificType annotation for
|
||||
// A, Y, C, E or B.
|
||||
|
@ -1023,7 +1023,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
aBox.remove(ind_x, RDF.type, classD); // retract assertion that x is of type D.
|
||||
// Verify that D is not longer the most specific type
|
||||
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertFalse(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1071,9 +1071,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
StmtIterator stmtIterator = aBox.listStatements(ind_x, mostSpecificType, (RDFNode)null);
|
||||
|
||||
// Verify ind_x mostSpecificType annotation for A, B and C
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classA.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classB.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classA.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classB.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1128,16 +1128,16 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
aBox.add(ind_x, RDF.type, OWL_THING);
|
||||
aBox.add(ind_y, RDF.type, classD);
|
||||
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
|
||||
aBox.add(ind_x, RDF.type, classC);
|
||||
aBox.add(ind_y, RDF.type, classF);
|
||||
|
||||
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
|
||||
Assert.assertFalse(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
|
||||
|
||||
// Set up a class hierarchy.
|
||||
// Pellet will compute TBox inferences.
|
||||
|
@ -1151,20 +1151,29 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
classD.addSubClass(classF);
|
||||
classD.addSubClass(classG);
|
||||
|
||||
Assert.assertFalse(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
|
||||
Assert.assertFalse(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
|
||||
|
||||
// If F is removed as a subclass of D, then D should once again be a most specific type
|
||||
// for y.
|
||||
classD.removeSubClass(classF);
|
||||
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||
|
||||
}
|
||||
// To help in debugging the unit test
|
||||
void printModel(OntModel ontModel) {
|
||||
|
||||
System.out.println("\nThe model has " + ontModel.size() + " statements:");
|
||||
System.out.println("---------------------------------------------------");
|
||||
// To help in debugging the unit test
|
||||
void printModel(Model model, String modelName) {
|
||||
|
||||
System.out.println("\nThe " + modelName + " model has " + model.size() + " statements:");
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
model.write(System.out);
|
||||
}
|
||||
|
||||
// To help in debugging the unit test
|
||||
void printModel(OntModel ontModel, String modelName) {
|
||||
|
||||
System.out.println("\nThe " + modelName + " model has " + ontModel.size() + " statements:");
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
ontModel.writeAll(System.out,"N3",null);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue