NIHVIVO-3697 sameAs support in SimpleReasoner

This commit is contained in:
stellamit 2012-06-11 00:19:54 +00:00
parent de081579af
commit 66b12eb4be
2 changed files with 40 additions and 44 deletions

View file

@ -890,29 +890,33 @@ public class SimpleReasoner extends StatementListener {
// subject is of type cls; otherwise returns false.
protected boolean entailedType(Resource subject, OntClass cls) {
List<Resource> sameIndividuals = getSameIndividuals(subject,inferenceModel);
sameIndividuals.add(subject);
tboxModel.enterCriticalSection(Lock.READ);
aboxModel.enterCriticalSection(Lock.READ);
try {
List<OntClass> subclasses = null;
subclasses = (cls.listSubClasses(false)).toList();
subclasses.addAll((cls.listEquivalentClasses()).toList());
aboxModel.enterCriticalSection(Lock.READ);
try {
List<OntClass> subclasses = null;
subclasses = (cls.listSubClasses(false)).toList();
subclasses.addAll((cls.listEquivalentClasses()).toList());
Iterator<OntClass> iter = subclasses.iterator();
while (iter.hasNext()) {
OntClass childClass = iter.next();
if (childClass.equals(cls)) continue;
Statement stmt = ResourceFactory.createStatement(subject, RDF.type, childClass);
if (aboxModel.contains(stmt)) return true;
Iterator<OntClass> iter = subclasses.iterator();
while (iter.hasNext()) {
OntClass childClass = iter.next();
if (childClass.equals(cls)) continue; // TODO - determine whether this is needed
Iterator<Resource> sameIter = sameIndividuals.iterator();
while (sameIter.hasNext()) {
Statement stmt = ResourceFactory.createStatement(sameIter.next(), RDF.type, childClass);
if (aboxModel.contains(stmt))
return true;
}
}
return false;
} finally {
aboxModel.leaveCriticalSection();
}
return false;
} catch (Exception e) {
log.debug("exception in method entailedType: " + e.getMessage());
return false;
} finally {
aboxModel.leaveCriticalSection();
tboxModel.leaveCriticalSection();
}
}

View file

@ -555,21 +555,9 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/
//@Test
public void mostSpecificTypeTest1() throws InterruptedException {
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
// Pellet will compute TBox inferences
// set up tbox. Pellet is reasoning; SimpleReasonerTBoxListener is not being used.
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model inf = ModelFactory.createDefaultModel();
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
aBox.register(simpleReasoner);
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
tBox.register(simpleReasonerTBoxListener);
// Set up the Tbox with a class hierarchy. C is a
// subclass of A. D and E are subclasses C.
// Pellet will compute TBox inferences.
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
OntClass classA = tBox.createClass("http://test.vivo/A");
@ -585,9 +573,15 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
classC.addSubClass(classD);
classC.addSubClass(classE);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay);
}
// this will receive the abox inferences
Model inf = ModelFactory.createDefaultModel();
// abox
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// set up SimpleReasoner and register it with abox
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
aBox.register(simpleReasoner);
// add & remove ABox type statements and verify inferences
Resource a = aBox.createResource("http://test.vivo/a");
@ -636,8 +630,6 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
simpleReasonerTBoxListener.setStopRequested();
}
/*