NIHVIVO-2837 - compute mostSpecificType annotations on the upgrade to 1.3
This commit is contained in:
parent
89fb16caf7
commit
ea5094d0ef
4 changed files with 115 additions and 18 deletions
|
@ -72,13 +72,6 @@ public class SimpleReasoner extends StatementListener {
|
||||||
this.inferenceRebuildModel = inferenceRebuildModel;
|
this.inferenceRebuildModel = inferenceRebuildModel;
|
||||||
this.scratchpadModel = scratchpadModel;
|
this.scratchpadModel = scratchpadModel;
|
||||||
|
|
||||||
inferenceRebuildModel.enterCriticalSection(Lock.WRITE);
|
|
||||||
try {
|
|
||||||
inferenceRebuildModel.removeAll();
|
|
||||||
} finally {
|
|
||||||
inferenceRebuildModel.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
aboxModel.register(this);
|
aboxModel.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +327,8 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("Didn't find target class (the object of the added rdf:type statement) in the TBox: " + ((Resource)stmt.getObject()).getURI());
|
if ( !(stmt.getObject().asResource().getNameSpace()).equals(OWL.NS))
|
||||||
|
log.warn("Didn't find target class (the object of the added rdf:type statement) in the TBox");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
|
log.warn("The object of this rdf:type assertion has a null URI: " + stmtString(stmt));
|
||||||
|
@ -785,7 +779,10 @@ public class SimpleReasoner extends StatementListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ontClass == null) {
|
if (ontClass == null) {
|
||||||
log.warn("(setMostSpecificType) Didn't find target class (the object of the added rdf:type statement) in the TBox: " + (stmt.getObject().asResource()).getURI());
|
if ( !(stmt.getObject().asResource().getNameSpace()).equals(OWL.NS)) {
|
||||||
|
log.warn("(setMostSpecificType) Didn't find target class (the object of the added rdf:type statement) in the TBox: " +
|
||||||
|
(stmt.getObject().asResource()).getURI() + "\nstatement is: " + stmtString(stmt));
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,6 +1058,82 @@ public class SimpleReasoner extends StatementListener {
|
||||||
log.info("ABox inference model updated");
|
log.info("ABox inference model updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Special for version 1.3
|
||||||
|
*/
|
||||||
|
public synchronized void recomputeMostSpecificType() {
|
||||||
|
|
||||||
|
// recompute the inferences
|
||||||
|
inferenceRebuildModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
tboxModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
try {
|
||||||
|
inferenceRebuildModel.removeAll();
|
||||||
|
StmtIterator iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
|
||||||
|
|
||||||
|
log.info("Computing mostSpecificType annotations");
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Statement stmt = iter.next();
|
||||||
|
setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception while recomputing ABox inference model", e);
|
||||||
|
inferenceRebuildModel.removeAll(); // don't do this in the finally, it's needed in the case
|
||||||
|
// where there isn't an exception
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
aboxModel.leaveCriticalSection();
|
||||||
|
tboxModel.leaveCriticalSection();
|
||||||
|
inferenceRebuildModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// reflect the recomputed inferences into the application inference
|
||||||
|
// model.
|
||||||
|
inferenceRebuildModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
scratchpadModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
log.info("Updating ABox inference model");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Add everything from the recomputed inference model that is not already
|
||||||
|
// in the current inference model to the current inference model.
|
||||||
|
inferenceModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
try {
|
||||||
|
scratchpadModel.removeAll();
|
||||||
|
StmtIterator iter = inferenceRebuildModel.listStatements();
|
||||||
|
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Statement stmt = iter.next();
|
||||||
|
if (!inferenceModel.contains(stmt)) {
|
||||||
|
scratchpadModel.add(stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
inferenceModel.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
inferenceModel.add(scratchpadModel);
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("Exception while reconciling the current and recomputed ABox inference models", e);
|
||||||
|
} finally {
|
||||||
|
inferenceModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inferenceRebuildModel.removeAll();
|
||||||
|
scratchpadModel.removeAll();
|
||||||
|
inferenceRebuildModel.leaveCriticalSection();
|
||||||
|
scratchpadModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("ABox inference model updated");
|
||||||
|
}
|
||||||
|
|
||||||
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
|
||||||
Object simpleReasoner = ctx.getAttribute("simpleReasoner");
|
Object simpleReasoner = ctx.getAttribute("simpleReasoner");
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,10 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (aboxChanged || tboxChanged) && !isUpdateRequired(sce.getServletContext()) ) {
|
if (isUpdateRequired(sce.getServletContext())) {
|
||||||
|
log.info("mostSpecificType will be computed because a knowledge base migration was performed." );
|
||||||
|
SimpleReasonerSetup.setMSTComputeRequired(sce.getServletContext());
|
||||||
|
} else if (aboxChanged || tboxChanged) {
|
||||||
log.info("a full recompute of the Abox will be performed because" +
|
log.info("a full recompute of the Abox will be performed because" +
|
||||||
" the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time." );
|
" the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time." );
|
||||||
SimpleReasonerSetup.setRecomputeRequired(sce.getServletContext());
|
SimpleReasonerSetup.setRecomputeRequired(sce.getServletContext());
|
||||||
|
|
|
@ -99,7 +99,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(unionOms.getTBoxModel(), assertionsOms.getABoxModel(), inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
SimpleReasoner simpleReasoner = new SimpleReasoner(unionOms.getTBoxModel(), assertionsOms.getABoxModel(), inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
||||||
|
|
||||||
if (isRecomputeRequired(sce.getServletContext())) {
|
if (isRecomputeRequired(sce.getServletContext())) {
|
||||||
|
|
||||||
log.info("ABox inference recompute required");
|
log.info("ABox inference recompute required");
|
||||||
|
|
||||||
int sleeps = 0;
|
int sleeps = 0;
|
||||||
|
@ -112,7 +111,19 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
simpleReasoner.recompute();
|
simpleReasoner.recompute();
|
||||||
|
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
||||||
|
log.info("most specific type computation required");
|
||||||
|
|
||||||
|
int sleeps = 0;
|
||||||
|
while (sleeps < 1000 && pelletListener.isReasoning()) {
|
||||||
|
if ((sleeps % 30) == 0) {
|
||||||
|
log.info("Waiting for initial TBox reasoning to complete");
|
||||||
|
}
|
||||||
|
Thread.sleep(100);
|
||||||
|
sleeps++;
|
||||||
|
}
|
||||||
|
|
||||||
|
simpleReasoner.recomputeMostSpecificType();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
assertionsOms.getTBoxModel().register(new SimpleReasonerTBoxListener(simpleReasoner));
|
||||||
|
@ -142,4 +153,14 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
return (ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR) != null);
|
return (ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String MSTCOMPUTE_REQUIRED_ATTR =
|
||||||
|
SimpleReasonerSetup.class.getName() + ".MSTComputeRequired";
|
||||||
|
|
||||||
|
public static void setMSTComputeRequired(ServletContext ctx) {
|
||||||
|
ctx.setAttribute(MSTCOMPUTE_REQUIRED_ATTR, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isMSTComputeRequired(ServletContext ctx) {
|
||||||
|
return (ctx.getAttribute(MSTCOMPUTE_REQUIRED_ATTR) != null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ontologyUpdater.updateRequired()) {
|
if (ontologyUpdater.updateRequired()) {
|
||||||
ctx.setAttribute(IndexConstants.INDEX_REBUILD_REQUESTED_AT_STARTUP, Boolean.TRUE);
|
//ctx.setAttribute(IndexConstants.INDEX_REBUILD_REQUESTED_AT_STARTUP, Boolean.TRUE);
|
||||||
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
|
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
|
||||||
//doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
|
//doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
|
||||||
reloadDisplayModel(ctx);
|
reloadDisplayModel(ctx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue