[TASK] Add QueryContainer class.
This commit is contained in:
@@ -9,16 +9,14 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import eu.larkc.csparql.cep.api.RdfStream;
|
||||
import eu.larkc.csparql.common.utils.CsparqlUtils;
|
||||
import eu.larkc.csparql.common.utils.ReasonerChainingType;
|
||||
import eu.larkc.csparql.core.engine.CsparqlEngine;
|
||||
import eu.larkc.csparql.core.engine.CsparqlEngineImpl;
|
||||
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
|
||||
import eu.larkc.csparql.core.engine.RDFStreamFormatter;
|
||||
import lu.jpt.csparqlproject.gui.FancyTextObserverWindow;
|
||||
import lu.jpt.csparqlproject.misc.QueryContainer;
|
||||
import lu.jpt.csparqlproject.misc.ReasoningTester;
|
||||
import lu.jpt.csparqlproject.rentacar.RentACarSimulation;
|
||||
import lu.jpt.csparqlproject.util.CsparqlQueryHelper;
|
||||
import lu.jpt.csparqlproject.util.CsparqlQueryHelper.CsparqlQueryInfo;
|
||||
|
||||
/**
|
||||
* This class encapsulates the use of the C-SPARQL Engine. Here, the RentACarSimulation,
|
||||
@@ -159,38 +157,39 @@ public class SimulationContext {
|
||||
RdfStream driverStream = simulation.getDriverStream();
|
||||
this.engine.registerStream(driverStream);
|
||||
this.registeredStreams.add(driverStream);
|
||||
Collection<String> queriesToRegister = new ArrayList<String>();
|
||||
Collection<QueryContainer> queriesToRegister = new ArrayList<QueryContainer>();
|
||||
// Collect the queries to use!
|
||||
//queriesToRegister.add(RentACarSimulation.getEventsQuery());
|
||||
queriesToRegister.add(RentACarSimulation.getAverageDataByCarAsStream());
|
||||
queriesToRegister.add(RentACarSimulation.selectFromRegisteredStream());
|
||||
// Now register each query appropriately!
|
||||
for(String query : queriesToRegister) {
|
||||
CsparqlQueryInfo queryInfo = CsparqlQueryHelper.getQueryInfo(query);
|
||||
for(QueryContainer queryContainer : queriesToRegister) {
|
||||
CsparqlQueryResultProxy resultProxy = null;
|
||||
try {
|
||||
resultProxy = this.engine.registerQuery(query, true);
|
||||
this.enableReasoningForResultProxy(resultProxy);
|
||||
resultProxy = this.engine.registerQuery(queryContainer.query, queryContainer.reasoningEnabled);
|
||||
if(queryContainer.reasoningEnabled) {
|
||||
this.enableReasoningForResultProxy(resultProxy, queryContainer);
|
||||
}
|
||||
// Take care of streams and queries differently.
|
||||
if(queryInfo.isStream) {
|
||||
if(queryContainer.isStream) {
|
||||
// If the query is a stream, we need additional components to feed it back into the engine.
|
||||
String streamUri = "http://example.org/stream/"+queryInfo.name;
|
||||
String streamUri = "http://example.org/stream/"+queryContainer.name;
|
||||
RDFStreamFormatter rdfStreamFormatter = new RDFStreamFormatter(streamUri);
|
||||
engine.registerStream(rdfStreamFormatter);
|
||||
resultProxy.addObserver(rdfStreamFormatter);
|
||||
Observer resultObserver = this.createResultObserverWindow(queryInfo.name);
|
||||
Observer resultObserver = this.createResultObserverWindow(queryContainer.name);
|
||||
resultProxy.addObserver(resultObserver);
|
||||
} else {
|
||||
// If it is a regular query, just attach a fitting observer
|
||||
Observer resultObserver = this.createResultObserverWindow(queryInfo.name);
|
||||
Observer resultObserver = this.createResultObserverWindow(queryContainer.name);
|
||||
resultProxy.addObserver(resultObserver);
|
||||
}
|
||||
this.queryResultProxies.add(resultProxy);
|
||||
SimulationContext.logger.info("Successfully registered query " + queryInfo.name + ": " + query);
|
||||
SimulationContext.logger.info("Successfully registered query " + queryContainer.name + ": " + queryContainer);
|
||||
} catch (Exception e) {
|
||||
SimulationContext.logger.error(e.toString());
|
||||
SimulationContext.logger.error("Could not register query "+queryInfo.name);
|
||||
SimulationContext.logger.error(query);
|
||||
SimulationContext.logger.error("Could not register query "+queryContainer.name);
|
||||
SimulationContext.logger.error(queryContainer.query);
|
||||
}
|
||||
}
|
||||
// Setup complete, ready to run.
|
||||
@@ -216,13 +215,19 @@ public class SimulationContext {
|
||||
return observer;
|
||||
}
|
||||
|
||||
private void enableReasoningForResultProxy(CsparqlQueryResultProxy resultProxy) {
|
||||
private void enableReasoningForResultProxy(CsparqlQueryResultProxy resultProxy, QueryContainer queryContainer) {
|
||||
try {
|
||||
engine.updateReasoner(
|
||||
/* If not using the queryContainer, these would be valid parameters:
|
||||
resultProxy.getSparqlQueryId(),
|
||||
CsparqlUtils.fileToString("data/rdfs.rules"),
|
||||
ReasonerChainingType.HYBRID,
|
||||
CsparqlUtils.serializeRDFFile("data/carSimulationTBox.rdf")
|
||||
*/
|
||||
engine.updateReasoner(
|
||||
resultProxy.getSparqlQueryId(),
|
||||
queryContainer.ruleSet,
|
||||
queryContainer.reasonerChainingType,
|
||||
queryContainer.TBox
|
||||
);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user