Skip to content

Adds support for static data #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@
import lombok.Getter;
import lombok.extern.log4j.Log4j;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Triple;
import org.apache.jena.mem.GraphMem;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.rdf.model.impl.InfModelImpl;
import org.apache.jena.reasoner.InfGraph;
import org.apache.jena.reasoner.Reasoner;
import org.apache.jena.reasoner.ReasonerRegistry;
import org.apache.jena.riot.system.IRIResolver;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.graph.GraphFactory;
import org.apache.jena.util.iterator.ExtendedIterator;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -128,9 +131,18 @@ public SDS build() {
InfGraph infGraph = new InfModelImpl(this.reasoner.bind(m.read(g).getGraph())).getInfGraph();
this.sds.add(new TimeVaryingStatic<>(sds, infGraph));
} else {
this.sds.add(new TimeVaryingStatic<>(sds, GraphFactory.createGraphMem()));
Graph staticGraph = GraphFactory.createGraphMem();
// load static data
StmtIterator stmtIt = m.listStatements();
while(stmtIt.hasNext()){
staticGraph.add(stmtIt.nextStatement().asTriple());
}
this.sds.add(new TimeVaryingStatic<>(sds, staticGraph));
}
});
// Remove graph and name graph definitions from query after loading
query.getGraphURIs().clear();
query.getNamedGraphURIs().clear();

Map<String, WebDataStream<Graph>> registeredStreams = stream_registration_service.getRegisteredStreams();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package it.polimi.deib.sr.rsp.esper.engine;

import it.polimi.sr.rsp.csparql.engine.CSPARQLEngine;
import it.polimi.yasper.core.engine.config.EngineConfiguration;
import it.polimi.yasper.core.querying.ContinuousQuery;
import it.polimi.yasper.core.querying.ContinuousQueryExecution;
import it.polimi.yasper.core.sds.SDSConfiguration;
import it.polimi.yasper.core.stream.data.DataStreamImpl;
import it.polimi.yasper.core.stream.data.WebDataStream;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.jena.graph.Graph;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
* Created by Riccardo on 03/08/16.
*/
public class CSPARQLStaticDataExample {

static CSPARQLEngine sr;

public static void main(String[] args) throws InterruptedException, IOException, ConfigurationException {

URL resource = CSPARQLStaticDataExample.class.getResource("/csparql.properties");
SDSConfiguration config = new SDSConfiguration(resource.getPath());
EngineConfiguration ec = EngineConfiguration.loadConfig("/csparql.properties");


sr = new CSPARQLEngine(0, ec);

GraphStream writer = new GraphStream("Artist", "http://differenthost:12134/stream2", 1);

DataStreamImpl<Graph> register = sr.register(writer);

writer.setWritable(register);

ContinuousQueryExecution cqe = sr.register(getQuery(".rspql"), config);

ContinuousQuery query = cqe.getContinuousQuery();

System.out.println(query.toString());

System.out.println("<<------>>");

// if (query.isConstructType()) {
// cqe.add(ResponseFormatterFactory.getConstructResponseSysOutFormatter("JSON-LD", true));
// } else if (query.isSelectType()) {
// cqe.add(ResponseFormatterFactory.getSelectResponseSysOutFormatter("TABLE", true)); //or "CSV" or "JSON" or "JSON-LD"
// }

WebDataStream outputStream = cqe.outstream();

if (outputStream != null)
outputStream.addConsumer((o, l) -> System.out.println(o));

//In real application we do not have to start the stream.
(new Thread(writer)).start();

}

public static String getQuery(String suffix) throws IOException {
URL resource = CSPARQLStaticDataExample.class.getResource("/q52_static" + suffix);
System.out.println(resource.getPath());
File file = new File(resource.getPath());
return FileUtils.readFileToString(file);
}

}
18 changes: 18 additions & 0 deletions jasper/src/test/resources/q52_static.rspql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PREFIX ars: <http://www.streamreasoning/artist#>
PREFIX afn: <http://jena.apache.org/ARQ/function#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX : <http://differenthost:12134/>

REGISTER RSTREAM <out> AS
SELECT *
FROM NAMED WINDOW <win2> ON :stream2 [RANGE PT5S STEP PT0.5S]
FROM <file:///Users/psbonte/Documents/Github/csparql2/jasper/src/test/resources/static.ttl>
WHERE {
?a ars:hasName ?name.
WINDOW ?w {
?a a ars:Artist ;
ars:hasAge ?age .
}

BIND( UUID() as ?uuid )
}
3 changes: 3 additions & 0 deletions jasper/src/test/resources/static.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREFIX ars: <http://www.streamreasoning/artist#>

<http://differenthost:12134/stream2/artist1> ars:hasName "someName".