[VIVO-1394] Make AboxRecomputer deal with inferred types correctly
This commit is contained in:
parent
d737f86084
commit
fcc476a237
2 changed files with 23 additions and 15 deletions
|
@ -218,15 +218,11 @@ public class ABoxRecomputer {
|
||||||
Model assertions = getAssertions(individualURI);
|
Model assertions = getAssertions(individualURI);
|
||||||
log.debug((System.currentTimeMillis() - start) + " ms to get assertions.");
|
log.debug((System.currentTimeMillis() - start) + " ms to get assertions.");
|
||||||
long prevRebuildSize = (simpleReasoner.getSameAsEnabled()) ? rebuildModel.size() : 0;
|
long prevRebuildSize = (simpleReasoner.getSameAsEnabled()) ? rebuildModel.size() : 0;
|
||||||
Model additionalInferences = recomputeIndividual(
|
|
||||||
individualURI, null, assertions, rebuildModel, caches, RUN_PLUGINS);
|
|
||||||
if (simpleReasoner.getSameAsEnabled()) {
|
if (simpleReasoner.getSameAsEnabled()) {
|
||||||
Set<String> sameAsInds = getSameAsIndividuals(individualURI);
|
Set<String> sameAsInds = getSameAsIndividuals(individualURI);
|
||||||
for (String sameAsInd : sameAsInds) {
|
for (String sameAsInd : sameAsInds) {
|
||||||
// sameAs for plugins is handled by the SimpleReasoner
|
// sameAs for plugins is handled by the SimpleReasoner
|
||||||
Model sameAsIndAssertions = getAssertions(sameAsInd);
|
Model sameAsIndAssertions = getAssertions(sameAsInd);
|
||||||
recomputeIndividual(
|
|
||||||
sameAsInd, individualURI, sameAsIndAssertions, rebuildModel, caches, SKIP_PLUGINS);
|
|
||||||
rebuildModel.add(
|
rebuildModel.add(
|
||||||
rewriteInferences(getAssertions(sameAsInd), individualURI));
|
rewriteInferences(getAssertions(sameAsInd), individualURI));
|
||||||
Resource indRes = ResourceFactory.createResource(individualURI);
|
Resource indRes = ResourceFactory.createResource(individualURI);
|
||||||
|
@ -242,6 +238,8 @@ public class ABoxRecomputer {
|
||||||
individualQueue.addAll(sameAsInds);
|
individualQueue.addAll(sameAsInds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Model additionalInferences = recomputeIndividual(
|
||||||
|
individualURI, null, assertions, rebuildModel, caches, RUN_PLUGINS);
|
||||||
return additionalInferences;
|
return additionalInferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +260,7 @@ public class ABoxRecomputer {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Model types = ModelFactory.createDefaultModel();
|
Model types = ModelFactory.createDefaultModel();
|
||||||
types.add(assertions.listStatements(null, RDF.type, (RDFNode) null));
|
types.add(assertions.listStatements(null, RDF.type, (RDFNode) null));
|
||||||
|
types.add(rebuildModel.listStatements(null, RDF.type, (RDFNode) null));
|
||||||
Model inferredTypes = rewriteInferences(getInferredTypes(individual, types, caches), aliasURI);
|
Model inferredTypes = rewriteInferences(getInferredTypes(individual, types, caches), aliasURI);
|
||||||
rebuildModel.add(inferredTypes);
|
rebuildModel.add(inferredTypes);
|
||||||
log.trace((System.currentTimeMillis() - start) + " to infer " + inferredTypes.size() + " types");
|
log.trace((System.currentTimeMillis() - start) + " to infer " + inferredTypes.size() + " types");
|
||||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.reasoner;
|
||||||
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;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.apache.jena.ontology.AnnotationProperty;
|
import org.apache.jena.ontology.AnnotationProperty;
|
||||||
|
@ -454,7 +455,7 @@ public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper {
|
||||||
* adding and removing a type assertion for an individual who has
|
* adding and removing a type assertion for an individual who has
|
||||||
* a sameAs individual.
|
* a sameAs individual.
|
||||||
*/
|
*/
|
||||||
//@Test
|
@Test
|
||||||
public void tBoxTypeAssertion1() {
|
public void tBoxTypeAssertion1() {
|
||||||
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||||
OntModel tBox = createTBoxModel();
|
OntModel tBox = createTBoxModel();
|
||||||
|
@ -493,7 +494,7 @@ public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper {
|
||||||
* adding and removing subclass assertion when there is an
|
* adding and removing subclass assertion when there is an
|
||||||
* individual member who has a sameAs individual.
|
* individual member who has a sameAs individual.
|
||||||
*/
|
*/
|
||||||
//@Test
|
@Test
|
||||||
public void tBoxSubclassAssertion1() throws InterruptedException {
|
public void tBoxSubclassAssertion1() throws InterruptedException {
|
||||||
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||||
OntModel tBox = createTBoxModel();
|
OntModel tBox = createTBoxModel();
|
||||||
|
@ -596,14 +597,16 @@ public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper {
|
||||||
* test that mostSpecificType inferences propagate to sameAs
|
* test that mostSpecificType inferences propagate to sameAs
|
||||||
* individuals
|
* individuals
|
||||||
*/
|
*/
|
||||||
//@Test
|
@Test
|
||||||
public void mostSpecificTypeTest1() {
|
public void mostSpecificTypeTest1() {
|
||||||
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||||
OntModel tBox = createTBoxModel();
|
OntModel tBox = createTBoxModel();
|
||||||
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
|
OntClass classA = createClass(tBox, "http://test.vivo/A", "class A");
|
||||||
OntClass classC = createClass(tBox, "http://test.vivo/B", "class C");
|
OntClass classC = createClass(tBox, "http://test.vivo/C", "class C");
|
||||||
OntClass classD = createClass(tBox, "http://test.vivo/B", "class D");
|
OntClass classD = createClass(tBox, "http://test.vivo/D", "class D");
|
||||||
OntClass classE = createClass(tBox, "http://test.vivo/B", "class E");
|
OntClass classE = createClass(tBox, "http://test.vivo/E", "class E");
|
||||||
|
|
||||||
|
// A is superclass of C, C is superclass of D and E
|
||||||
addSubclass(classA, classC);
|
addSubclass(classA, classC);
|
||||||
addSubclass(classC, classD);
|
addSubclass(classC, classD);
|
||||||
addSubclass(classC, classE);
|
addSubclass(classC, classE);
|
||||||
|
@ -627,21 +630,27 @@ public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper {
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
|
// Assert a, b, c and d are the same
|
||||||
aBox.add(a, OWL.sameAs, b);
|
aBox.add(a, OWL.sameAs, b);
|
||||||
aBox.add(c, OWL.sameAs, b);
|
aBox.add(c, OWL.sameAs, b);
|
||||||
aBox.add(d, OWL.sameAs, a);
|
aBox.add(d, OWL.sameAs, a);
|
||||||
|
|
||||||
|
// Assert a is D, and d ic C
|
||||||
|
// All resources will therefore be C and D
|
||||||
aBox.add(a, RDF.type, classD);
|
aBox.add(a, RDF.type, classD);
|
||||||
aBox.add(d, RDF.type, classC);
|
aBox.add(d, RDF.type, classC);
|
||||||
Assert.assertFalse(inf.contains(a,RDF.type,classD));
|
|
||||||
|
// All resources should be inferred as C and D, except a and d which have direct assertions
|
||||||
|
Assert.assertFalse(inf.contains(a,RDF.type,classD)); // D is asserted for a
|
||||||
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type, classD));
|
Assert.assertTrue(inf.contains(b,RDF.type, classD));
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
||||||
Assert.assertTrue(inf.contains(c,RDF.type, classD));
|
Assert.assertTrue(inf.contains(c,RDF.type, classD));
|
||||||
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
||||||
Assert.assertTrue(inf.contains(d,RDF.type, classD));
|
Assert.assertTrue(inf.contains(d,RDF.type, classD));
|
||||||
Assert.assertFalse(inf.contains(d,RDF.type, classC));
|
Assert.assertFalse(inf.contains(d,RDF.type, classC)); // C is asserted for d
|
||||||
|
|
||||||
|
// In all cases, mostSpecificType should be D, not C
|
||||||
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
|
Loading…
Add table
Reference in a new issue