merging NIHVIVO-3028 from branch
This commit is contained in:
parent
199a5f6c2f
commit
3a853c54f8
2 changed files with 49 additions and 22 deletions
|
@ -366,15 +366,20 @@ public class SimpleReasoner extends StatementListener {
|
||||||
if (parentClass.isAnon()) continue;
|
if (parentClass.isAnon()) continue;
|
||||||
|
|
||||||
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), RDF.type, parentClass);
|
||||||
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if (!inferenceModel.contains(infStmt) && !infStmt.equals(stmt) ) {
|
if (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt)) {
|
||||||
//log.debug("Adding this inferred statement: " + infStmt.toString() );
|
//log.debug("Adding this inferred statement: " + infStmt.toString() );
|
||||||
inferenceModel.add(infStmt);
|
inferenceModel.add(infStmt);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( !(stmt.getObject().asResource().getNameSpace()).equals(OWL.NS)) {
|
if ( !(stmt.getObject().asResource().getNameSpace()).equals(OWL.NS)) {
|
||||||
|
@ -435,14 +440,19 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), superProp, stmt.getObject());
|
Statement infStmt = ResourceFactory.createStatement(stmt.getSubject(), superProp, stmt.getObject());
|
||||||
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if (!inferenceModel.contains(infStmt) && !infStmt.equals(stmt) ) {
|
if (!inferenceModel.contains(infStmt) && !aboxModel.contains(infStmt) ) {
|
||||||
inferenceModel.add(infStmt);
|
inferenceModel.add(infStmt);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("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());
|
||||||
|
@ -458,7 +468,6 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* that B is of that type.
|
* that B is of that type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void removedABoxTypeAssertion(Statement stmt, Model inferenceModel) {
|
public void removedABoxTypeAssertion(Statement stmt, Model inferenceModel) {
|
||||||
|
|
||||||
tboxModel.enterCriticalSection(Lock.READ);
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
@ -474,6 +483,20 @@ public class SimpleReasoner extends StatementListener {
|
||||||
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
cls = tboxModel.getOntClass(stmt.getObject().asResource().getURI());
|
||||||
|
|
||||||
if (cls != null) {
|
if (cls != null) {
|
||||||
|
if (entailedType(stmt.getSubject(),cls)) {
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
//don't have to check aboxmodel here because this is the
|
||||||
|
//statement being removed.
|
||||||
|
if (!inferenceModel.contains(stmt)) {
|
||||||
|
inferenceModel.add(stmt);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<OntClass> parents = null;
|
List<OntClass> parents = null;
|
||||||
parents = (cls.listSuperClasses(false)).toList();
|
parents = (cls.listSuperClasses(false)).toList();
|
||||||
|
@ -652,14 +675,19 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
for (Resource subject : subjectList) {
|
for (Resource subject : subjectList) {
|
||||||
Statement infStmt = ResourceFactory.createStatement(subject, RDF.type, superClass);
|
Statement infStmt = ResourceFactory.createStatement(subject, RDF.type, superClass);
|
||||||
|
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
aboxModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
if (!inferenceModel.contains(infStmt)) {
|
if (!inferenceModel.contains(infStmt) ) {
|
||||||
|
if (!aboxModel.contains(infStmt)) {
|
||||||
inferenceModel.add(infStmt);
|
inferenceModel.add(infStmt);
|
||||||
setMostSpecificTypes(subject, inferenceModel, new HashSet<String>());
|
}
|
||||||
|
setMostSpecificTypes(infStmt.getSubject(), inferenceModel, new HashSet<String>());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -672,7 +700,6 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* of A (including A itself)
|
* of A (including A itself)
|
||||||
*/
|
*/
|
||||||
public void removedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
public void removedSubClass(OntClass subClass, OntClass superClass, Model inferenceModel) {
|
||||||
log.debug("subClass = " + subClass.getURI() + ". superClass = " + superClass.getURI());
|
|
||||||
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);
|
||||||
|
@ -688,14 +715,16 @@ public class SimpleReasoner extends StatementListener {
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
for (Resource ind : subjectList) {
|
for (Resource ind : subjectList) {
|
||||||
if (entailedType(ind,superClass)) continue;
|
if (entailedType(ind,superClass)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Statement infStmt = ResourceFactory.createStatement(ind, RDF.type, superClass);
|
Statement infStmt = ResourceFactory.createStatement(ind, RDF.type, superClass);
|
||||||
inferenceModel.enterCriticalSection(Lock.WRITE);
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
if (inferenceModel.contains(infStmt)) {
|
if (inferenceModel.contains(infStmt)) {
|
||||||
inferenceModel.remove(infStmt);
|
inferenceModel.remove(infStmt);
|
||||||
setMostSpecificTypes(infStmt.getSubject(), inferenceModel, new HashSet<String>());
|
|
||||||
}
|
}
|
||||||
|
setMostSpecificTypes(ind, inferenceModel, new HashSet<String>());
|
||||||
} finally {
|
} finally {
|
||||||
inferenceModel.leaveCriticalSection();
|
inferenceModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -709,8 +738,6 @@ public class SimpleReasoner extends StatementListener {
|
||||||
*/
|
*/
|
||||||
public void addedSubProperty(OntProperty subProp, OntProperty superProp, Model inferenceModel) {
|
public void addedSubProperty(OntProperty subProp, OntProperty superProp, Model inferenceModel) {
|
||||||
|
|
||||||
log.debug("subProperty = " + subProp.getURI() + " superProperty = " + subProp.getURI());
|
|
||||||
|
|
||||||
if ( !((subProp.isObjectProperty() && superProp.isObjectProperty()) || (subProp.isDatatypeProperty() && superProp.isDatatypeProperty())) ) {
|
if ( !((subProp.isObjectProperty() && superProp.isObjectProperty()) || (subProp.isDatatypeProperty() && superProp.isDatatypeProperty())) ) {
|
||||||
log.warn("sub-property and super-property do not have the same type. No inferencing will be performed. sub-property: " + subProp.getURI() + " super-property:" + superProp.getURI());
|
log.warn("sub-property and super-property do not have the same type. No inferencing will be performed. sub-property: " + subProp.getURI() + " super-property:" + superProp.getURI());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1116,7 +1116,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
classE.setLabel("class E", "en-US");
|
classE.setLabel("class E", "en-US");
|
||||||
|
|
||||||
OntClass classF = tBox.createClass("http://test.vivo/F");
|
OntClass classF = tBox.createClass("http://test.vivo/F");
|
||||||
classE.setLabel("class F", "en-US");
|
classF.setLabel("class F", "en-US");
|
||||||
|
|
||||||
OntClass classG = tBox.createClass("http://test.vivo/G");
|
OntClass classG = tBox.createClass("http://test.vivo/G");
|
||||||
classE.setLabel("class G", "en-US");
|
classE.setLabel("class G", "en-US");
|
||||||
|
|
Loading…
Add table
Reference in a new issue