incremental development for sameAs inference support
This commit is contained in:
parent
5a7f70e1d7
commit
2b15e7211c
3 changed files with 262 additions and 112 deletions
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -427,6 +428,8 @@ public class SimpleReasoner extends StatementListener {
|
||||||
Resource subject = null;
|
Resource subject = null;
|
||||||
Resource object = null;
|
Resource object = null;
|
||||||
|
|
||||||
|
//System.out.println("\n\naddedABoxSameAsAssertion called for this statement: " + stmtString(stmt));
|
||||||
|
|
||||||
if (stmt.getSubject().isResource()) {
|
if (stmt.getSubject().isResource()) {
|
||||||
subject = stmt.getSubject().asResource();
|
subject = stmt.getSubject().asResource();
|
||||||
if (tboxModel.containsResource(subject) || subject.isAnon()) {
|
if (tboxModel.containsResource(subject) || subject.isAnon()) {
|
||||||
|
@ -449,18 +452,6 @@ public class SimpleReasoner extends StatementListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Model inferences = ModelFactory.createDefaultModel();
|
|
||||||
inferences.add(generateSameAsInferences(subject, object, inferenceModel));
|
|
||||||
inferences.add(generateSameAsInferences(object, subject, inferenceModel));
|
|
||||||
inferences.add(object, OWL.sameAs, subject);
|
|
||||||
|
|
||||||
Iterator<Statement> infIter = inferences.listStatements();
|
|
||||||
|
|
||||||
while (infIter.hasNext()) {
|
|
||||||
Statement infStmt = infIter.next();
|
|
||||||
addInference(infStmt,inferenceModel,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if (inferenceModel.contains(stmt)) {
|
if (inferenceModel.contains(stmt)) {
|
||||||
|
@ -469,35 +460,103 @@ public class SimpleReasoner extends StatementListener {
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Statement opposite = ResourceFactory.createStatement(object, OWL.sameAs, subject);
|
||||||
|
addInference(opposite,inferenceModel,true);
|
||||||
|
|
||||||
|
generateSameAsInferences(subject, object, inferenceModel);
|
||||||
|
generateSameAsInferences(object, subject, inferenceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a model that contains every assertion about indB as exists for
|
* Materializes inferences based on the owl:sameAs relationship.
|
||||||
* indA in the Abox assertions or inference model
|
*
|
||||||
|
* If it is removed that x is sameAs y, then remove y sameAs x from
|
||||||
|
* the inference graph and then recompute the inferences for x and
|
||||||
|
* y based on their respective assertions. that x owl:sameAs y, then all asserted and inferred
|
||||||
*/
|
*/
|
||||||
public Model generateSameAsInferences(Resource indA, Resource indB, Model inferenceModel) {
|
public void removedABoxSameAsAssertion(Statement stmt, Model inferenceModel) {
|
||||||
|
Resource subject = null;
|
||||||
|
Resource object = null;
|
||||||
|
|
||||||
Model inferences = ModelFactory.createDefaultModel();
|
if (stmt.getSubject().isResource()) {
|
||||||
|
subject = stmt.getSubject().asResource();
|
||||||
|
if (tboxModel.containsResource(subject) || subject.isAnon()) {
|
||||||
|
log.debug("the subject of this removed sameAs statement is either in the tbox or an anonymous node, no reasoning will be done: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("the subject of this removed sameAs statement is not a resource, no reasoning will be done: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stmt.getObject().isResource()) {
|
||||||
|
object = stmt.getObject().asResource();
|
||||||
|
if (tboxModel.containsResource(object) || object.isAnon()) {
|
||||||
|
log.debug("the object of this removed sameAs statement is either in the tbox or an anonymous node, no reasoning will be done: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("the object of this removed sameAs statement is not a resource, no reasoning will be done: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Resource> sameIndividuals = new HashSet<Resource>();
|
||||||
|
|
||||||
|
inferenceModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
Iterator<Statement> iter1 = inferenceModel.listStatements(subject, OWL.sameAs, (RDFNode) null);
|
||||||
|
while (iter1.hasNext()) {
|
||||||
|
Statement sameStmt = iter1.next();
|
||||||
|
if (sameStmt.getObject() == null || !sameStmt.getObject().isResource()) continue;
|
||||||
|
sameIndividuals.add(sameStmt.getObject().asResource());
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Statement> iter2 = inferenceModel.listStatements(object, OWL.sameAs, (RDFNode) null);
|
||||||
|
while (iter2.hasNext()) {
|
||||||
|
Statement sameStmt = iter2.next();
|
||||||
|
if (sameStmt.getObject() == null || !sameStmt.getObject().isResource()) continue;
|
||||||
|
sameIndividuals.add(sameStmt.getObject().asResource());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Iterator<Resource> sIter1 = sameIndividuals.iterator();
|
||||||
|
while (sIter1.hasNext()) {
|
||||||
|
removeInferencesForIndividual(sIter1.next(), inferenceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Resource> sIter2 = sameIndividuals.iterator();
|
||||||
|
while (sIter2.hasNext()) {
|
||||||
|
computeInferencesForIndividual(sIter2.next(), inferenceModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateSameAsInferences(Resource ind1, Resource ind2, Model inferenceModel) {
|
||||||
|
|
||||||
|
//System.out.println("\n\tgenerateSameAsInferences. ind1= " + ind1.getLocalName() + " ind2= " + ind2.getLocalName());
|
||||||
|
|
||||||
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
unionModel.addSubModel(aboxModel);
|
unionModel.addSubModel(aboxModel);
|
||||||
unionModel.addSubModel(inferenceModel);
|
unionModel.addSubModel(inferenceModel);
|
||||||
|
|
||||||
aboxModel.enterCriticalSection(Lock.READ);
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
Iterator<Statement> iter = unionModel.listStatements(indA, (Property) null, (RDFNode) null);
|
Iterator<Statement> iter = unionModel.listStatements(ind1, (Property) null, (RDFNode) null);
|
||||||
|
while (iter.hasNext()) {
|
||||||
while (iter.hasNext()) {
|
Statement stmt = iter.next();
|
||||||
Statement stmt = iter.next();
|
//System.out.println("\tIn loop. stmt = " + stmtString(stmt));
|
||||||
if (stmt.getObject() == null) continue;
|
if (stmt.getObject() == null) continue;
|
||||||
if (OWL.sameAs.equals(stmt.getPredicate()) && indB.equals(stmt.getObject())) continue;
|
Statement infStmt = ResourceFactory.createStatement(ind2,stmt.getPredicate(),stmt.getObject());
|
||||||
inferences.add(indB, stmt.getPredicate(), stmt.getObject());
|
addInference(infStmt, inferenceModel,true);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
aboxModel.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return inferences;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -532,59 +591,18 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Materializes inferences based on the owl:sameAs relationship.
|
* Remove inferences for individual
|
||||||
*
|
|
||||||
* If it is removed that x is sameAs y, then remove y sameAs x from
|
|
||||||
* the inference graph and then recompute the inferences for x and
|
|
||||||
* y based on their respective assertions. that x owl:sameAs y, then all asserted and inferred
|
|
||||||
*/
|
*/
|
||||||
//TODO - I think I need to handle sameAs chains here
|
public void removeInferencesForIndividual(Resource ind, Model inferenceModel) {
|
||||||
public void removedABoxSameAsAssertion(Statement stmt, Model inferenceModel) {
|
|
||||||
|
|
||||||
Resource subject = null;
|
Model individualInferences = ModelFactory.createDefaultModel();
|
||||||
Resource object = null;
|
|
||||||
|
|
||||||
if (stmt.getSubject().isResource()) {
|
|
||||||
subject = stmt.getSubject().asResource();
|
|
||||||
if (tboxModel.containsResource(subject) || subject.isAnon()) {
|
|
||||||
log.debug("the subject of this removed sameAs statement is either in the tbox or an anonymous node, no reasoning will be done: " + stmtString(stmt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("the subject of this removed sameAs statement is not a resource, no reasoning will be done: " + stmtString(stmt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stmt.getObject().isResource()) {
|
|
||||||
object = stmt.getObject().asResource();
|
|
||||||
if (tboxModel.containsResource(object) || object.isAnon()) {
|
|
||||||
log.debug("the object of this removed sameAs statement is either in the tbox or an anonymous node, no reasoning will be done: " + stmtString(stmt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("the object of this removed sameAs statement is not a resource, no reasoning will be done: " + stmtString(stmt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement infStmt = ResourceFactory.createStatement(object,OWL.sameAs,subject);
|
|
||||||
removeInference(infStmt,inferenceModel,false);
|
|
||||||
recomputeInferencesForIndividual(subject, inferenceModel);
|
|
||||||
recomputeInferencesForIndividual(object, inferenceModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Recompute inferences for individual
|
|
||||||
*/
|
|
||||||
public void recomputeInferencesForIndividual(Resource ind, Model inferenceModel) {
|
|
||||||
|
|
||||||
Model inferencesToRemove = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.READ);
|
inferenceModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
Iterator<Statement> iter = inferenceModel.listStatements(ind, (Property) null, (RDFNode) null);
|
Iterator<Statement> iter = inferenceModel.listStatements(ind, (Property) null, (RDFNode) null);
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
inferencesToRemove.add(iter.next());
|
individualInferences.add(iter.next());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
|
@ -592,11 +610,19 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
inferenceModel.remove(inferencesToRemove);
|
inferenceModel.remove(individualInferences);
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compute inferences for individual
|
||||||
|
*/
|
||||||
|
public void computeInferencesForIndividual(Resource ind, Model inferenceModel) {
|
||||||
|
|
||||||
Iterator<Statement> iter = null;
|
Iterator<Statement> iter = null;
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
|
@ -606,7 +632,9 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
addedStatement(iter.next());
|
Statement stmt = iter.next();
|
||||||
|
//System.out.println("calling addedStatement for: " + stmtString(stmt));
|
||||||
|
addedStatement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -624,6 +652,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void addedABoxAssertion(Statement stmt, Model inferenceModel) {
|
public void addedABoxAssertion(Statement stmt, Model inferenceModel) {
|
||||||
|
|
||||||
List<OntProperty> inverseProperties = getInverseProperties(stmt);
|
List<OntProperty> inverseProperties = getInverseProperties(stmt);
|
||||||
Iterator<OntProperty> inverseIter = inverseProperties.iterator();
|
Iterator<OntProperty> inverseIter = inverseProperties.iterator();
|
||||||
|
|
||||||
|
@ -1082,6 +1111,10 @@ public class SimpleReasoner extends StatementListener {
|
||||||
*/
|
*/
|
||||||
protected void removeInference(Statement infStmt, Model inferenceModel, boolean handleSameAs) {
|
protected void removeInference(Statement infStmt, Model inferenceModel, boolean handleSameAs) {
|
||||||
|
|
||||||
|
//TODO - add to Abox here if it's entailed?
|
||||||
|
|
||||||
|
//System.out.println("\nremoveInference called for this statement: " + stmtString(infStmt));
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if ( !entailedStatement(infStmt) && inferenceModel.contains(infStmt)) {
|
if ( !entailedStatement(infStmt) && inferenceModel.contains(infStmt)) {
|
||||||
|
@ -1100,6 +1133,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
while (sameIter.hasNext()) {
|
while (sameIter.hasNext()) {
|
||||||
Statement infStmtSame = ResourceFactory.createStatement(sameIter.next(), infStmt.getPredicate(), infStmt.getObject());
|
Statement infStmtSame = ResourceFactory.createStatement(sameIter.next(), infStmt.getPredicate(), infStmt.getObject());
|
||||||
if (!entailedStatement(infStmtSame) && inferenceModel.contains(infStmtSame)) {
|
if (!entailedStatement(infStmtSame) && inferenceModel.contains(infStmtSame)) {
|
||||||
|
//System.out.println("\tsameAs processing: removing this from the inference model: " + stmtString(infStmtSame));
|
||||||
inferenceModel.remove(infStmtSame);
|
inferenceModel.remove(infStmtSame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1117,11 +1151,14 @@ public class SimpleReasoner extends StatementListener {
|
||||||
*/
|
*/
|
||||||
protected void addInference(Statement infStmt, Model inferenceModel, boolean handleSameAs) {
|
protected void addInference(Statement infStmt, Model inferenceModel, boolean handleSameAs) {
|
||||||
|
|
||||||
|
//System.out.println("\taddInference called for this statement: " + stmtString(infStmt));
|
||||||
|
|
||||||
aboxModel.enterCriticalSection(Lock.READ);
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt)) {
|
if (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt)) {
|
||||||
|
//System.out.println("\t\tadding this to the inference model: " + stmtString(infStmt));
|
||||||
inferenceModel.add(infStmt);
|
inferenceModel.add(infStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,8 +1167,16 @@ public class SimpleReasoner extends StatementListener {
|
||||||
Iterator<Resource> sameIter = sameIndividuals.iterator();
|
Iterator<Resource> sameIter = sameIndividuals.iterator();
|
||||||
while (sameIter.hasNext()) {
|
while (sameIter.hasNext()) {
|
||||||
Resource subject = sameIter.next();
|
Resource subject = sameIter.next();
|
||||||
if (!inferenceModel.contains(subject,infStmt.getPredicate(),infStmt.getObject()) && !aboxModel.contains(subject,infStmt.getPredicate(),infStmt.getObject())) {
|
|
||||||
inferenceModel.add(subject,infStmt.getPredicate(),infStmt.getObject());
|
Statement sameStmt = ResourceFactory.createStatement(subject,infStmt.getPredicate(),infStmt.getObject());
|
||||||
|
if (subject.equals(infStmt.getObject()) && OWL.sameAs.equals(infStmt.getPredicate())) {
|
||||||
|
//System.out.println("\t\tsameAS processing: skipping adding this statement to the inference model: " + stmtString(sameStmt));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inferenceModel.contains(sameStmt) && !aboxModel.contains(sameStmt)) {
|
||||||
|
//System.out.println("\t\tsameAs processing: adding this to the inference model: " + stmtString(sameStmt));
|
||||||
|
inferenceModel.add(sameStmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1143,11 +1188,11 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
System.out.println("hello!!! ONE");
|
//System.out.println("hello!!! ONE");
|
||||||
if (handleSameAs) {
|
if (handleSameAs) {
|
||||||
System.out.println("hello!!! TWO");
|
//System.out.println("hello!!! TWO");
|
||||||
aboxModel.enterCriticalSection(Lock.READ);
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
System.out.println("hello!!! TRES");
|
//System.out.println("hello!!! TRES");
|
||||||
try {
|
try {
|
||||||
List<Resource> sameIndividuals = getSameIndividuals(infStmt.getSubject().asResource(), inferenceModel);
|
List<Resource> sameIndividuals = getSameIndividuals(infStmt.getSubject().asResource(), inferenceModel);
|
||||||
Iterator<Resource> sameIter = sameIndividuals.iterator();
|
Iterator<Resource> sameIter = sameIndividuals.iterator();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void suppressErrorOutput() {
|
public void suppressErrorOutput() {
|
||||||
suppressSyserr();
|
//suppressSyserr();
|
||||||
//Turn off log messages to console
|
//Turn off log messages to console
|
||||||
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
||||||
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void suppressErrorOutput() {
|
public void suppressErrorOutput() {
|
||||||
suppressSyserr();
|
//suppressSyserr();
|
||||||
//Turn off log messages to console
|
//Turn off log messages to console
|
||||||
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
setLoggerLevel(SimpleReasoner.class, Level.OFF);
|
||||||
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
||||||
|
@ -103,10 +103,10 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
|
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/data1");
|
||||||
S.setLabel("property S", "en-US");
|
S.setLabel("property S", "en-US");
|
||||||
|
|
||||||
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
|
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/data2");
|
||||||
T.setLabel("property T", "en-US");
|
T.setLabel("property T", "en-US");
|
||||||
|
|
||||||
Literal literal1 = tBox.createLiteral("Literal value 1");
|
Literal literal1 = tBox.createLiteral("Literal value 1");
|
||||||
|
@ -147,8 +147,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* basic scenario of adding an abox assertion for
|
* adding abox assertion for individual in sameAs chain.
|
||||||
* an individual is sameAs another.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion1() {
|
public void addABoxAssertion1() {
|
||||||
|
@ -182,10 +181,23 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
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");
|
||||||
|
Resource e = aBox.createResource("http://test.vivo/e");
|
||||||
|
Resource f = aBox.createResource("http://test.vivo/f");
|
||||||
|
|
||||||
aBox.add(a,OWL.sameAs,b);
|
aBox.add(a,OWL.sameAs,b);
|
||||||
|
aBox.add(b,OWL.sameAs,e);
|
||||||
|
aBox.add(e,OWL.sameAs,f);
|
||||||
|
|
||||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(e,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(e,OWL.sameAs,b));
|
||||||
|
Assert.assertTrue(inf.contains(a,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,b));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,f));
|
||||||
|
Assert.assertTrue(inf.contains(a,OWL.sameAs,f));
|
||||||
|
|
||||||
|
|
||||||
aBox.add(a,P,c);
|
aBox.add(a,P,c);
|
||||||
aBox.add(a,S,literal1);
|
aBox.add(a,S,literal1);
|
||||||
|
@ -196,24 +208,48 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
Assert.assertTrue(inf.contains(b,S,literal1));
|
Assert.assertTrue(inf.contains(b,S,literal1));
|
||||||
Assert.assertTrue(inf.contains(a,Q,d));
|
Assert.assertTrue(inf.contains(a,Q,d));
|
||||||
Assert.assertTrue(inf.contains(a,T,literal2));
|
Assert.assertTrue(inf.contains(a,T,literal2));
|
||||||
|
Assert.assertTrue(inf.contains(e,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(e,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(e,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(e,T,literal2));
|
||||||
|
Assert.assertTrue(inf.contains(f,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(f,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(f,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(f,T,literal2));
|
||||||
|
|
||||||
|
aBox.remove(b,OWL.sameAs,e);
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(e,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(e,OWL.sameAs,b));
|
||||||
|
Assert.assertFalse(inf.contains(a,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,e));
|
||||||
|
Assert.assertFalse(inf.contains(f,OWL.sameAs,b));
|
||||||
|
Assert.assertFalse(inf.contains(f,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(b,OWL.sameAs,f));
|
||||||
|
Assert.assertFalse(inf.contains(a,OWL.sameAs,f));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(b,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(a,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(a,T,literal2));
|
||||||
|
Assert.assertFalse(inf.contains(e,P,c));
|
||||||
|
Assert.assertFalse(inf.contains(e,S,literal1));
|
||||||
|
Assert.assertFalse(inf.contains(e,Q,d));
|
||||||
|
Assert.assertFalse(inf.contains(e,T,literal2));
|
||||||
|
Assert.assertFalse(inf.contains(f,P,c));
|
||||||
|
Assert.assertFalse(inf.contains(f,S,literal1));
|
||||||
|
Assert.assertFalse(inf.contains(f,Q,d));
|
||||||
|
Assert.assertFalse(inf.contains(f,T,literal2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adding abox assertion for individuals that are sameAs
|
* sameAs with datatype properties
|
||||||
* each other.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion2() {
|
public void addABoxAssertion2() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntClass classA = tBox.createClass("http://test.vivo/A");
|
|
||||||
classA.setLabel("class A", "en-US");
|
|
||||||
|
|
||||||
OntClass classB = tBox.createClass("http://test.vivo/B");
|
|
||||||
classB.setLabel("class B", "en-US");
|
|
||||||
|
|
||||||
classA.addSubClass(classB);
|
|
||||||
|
|
||||||
OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
|
OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
|
||||||
desc.setLabel("property desc", "en-US");
|
desc.setLabel("property desc", "en-US");
|
||||||
|
|
||||||
|
@ -234,14 +270,10 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
aBox.add(a,desc,desc1);
|
aBox.add(a,desc,desc1);
|
||||||
aBox.add(b,desc,desc2);
|
aBox.add(b,desc,desc2);
|
||||||
aBox.add(a,OWL.sameAs,b);
|
aBox.add(a,OWL.sameAs,b);
|
||||||
aBox.add(a, RDF.type, classB);
|
|
||||||
|
|
||||||
Assert.assertTrue(inf.contains(a,desc,desc2));
|
Assert.assertTrue(inf.contains(a,desc,desc2));
|
||||||
Assert.assertTrue(inf.contains(a,RDF.type,classA));
|
|
||||||
Assert.assertTrue(inf.contains(b,desc,desc1));
|
Assert.assertTrue(inf.contains(b,desc,desc1));
|
||||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type,classB));
|
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type,classA));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -361,6 +393,79 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adding and removing a type assertion for an individual who has
|
||||||
|
* a sameAs individual.
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void tBoxTypeAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
|
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||||
|
// Pellet will compute TBox inferences
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
|
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||||
|
classA.setLabel("class A", "en-US");
|
||||||
|
|
||||||
|
OntClass classB = tBox.createClass("http://test.vivo/B");
|
||||||
|
classB.setLabel("class B", "en-US");
|
||||||
|
|
||||||
|
classA.addSubClass(classB);
|
||||||
|
|
||||||
|
// this is the model to receive inferences
|
||||||
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
// create an ABox and register the SimpleReasoner listener with it
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
|
Resource x = aBox.createResource("http://test.vivo/x");
|
||||||
|
Resource y = aBox.createResource("http://test.vivo/y");
|
||||||
|
Resource z = aBox.createResource("http://test.vivo/z");
|
||||||
|
|
||||||
|
aBox.add(x,OWL.sameAs,y);
|
||||||
|
aBox.add(y,OWL.sameAs,z);
|
||||||
|
aBox.add(x,RDF.type,classB);
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(y,RDF.type,classB));
|
||||||
|
Assert.assertTrue(inf.contains(y,RDF.type,classA));
|
||||||
|
// Assert.assertTrue(inf.contains(z,RDF.type,classB));
|
||||||
|
// Assert.assertTrue(inf.contains(z,RDF.type,classA));
|
||||||
|
|
||||||
|
aBox.remove(x,RDF.type,classB);
|
||||||
|
Assert.assertFalse(inf.contains(y,RDF.type,classB));
|
||||||
|
Assert.assertFalse(inf.contains(y,RDF.type,classA));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adding and removing subclass assertion when there is an
|
||||||
|
* individual member who has a sameAs individual.
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void tBoxSubclassAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test that mostSpecificType inferences propagate to sameAs
|
||||||
|
* individuals
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void mostSpecificTypeTest1() throws InterruptedException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* there is a sameAs chain and one sameAs statement is removed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void sameAsChain1() throws InterruptedException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic scenario around recomputing the ABox inferences
|
* Basic scenario around recomputing the ABox inferences
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue