SimpleReasoner listening to all abox graphs
This commit is contained in:
parent
101de4614b
commit
964cb1bdb4
3 changed files with 67 additions and 5 deletions
|
@ -0,0 +1,42 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||||
|
|
||||||
|
public class ABoxJenaChangeListener extends JenaChangeListener {
|
||||||
|
|
||||||
|
private HashSet<String> ignoredGraphs = new HashSet<String>();
|
||||||
|
|
||||||
|
public ABoxJenaChangeListener(ModelChangedListener listener) {
|
||||||
|
super(listener);
|
||||||
|
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_INF_MODEL);
|
||||||
|
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
||||||
|
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addedStatement(String serializedTriple, String graphURI) {
|
||||||
|
if (isABoxGraph(graphURI)) {
|
||||||
|
super.addedStatement(serializedTriple, graphURI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removedStatement(String serializedTriple, String graphURI) {
|
||||||
|
if (isABoxGraph(graphURI)) {
|
||||||
|
super.removedStatement(serializedTriple, graphURI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isABoxGraph(String graphURI) {
|
||||||
|
return (graphURI == null ||
|
||||||
|
JenaDataSourceSetupBase.JENA_DB_MODEL.equals(graphURI)
|
||||||
|
|| (!ignoredGraphs.contains(graphURI)
|
||||||
|
&& !graphURI.contains("filegraph")
|
||||||
|
&& !graphURI.contains("tbox")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -39,8 +39,12 @@ import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ABoxJenaChangeListener;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.CumulativeDeltaModeler;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.CumulativeDeltaModeler;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows for real-time incremental materialization or retraction of RDFS-
|
* Allows for real-time incremental materialization or retraction of RDFS-
|
||||||
|
@ -53,6 +57,7 @@ public class SimpleReasoner extends StatementListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(SimpleReasoner.class);
|
private static final Log log = LogFactory.getLog(SimpleReasoner.class);
|
||||||
|
|
||||||
|
private RDFService rdfService;
|
||||||
private OntModel tboxModel; // asserted and inferred TBox axioms
|
private OntModel tboxModel; // asserted and inferred TBox axioms
|
||||||
private OntModel aboxModel; // ABox assertions
|
private OntModel aboxModel; // ABox assertions
|
||||||
private Model inferenceModel; // ABox inferences
|
private Model inferenceModel; // ABox inferences
|
||||||
|
@ -78,10 +83,13 @@ public class SimpleReasoner extends StatementListener {
|
||||||
* @param inferenceRebuildModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
* @param inferenceRebuildModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
||||||
* @param inferenceScratchpadModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
* @param inferenceScratchpadModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
||||||
*/
|
*/
|
||||||
public SimpleReasoner(OntModel tboxModel, OntModel aboxModel, Model inferenceModel,
|
public SimpleReasoner(OntModel tboxModel, RDFService rdfService, Model inferenceModel,
|
||||||
Model inferenceRebuildModel, Model scratchpadModel) {
|
Model inferenceRebuildModel, Model scratchpadModel) {
|
||||||
|
this.rdfService = rdfService;
|
||||||
this.tboxModel = tboxModel;
|
this.tboxModel = tboxModel;
|
||||||
this.aboxModel = aboxModel;
|
this.aboxModel = ModelFactory.createOntologyModel(
|
||||||
|
OntModelSpec.OWL_MEM, ModelFactory.createModelForGraph(
|
||||||
|
new RDFServiceGraph(rdfService)));
|
||||||
this.inferenceModel = inferenceModel;
|
this.inferenceModel = inferenceModel;
|
||||||
this.inferenceRebuildModel = inferenceRebuildModel;
|
this.inferenceRebuildModel = inferenceRebuildModel;
|
||||||
this.scratchpadModel = scratchpadModel;
|
this.scratchpadModel = scratchpadModel;
|
||||||
|
@ -90,8 +98,16 @@ public class SimpleReasoner extends StatementListener {
|
||||||
aBoxDeltaModeler1 = new CumulativeDeltaModeler();
|
aBoxDeltaModeler1 = new CumulativeDeltaModeler();
|
||||||
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
aBoxDeltaModeler2 = new CumulativeDeltaModeler();
|
||||||
stopRequested = false;
|
stopRequested = false;
|
||||||
|
|
||||||
aboxModel.getBaseModel().register(this);
|
if (rdfService == null) {
|
||||||
|
aboxModel.register(this);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
rdfService.registerListener(new ABoxJenaChangeListener(this));
|
||||||
|
} catch (RDFServiceException e) {
|
||||||
|
throw new RuntimeException("Unable to register change listener", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
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.dao.jena.pellet.PelletListener;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ReasonerConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ReasonerConfiguration;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
||||||
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||||
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasonerTBoxListener;
|
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasonerTBoxListener;
|
||||||
|
@ -101,7 +103,9 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
|
|
||||||
// the simple reasoner will register itself as a listener to the ABox assertions
|
// the simple reasoner will register itself as a listener to the ABox assertions
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(unionOms.getTBoxModel(), assertionsOms.getABoxModel(), inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx).getRDFService();
|
||||||
|
SimpleReasoner simpleReasoner = new SimpleReasoner(
|
||||||
|
unionOms.getTBoxModel(), rdfService, inferencesOms.getABoxModel(), rebuildModel, scratchModel);
|
||||||
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
||||||
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue