VIVO-778 Separate PelletReasonerSetup from SimpleReasonerSetup.
This commit is contained in:
parent
10e081c378
commit
85b9067eee
5 changed files with 110 additions and 73 deletions
|
@ -97,13 +97,6 @@ public class FileGraphSetup implements ServletContextListener {
|
|||
OntDocumentManager.getInstance().setProcessImports(false);
|
||||
}
|
||||
|
||||
/*
|
||||
if (isUpdateRequired(ctx)) {
|
||||
log.info("mostSpecificType will be computed because a knowledge base migration was performed." );
|
||||
SimpleReasonerSetup.setMSTComputeRequired(ctx);
|
||||
} else
|
||||
*/
|
||||
|
||||
if ( (aboxChanged || tboxChanged) && !isUpdateRequired(ctx)) {
|
||||
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." );
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_ASSERTIONS;
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_INFERENCES;
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_UNION;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.tboxreasoner.ReasonerConfiguration;
|
||||
|
||||
/**
|
||||
* Start the Pellet reasoner on the TBox.
|
||||
*/
|
||||
public class PelletReasonerSetup implements ServletContextListener {
|
||||
private static final Log log = LogFactory.getLog(PelletReasonerSetup.class);
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ServletContext ctx = sce.getServletContext();
|
||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||
|
||||
ContextModelAccess contextModels = ModelAccess.on(ctx);
|
||||
OntModel tboxAssertionsModel = contextModels
|
||||
.getOntModel(TBOX_ASSERTIONS);
|
||||
OntModel tboxInferencesModel = contextModels
|
||||
.getOntModel(TBOX_INFERENCES);
|
||||
OntModel tboxUnionModel = contextModels.getOntModel(TBOX_UNION);
|
||||
WebappDaoFactory wadf = contextModels.getWebappDaoFactory();
|
||||
|
||||
if (!tboxAssertionsModel.getProfile().NAMESPACE()
|
||||
.equals(OWL.NAMESPACE.getNameSpace())) {
|
||||
ss.fatal(this, "Not connecting Pellet reasoner "
|
||||
+ "- the TBox assertions model is not an OWL model");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set various Pellet options for incremental consistency checking, etc.
|
||||
// PelletOptions.DL_SAFE_RULES = true;
|
||||
// PelletOptions.USE_COMPLETION_QUEUE = true;
|
||||
// PelletOptions.USE_TRACING = true;
|
||||
// PelletOptions.TRACK_BRANCH_EFFECTS = true;
|
||||
// PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
||||
// PelletOptions.USE_INCREMENTAL_DELETION = true;
|
||||
|
||||
PelletListener pelletListener = new PelletListener(tboxUnionModel,
|
||||
tboxAssertionsModel, tboxInferencesModel,
|
||||
ReasonerConfiguration.DEFAULT);
|
||||
sce.getServletContext().setAttribute("pelletListener", pelletListener);
|
||||
sce.getServletContext().setAttribute("pelletOntModel",
|
||||
pelletListener.getPelletModel());
|
||||
|
||||
if (wadf instanceof WebappDaoFactoryJena) {
|
||||
((WebappDaoFactoryJena) wadf).setPelletListener(pelletListener);
|
||||
}
|
||||
|
||||
ss.info(this, "Pellet reasoner connected for the TBox");
|
||||
|
||||
waitForTBoxReasoning(sce);
|
||||
}
|
||||
|
||||
public static void waitForTBoxReasoning(ServletContextEvent sce) {
|
||||
PelletListener pelletListener = (PelletListener) sce
|
||||
.getServletContext().getAttribute("pelletListener");
|
||||
if (pelletListener == null) {
|
||||
return;
|
||||
}
|
||||
int sleeps = 0;
|
||||
// sleep at least once to make sure the TBox reasoning gets started
|
||||
while ((0 == sleeps)
|
||||
|| ((sleeps < 1000) && pelletListener.isReasoning())) {
|
||||
if (((sleeps - 1) % 10) == 0) { // print message at 10 second
|
||||
// intervals
|
||||
log.info("Waiting for initial TBox reasoning to complete");
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// This should never happen.
|
||||
e.printStackTrace();
|
||||
}
|
||||
sleeps++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
// Nothing to tear down
|
||||
}
|
||||
|
||||
}
|
|
@ -21,11 +21,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
|
@ -33,7 +29,6 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
|||
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasonerTBoxListener;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.tboxreasoner.ReasonerConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||
|
||||
public class SimpleReasonerSetup implements ServletContextListener {
|
||||
|
@ -51,41 +46,10 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
ServletContext ctx = sce.getServletContext();
|
||||
|
||||
try {
|
||||
// set up Pellet reasoning for the TBox
|
||||
OntModel tboxAssertionsModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS);
|
||||
OntModel tboxInferencesModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_INFERENCES);
|
||||
OntModel tboxUnionModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_UNION);
|
||||
log.debug("tboxAssertionsModel=" + tboxAssertionsModel);
|
||||
log.debug("tboxInferencesModel=" + tboxInferencesModel);
|
||||
log.debug("tboxUnionModel=" + tboxUnionModel);
|
||||
|
||||
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
||||
|
||||
if (!tboxAssertionsModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
|
||||
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set various Pellet options for incremental consistency checking, etc.
|
||||
//PelletOptions.DL_SAFE_RULES = true;
|
||||
//PelletOptions.USE_COMPLETION_QUEUE = true;
|
||||
//PelletOptions.USE_TRACING = true;
|
||||
//PelletOptions.TRACK_BRANCH_EFFECTS = true;
|
||||
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
||||
//PelletOptions.USE_INCREMENTAL_DELETION = true;
|
||||
|
||||
PelletListener pelletListener = new PelletListener(tboxUnionModel,tboxAssertionsModel,tboxInferencesModel,ReasonerConfiguration.DEFAULT);
|
||||
sce.getServletContext().setAttribute("pelletListener",pelletListener);
|
||||
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
|
||||
|
||||
if (wadf instanceof WebappDaoFactoryJena) {
|
||||
((WebappDaoFactoryJena) wadf).setPelletListener(pelletListener);
|
||||
}
|
||||
|
||||
log.info("Pellet reasoner connected for the TBox");
|
||||
|
||||
waitForTBoxReasoning(sce);
|
||||
|
||||
// set up simple reasoning for the ABox
|
||||
|
||||
RDFService rdfService = ModelAccess.on(ctx).getRDFService();
|
||||
|
@ -139,23 +103,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
}
|
||||
}
|
||||
|
||||
public static void waitForTBoxReasoning(ServletContextEvent sce)
|
||||
throws InterruptedException {
|
||||
PelletListener pelletListener = (PelletListener) sce.getServletContext().getAttribute("pelletListener");
|
||||
if (pelletListener == null) {
|
||||
return ;
|
||||
}
|
||||
int sleeps = 0;
|
||||
// sleep at least once to make sure the TBox reasoning gets started
|
||||
while ((0 == sleeps) || ((sleeps < 1000) && pelletListener.isReasoning())) {
|
||||
if (((sleeps - 1) % 10) == 0) { // print message at 10 second intervals
|
||||
log.info("Waiting for initial TBox reasoning to complete");
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
sleeps++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
log.info("received contextDestroyed notification");
|
||||
|
@ -209,17 +156,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
return (RecomputeMode) ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the names of the plugin classes classes.
|
||||
*
|
||||
|
@ -278,7 +214,8 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
this.simpleReasoner = simpleReasoner;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
simpleReasoner.recompute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
putReportingPathsIntoSettings(ctx, settings);
|
||||
putNonReportingPathsIntoSettings(ctx, settings);
|
||||
|
||||
SimpleReasonerSetup.waitForTBoxReasoning(sce);
|
||||
PelletReasonerSetup.waitForTBoxReasoning(sce);
|
||||
|
||||
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
||||
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue