NIHVIVO-2752 (SimpleReasoner exception when object of TBox statement is null)
This commit is contained in:
parent
61afec8de0
commit
29cb6e4077
1 changed files with 126 additions and 61 deletions
|
@ -76,6 +76,8 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This constructor is used for the unit tests only
|
||||||
|
*
|
||||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||||
* @param aboxModel - input. This model contains asserted ABox statements
|
* @param aboxModel - input. This model contains asserted ABox statements
|
||||||
* @param inferenceModel - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).
|
* @param inferenceModel - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).
|
||||||
|
@ -158,8 +160,27 @@ public class SimpleReasoner extends StatementListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( stmt.getObject().isResource() && (stmt.getObject().asResource()).getURI() == null ) {
|
||||||
|
log.warn("The object of this assertion has a null URI: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( stmt.getSubject().getURI() == null ) {
|
||||||
|
log.warn("The subject of this assertion has a null URI: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OntClass subject = tboxModel.getOntClass((stmt.getSubject()).getURI());
|
OntClass subject = tboxModel.getOntClass((stmt.getSubject()).getURI());
|
||||||
|
if (subject == null) {
|
||||||
|
log.debug("didn't find subject class in the tbox: " + (stmt.getSubject()).getURI());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OntClass object = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
OntClass object = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
||||||
|
if (object == null) {
|
||||||
|
log.debug("didn't find object class in the tbox: " + ((Resource)stmt.getObject()).getURI());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
|
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
|
||||||
addedSubClass(subject,object,inferenceModel);
|
addedSubClass(subject,object,inferenceModel);
|
||||||
|
@ -208,8 +229,27 @@ public class SimpleReasoner extends StatementListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( stmt.getObject().isResource() && (stmt.getObject().asResource()).getURI() == null ) {
|
||||||
|
log.warn("The object of this assertion has a null URI: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( stmt.getSubject().getURI() == null ) {
|
||||||
|
log.warn("The subject of this assertion has a null URI: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OntClass subject = tboxModel.getOntClass((stmt.getSubject()).getURI());
|
OntClass subject = tboxModel.getOntClass((stmt.getSubject()).getURI());
|
||||||
|
if (subject == null) {
|
||||||
|
log.debug("didn't find subject class in the tbox: " + (stmt.getSubject()).getURI());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OntClass object = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
OntClass object = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
||||||
|
if (object == null) {
|
||||||
|
log.debug("didn't find object class in the tbox: " + ((Resource)stmt.getObject()).getURI());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
|
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
|
||||||
removedSubClass(subject,object,inferenceModel);
|
removedSubClass(subject,object,inferenceModel);
|
||||||
|
@ -253,36 +293,44 @@ public class SimpleReasoner extends StatementListener {
|
||||||
tboxModel.enterCriticalSection(Lock.READ);
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OntClass cls = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
|
||||||
|
|
||||||
if (cls != null) {
|
OntClass cls = null;
|
||||||
|
|
||||||
List<OntClass> parents = (cls.listSuperClasses(false)).toList();
|
if ( (stmt.getObject().asResource()).getURI() != null ) {
|
||||||
parents.addAll((cls.listEquivalentClasses()).toList());
|
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
||||||
Iterator<OntClass> parentIt = parents.iterator();
|
|
||||||
|
|
||||||
while (parentIt.hasNext()) {
|
if (cls != null) {
|
||||||
OntClass parentClass = parentIt.next();
|
|
||||||
|
|
||||||
// VIVO doesn't materialize statements that assert anonymous types
|
List<OntClass> parents = (cls.listSuperClasses(false)).toList();
|
||||||
// for individuals. Also, sharing an identical anonymous node is
|
parents.addAll((cls.listEquivalentClasses()).toList());
|
||||||
// not allowed in owl-dl. picklist population code looks at qualities
|
Iterator<OntClass> parentIt = parents.iterator();
|
||||||
// of classes not individuals.
|
|
||||||
if (parentClass.isAnon()) continue;
|
|
||||||
|
|
||||||
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
while (parentIt.hasNext()) {
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
OntClass parentClass = parentIt.next();
|
||||||
try {
|
|
||||||
if (!inferenceModel.contains(infStmt) && !infStmt.equals(stmt) ) {
|
// VIVO doesn't materialize statements that assert anonymous types
|
||||||
//log.debug("Adding this inferred statement: " + infStmt.toString() );
|
// for individuals. Also, sharing an identical anonymous node is
|
||||||
inferenceModel.add(infStmt);
|
// not allowed in owl-dl. picklist population code looks at qualities
|
||||||
|
// of classes not individuals.
|
||||||
|
if (parentClass.isAnon()) continue;
|
||||||
|
|
||||||
|
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
if (!inferenceModel.contains(infStmt) && !infStmt.equals(stmt) ) {
|
||||||
|
//log.debug("Adding this inferred statement: " + infStmt.toString() );
|
||||||
|
inferenceModel.add(infStmt);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
inferenceModel.leaveCriticalSection();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
|
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tboxModel.leaveCriticalSection();
|
tboxModel.leaveCriticalSection();
|
||||||
|
@ -340,7 +388,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("Didn't find target property (the predicate of the added statement) in the TBox: " + stmt.getPredicate().getURI());
|
log.debug("Didn't find target property (the predicate of the added statement) in the TBox: " + stmt.getPredicate().getURI());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tboxModel.leaveCriticalSection();
|
tboxModel.leaveCriticalSection();
|
||||||
|
@ -359,42 +407,52 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
tboxModel.enterCriticalSection(Lock.READ);
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
// convert this method to use generic resources - not get ontclass, not cls.listSuperClasses...
|
||||||
|
// use model contains if want to log warning about type owl class
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OntClass cls = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
|
|
||||||
|
|
||||||
if (cls != null) {
|
OntClass cls = null;
|
||||||
|
|
||||||
List<OntClass> parents = (cls.listSuperClasses(false)).toList();
|
if ( (stmt.getObject().asResource()).getURI() != null ) {
|
||||||
parents.addAll((cls.listEquivalentClasses()).toList());
|
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
||||||
Iterator<OntClass> parentIt = parents.iterator();
|
|
||||||
|
|
||||||
while (parentIt.hasNext()) {
|
if (cls != null) {
|
||||||
OntClass parentClass = parentIt.next();
|
|
||||||
|
|
||||||
// VIVO doesn't materialize statements that assert anonymous types
|
List<OntClass> parents = (cls.listSuperClasses(false)).toList();
|
||||||
// for individuals. Also, sharing an identical anonymous node is
|
parents.addAll((cls.listEquivalentClasses()).toList());
|
||||||
// not allowed in owl-dl. picklist population code looks at qualities
|
Iterator<OntClass> parentIt = parents.iterator();
|
||||||
// of classes not individuals.
|
|
||||||
if (parentClass.isAnon()) continue;
|
|
||||||
|
|
||||||
if (entailedType(stmt.getSubject(),parentClass)) continue; // if a type is still entailed without the
|
while (parentIt.hasNext()) {
|
||||||
// removed statement, then don't remove it
|
OntClass parentClass = parentIt.next();
|
||||||
// from the inferences
|
|
||||||
|
|
||||||
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
// VIVO doesn't materialize statements that assert anonymous types
|
||||||
|
// for individuals. Also, sharing an identical anonymous node is
|
||||||
|
// not allowed in owl-dl. picklist population code looks at qualities
|
||||||
|
// of classes not individuals.
|
||||||
|
if (parentClass.isAnon()) continue;
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
if (entailedType(stmt.getSubject(),parentClass)) continue; // if a type is still entailed without the
|
||||||
try {
|
// removed statement, then don't remove it
|
||||||
if (inferenceModel.contains(infStmt)) {
|
// from the inferences
|
||||||
//log.debug("Removing this inferred statement: " + infStmt.toString() + " - " + infStmt.getSubject().toString() + " - " + infStmt.getPredicate().toString() + " - " + infStmt.getObject().toString());
|
|
||||||
inferenceModel.remove(infStmt);
|
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
||||||
|
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
if (inferenceModel.contains(infStmt)) {
|
||||||
|
//log.debug("Removing this inferred statement: " + infStmt.toString() + " - " + infStmt.getSubject().toString() + " - " + infStmt.getPredicate().toString() + " - " + infStmt.getObject().toString());
|
||||||
|
inferenceModel.remove(infStmt);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
inferenceModel.leaveCriticalSection();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Didn't find target class (the object of the removed rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Didn't find target class (the object of the removed rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
|
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tboxModel.leaveCriticalSection();
|
tboxModel.leaveCriticalSection();
|
||||||
|
@ -700,10 +758,17 @@ public class SimpleReasoner extends StatementListener {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
OntClass ontClass = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
OntClass ontClass = null;
|
||||||
|
|
||||||
|
if ( (stmt.getObject().asResource()).getURI() != null ) {
|
||||||
|
ontClass = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
||||||
|
} else {
|
||||||
|
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (ontClass == null) {
|
if (ontClass == null) {
|
||||||
log.warn("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + (stmt.getObject().asResource()).getURI());
|
log.debug("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + (stmt.getObject().asResource()).getURI());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue