merge for NIHVIVO-3511

This commit is contained in:
stellamit 2011-12-15 17:42:40 +00:00
parent 5966c5e945
commit 77c49f7c65
3 changed files with 69 additions and 19 deletions

View file

@ -450,9 +450,6 @@ public class SimpleReasoner extends StatementListener {
// Returns true if it is entailed by class subsumption that // Returns true if it is entailed by class subsumption that
// subject is of type cls; otherwise returns false. // subject is of type cls; otherwise returns false.
public boolean entailedType(Resource subject, OntClass cls) { public boolean entailedType(Resource subject, OntClass cls) {
//log.debug("subject = " + subject.getURI() + " class = " + cls.getURI());
aboxModel.enterCriticalSection(Lock.READ); aboxModel.enterCriticalSection(Lock.READ);
tboxModel.enterCriticalSection(Lock.READ); tboxModel.enterCriticalSection(Lock.READ);
@ -465,7 +462,7 @@ public class SimpleReasoner extends StatementListener {
while (iter.hasNext()) { while (iter.hasNext()) {
OntClass childClass = iter.next(); OntClass childClass = iter.next();
if (childClass.equals(cls)) break; if (childClass.equals(cls)) continue;
Statement stmt = ResourceFactory.createStatement(subject, RDF.type, childClass); Statement stmt = ResourceFactory.createStatement(subject, RDF.type, childClass);
if (aboxModel.contains(stmt)) return true; if (aboxModel.contains(stmt)) return true;
} }

View file

@ -138,6 +138,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner); SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener); sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener); assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener);
inferencesOms.getTBoxModel().register(simpleReasonerTBoxListener);
log.info("Simple reasoner connected for the ABox"); log.info("Simple reasoner connected for the ABox");

View file

@ -3,8 +3,6 @@
package edu.cornell.mannlib.vitro.webapp.reasoner; package edu.cornell.mannlib.vitro.webapp.reasoner;
import java.util.Iterator;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -483,23 +481,15 @@ public class SimpleReasonerTest extends AbstractTestClass {
simpleReasonerTBoxListener.setStopRequested(); simpleReasonerTBoxListener.setStopRequested();
} }
@Test
/* /*
* Test the removal of a subClassOf statement from * Test the removal of a subClassOf statement from
* the TBox. The instance data that is the basis * the TBox. The instance data that is the basis
* for the inference is in the ABox graph and the * for the inference is in the ABox graph and the
* inference graph. The existing instance of the * inference graph.
* subclass of the newly added subclass should
* be inferred to have the type of the superclass
* of the newly added subclass.
*
* Since the addition of an owl:equivalentClass
* statement is implemented as two calls to the
* method that handles the addition of an
* rdfs:subClassOf statement, this test serves
* as a test of equivalentClass assertions also.
* *
*/ */
@Test
public void removeTBoxSubClassAssertion1() throws InterruptedException { public void removeTBoxSubClassAssertion1() throws InterruptedException {
// Create TBox, ABox and Inference models and register // Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox // the ABox reasoner listeners with the ABox and TBox
@ -594,6 +584,68 @@ public class SimpleReasonerTest extends AbstractTestClass {
simpleReasonerTBoxListener.setStopRequested(); simpleReasonerTBoxListener.setStopRequested();
} }
/*
* Test the removal of a subClassOf statement from
* the TBox. The instance data that is the basis
* for the inference is in the ABox graph and the
* inference graph.
*
*/
//@Test - enable this in 1.5 - will need to add in PelletListener infrastructure
public void removeTBoxSubClassAssertion2() throws InterruptedException {
// Create TBox, ABox and Inference models and register
// the ABox reasoner listeners with the ABox and TBox
// Pellet will compute TBox inferences
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);
// Add classes LivingThing, Flora, Brassica to the TBox
// Brassica is a subClass of Flora and Flora is a subclass of Brassica
OntClass LivingThing = tBox.createClass("http://test.vivo/LivingThing");
LivingThing.setLabel("Living Thing", "en-US");
OntClass Flora = tBox.createClass("http://test.vivo/Flora");
Flora.setLabel("Flora", "en-US");
OntClass Brassica = tBox.createClass("http://test.vivo/Brassica");
Brassica.setLabel("Brassica", "en-US");
LivingThing.addSubClass(Flora);
Flora.addSubClass(Brassica);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay);
}
// Add a statement that individual kale is of type Brassica to the ABox
Resource kale = aBox.createResource("http://test.vivo/kale");
aBox.add(kale, RDF.type, Brassica);
// Remove the statement that Brassica is a subclass of Flora from the TBox
Flora.removeSubClass(Brassica);
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
Thread.sleep(delay);
}
// Verify that "kale is of type Flora" is not in the inference graph
Statement kaleIsFlora = ResourceFactory.createStatement(kale, RDF.type, Flora);
Assert.assertFalse(inf.contains(kaleIsFlora));
// Verify that "kale is of type LivingThing" is not in the inference graph
Statement kaleIsLivingThing = ResourceFactory.createStatement(kale, RDF.type, LivingThing);
Assert.assertFalse(inf.contains(kaleIsLivingThing));
simpleReasonerTBoxListener.setStopRequested();
}
/* /*
* tests rdfs:subPropertyOf materialization for object properties. * tests rdfs:subPropertyOf materialization for object properties.