NIHVIVO-2752 (SimpleReasoner exception when object of TBox statement is null)

This commit is contained in:
stellamit 2011-06-22 16:19:08 +00:00
parent 61afec8de0
commit 29cb6e4077

View file

@ -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 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).
@ -158,8 +160,27 @@ public class SimpleReasoner extends StatementListener {
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());
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());
if (object == null) {
log.debug("didn't find object class in the tbox: " + ((Resource)stmt.getObject()).getURI());
return;
}
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
addedSubClass(subject,object,inferenceModel);
@ -208,8 +229,27 @@ public class SimpleReasoner extends StatementListener {
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());
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());
if (object == null) {
log.debug("didn't find object class in the tbox: " + ((Resource)stmt.getObject()).getURI());
return;
}
if (stmt.getPredicate().equals(RDFS.subClassOf)) {
removedSubClass(subject,object,inferenceModel);
@ -253,7 +293,11 @@ public class SimpleReasoner extends StatementListener {
tboxModel.enterCriticalSection(Lock.READ);
try {
OntClass cls = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
OntClass cls = null;
if ( (stmt.getObject().asResource()).getURI() != null ) {
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
if (cls != null) {
@ -284,6 +328,10 @@ public class SimpleReasoner extends StatementListener {
} else {
log.debug("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
}
} else {
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
return;
}
} finally {
tboxModel.leaveCriticalSection();
}
@ -340,7 +388,7 @@ public class SimpleReasoner extends StatementListener {
}
}
} 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 {
tboxModel.leaveCriticalSection();
@ -359,8 +407,15 @@ public class SimpleReasoner extends StatementListener {
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 {
OntClass cls = tboxModel.getOntClass(((Resource)stmt.getObject()).getURI());
OntClass cls = null;
if ( (stmt.getObject().asResource()).getURI() != null ) {
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
if (cls != null) {
@ -396,6 +451,9 @@ public class SimpleReasoner extends StatementListener {
} else {
log.debug("Didn't find target class (the object of the removed rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
}
} else {
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
}
} finally {
tboxModel.leaveCriticalSection();
}
@ -700,10 +758,17 @@ public class SimpleReasoner extends StatementListener {
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) {
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;
}