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

View file

@ -555,21 +555,9 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
*/ */
//@Test //@Test
public void mostSpecificTypeTest1() throws InterruptedException { public void mostSpecificTypeTest1() throws InterruptedException {
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // set up tbox. Pellet is reasoning; SimpleReasonerTBoxListener is not being used.
// Pellet will compute TBox inferences
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); 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); AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
OntClass classA = tBox.createClass("http://test.vivo/A"); OntClass classA = tBox.createClass("http://test.vivo/A");
@ -584,10 +572,16 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
classA.addSubClass(classC); classA.addSubClass(classC);
classC.addSubClass(classD); classC.addSubClass(classD);
classC.addSubClass(classE); classC.addSubClass(classE);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { // this will receive the abox inferences
Thread.sleep(delay); 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 // add & remove ABox type statements and verify inferences
Resource a = aBox.createResource("http://test.vivo/a"); 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(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertFalse(inf.contains(c, 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()))); Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
simpleReasonerTBoxListener.setStopRequested();
} }
/* /*