fix for NIHVIVO-2659 (object of most specific type annotation should be a resource)

This commit is contained in:
stellamit 2011-05-31 19:53:58 +00:00
parent 1613ecdfd0
commit a7a576340f
2 changed files with 30 additions and 32 deletions

View file

@ -12,7 +12,6 @@ import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.AnnotationProperty;
import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
@ -54,7 +53,7 @@ public class SimpleReasoner extends StatementListener {
private static final String bottomObjectPropertyURI = "http://www.w3.org/2002/07/owl#bottomObjectProperty"; private static final String bottomObjectPropertyURI = "http://www.w3.org/2002/07/owl#bottomObjectProperty";
private static final String topDataPropertyURI = "http://www.w3.org/2002/07/owl#topDataProperty"; private static final String topDataPropertyURI = "http://www.w3.org/2002/07/owl#topDataProperty";
private static final String bottomDataPropertyURI = "http://www.w3.org/2002/07/owl#bottomDataProperty"; private static final String bottomDataPropertyURI = "http://www.w3.org/2002/07/owl#bottomDataProperty";
private static final String mostSpecificTypePropertyURI = "http://vivoweb.org/ontology/core#mostSpecificType"; private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
private AnnotationProperty mostSpecificType = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createAnnotationProperty(mostSpecificTypePropertyURI); private AnnotationProperty mostSpecificType = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createAnnotationProperty(mostSpecificTypePropertyURI);
@ -774,12 +773,12 @@ public class SimpleReasoner extends StatementListener {
while (iter.hasNext()) { while (iter.hasNext()) {
Statement stmt = iter.next(); Statement stmt = iter.next();
if ( !stmt.getObject().isLiteral() ) { if ( !stmt.getObject().isResource() ) {
log.warn("The object of this assertion is expected to be a literal: " + stmtString(stmt)); log.warn("The object of this assertion is expected to be a resource: " + stmtString(stmt));
continue; continue;
} }
if (!typeURIs.contains(stmt.getObject().asLiteral().getLexicalForm())) { if (!typeURIs.contains(stmt.getObject().asResource().getURI())) {
retractions.add(stmt); retractions.add(stmt);
} }
} }
@ -791,11 +790,10 @@ public class SimpleReasoner extends StatementListener {
while (typeIter.hasNext()) { while (typeIter.hasNext()) {
String typeURI = typeIter.next(); String typeURI = typeIter.next();
Literal uriLiteral = ResourceFactory.createTypedLiteral(typeURI, XSDDatatype.XSDanyURI); Resource mstResource = ResourceFactory.createResource(typeURI);
if (!aboxModel.contains(individual, mostSpecificType, uriLiteral)) { if (!aboxModel.contains(individual, mostSpecificType, mstResource)) {
Statement toAdd = ResourceFactory.createStatement(individual, mostSpecificType, uriLiteral); aboxModel.add(individual, mostSpecificType, mstResource);
aboxModel.add(individual, mostSpecificType, uriLiteral);
} }
} }
} finally { } finally {

View file

@ -33,7 +33,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
private Resource objectProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#ObjectProperty"); private Resource objectProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#ObjectProperty");
private static final String mostSpecificTypePropertyURI = "http://vivoweb.org/ontology/core#mostSpecificType"; private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
@Before @Before
public void suppressErrorOutput() { public void suppressErrorOutput() {
@ -1011,19 +1011,19 @@ public class SimpleReasonerTest extends AbstractTestClass {
aBox.add(ind_x, RDF.type, classD); aBox.add(ind_x, RDF.type, classD);
// Verify ind_x mostSpecificType annotation for D // Verify ind_x mostSpecificType annotation for D
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
// Verify ind_x doesn't have a mostSpecificType annotation for // Verify ind_x doesn't have a mostSpecificType annotation for
// A, Y, C, E or B. // A, Y, C, E or B.
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classA.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classA.getURI())));
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classY.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classY.getURI())));
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classC.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classE.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classE.getURI())));
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classB.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classB.getURI())));
aBox.remove(ind_x, RDF.type, classD); // retract assertion that x is of type D. 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 // Verify that D is not longer the most specific type
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.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); StmtIterator stmtIterator = aBox.listStatements(ind_x, mostSpecificType, (RDFNode)null);
// Verify ind_x mostSpecificType annotation for A, B and C // Verify ind_x mostSpecificType annotation for A, B and C
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classA.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classA.getURI())));
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classB.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classB.getURI())));
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classC.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.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_x, RDF.type, OWL_THING);
aBox.add(ind_y, RDF.type, classD); aBox.add(ind_y, RDF.type, classD);
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(OWL.Thing.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
aBox.add(ind_x, RDF.type, classC); aBox.add(ind_x, RDF.type, classC);
aBox.add(ind_y, RDF.type, classF); aBox.add(ind_y, RDF.type, classF);
Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(OWL.Thing.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(OWL.Thing.getURI())));
Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createTypedLiteral(classC.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_x, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classF.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI())));
// Set up a class hierarchy. // Set up a class hierarchy.
// Pellet will compute TBox inferences. // Pellet will compute TBox inferences.
@ -1151,17 +1151,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
classD.addSubClass(classF); classD.addSubClass(classF);
classD.addSubClass(classG); classD.addSubClass(classG);
Assert.assertFalse(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertFalse(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classF.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.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 // If F is removed as a subclass of D, then D should once again be a most specific type
// for y. // for y.
classD.removeSubClass(classF); classD.removeSubClass(classF);
Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createTypedLiteral(classD.getURI(), XSDDatatype.XSDanyURI))); Assert.assertTrue(aBox.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
} }
// To help in debugging the unit test // To help in debugging the unit test
void printModels(OntModel ontModel) { void printModel(OntModel ontModel) {
System.out.println("\nThe model has " + ontModel.size() + " statements:"); System.out.println("\nThe model has " + ontModel.size() + " statements:");
System.out.println("---------------------------------------------------"); System.out.println("---------------------------------------------------");