Commit ba4e94d2 authored by Giustozzi Franco's avatar Giustozzi Franco
Browse files

global update

parent c0da0227
......@@ -73,6 +73,18 @@ public class Example {
//Configure log4j logger for the csparql engine
PropertyConfigurator.configure("log4j_configuration/csparql_readyToGoPack_log4j.properties");
//create a new instance of the api manager
//RSP_services_csparql_API api = new RSP_services_csparql_API("http://localhost:8175");
//Register new stream in the engine
//api.registerStream("http://streamreasoning.org/streams/rfs");
//Thread rfsThread = new Thread(rfs);
//Register new query in the engine
//String queryURI = api.registerQuery("IsInFs", queryBody);
//Attach a result consumer to the query result proxy to print the results on the console
//api.addObserver(queryURI, "http://localhost:8178/results");
//Start the thread that put the triples in the engine
//rfsThread.start();
//Create csparql engine instance
CsparqlEngineImpl engine = new CsparqlEngineImpl();
......
/*******************************************************************************
* Copyright 2014 Davide Barbieri, Emanuele Della Valle, Marco Balduini
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Acknowledgements:
*
* This work was partially supported by the European project LarKC (FP7-215535)
* and by the European project MODAClouds (FP7-318484)
******************************************************************************/
package srOntoInd4;
import it.polimi.deib.csparql_rest_api.RSP_services_csparql_API;
import srOntoInd4.streamer.RemoteFoursquareStreamer;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SR4LD2014_Ex1_rsp {
private static Logger logger = LoggerFactory.getLogger(SR4LD2014_Ex1_rsp.class);
/*
* Example 1 rsp: usage of remote instance of csparql engine using the java api for calling the rsp implementation for csparql engine
*/
public static void main(String[] args) {
try{
//Configure log4j logger for the csparql engine
PropertyConfigurator.configure("log4j_configuration/csparql_readyToGoPack_log4j.properties");
//create a new instance of the api manager
RSP_services_csparql_API api = new RSP_services_csparql_API("http://localhost:8175");
String queryBody = "REGISTER STREAM IsInFs AS "
+ "PREFIX : <http://www.streamreasoning.org/ontologies/sr4ld2014-onto#> "
+ "CONSTRUCT { ?person :isIn ?room } "
+ "FROM STREAM <http://streamreasoning.org/streams/rfs> [RANGE 10s STEP 1s] "
+ "WHERE { "
+ "?person :posts [ :who ?person ; :where ?room ] "
+ "}";
RemoteFoursquareStreamer rfs = new RemoteFoursquareStreamer(api,"http://streamreasoning.org/streams/rfs", "http://www.streamreasoning.org/ontologies/sr4ld2014-onto#", 1000L);
//Register new stream in the engine
api.registerStream("http://streamreasoning.org/streams/rfs");
Thread rfsThread = new Thread(rfs);
//Register new query in the engine
String queryURI = api.registerQuery("IsInFs", queryBody);
//Attach a result consumer to the query result proxy to print the results on the console
api.addObserver(queryURI, "http://localhost:8178/results");
//Start the thread that put the triples in the engine
rfsThread.start();
}catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
/*******************************************************************************
* Copyright 2014 Davide Barbieri, Emanuele Della Valle, Marco Balduini
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Acknowledgements:
*
* This work was partially supported by the European project LarKC (FP7-215535)
* and by the European project MODAClouds (FP7-318484)
******************************************************************************/
package srOntoInd4.streamer;
import it.polimi.deib.csparql_rest_api.RSP_services_csparql_API;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
public class RemoteFoursquareStreamer implements Runnable {
private RSP_services_csparql_API csparqlAPI;
private String streamName;
private long sleepTime;
private String baseUri;
private boolean keepRunning = true;
private Logger logger = LoggerFactory.getLogger(RemoteFoursquareStreamer.class.getName());
public RemoteFoursquareStreamer(RSP_services_csparql_API csparqlAPI, String iri, String baseUri, long sleepTime) {
super();
this.csparqlAPI = csparqlAPI;
this.streamName = iri;
this.sleepTime = sleepTime;
this.baseUri = baseUri;
}
public void run() {
Model m;
Random random = new Random();
int senderIndex;
int roomIndex;
int postIndex;
while(keepRunning){
try {
senderIndex = random.nextInt(5);
roomIndex = random.nextInt(5);
postIndex = random.nextInt(Integer.MAX_VALUE);
m = ModelFactory.createDefaultModel();
m.add(new ResourceImpl(baseUri + "person" + senderIndex), new PropertyImpl(baseUri + "posts"), new ResourceImpl(baseUri + "post" + postIndex));
m.add(new ResourceImpl(baseUri+"post" + postIndex), new PropertyImpl(baseUri + "who"), new ResourceImpl(baseUri + "person" + senderIndex));
m.add(new ResourceImpl(baseUri+"post" + postIndex), new PropertyImpl(baseUri + "where"), new ResourceImpl(baseUri + "room" + roomIndex));
csparqlAPI.feedStream(streamName, m);
Thread.sleep(sleepTime);
} catch (Exception e) {
logger.error("Error while launching the sleep operation", e);
}
}
}
public void stopStream(){
keepRunning = false;
}
}
......@@ -48,7 +48,7 @@ public class SensorsStreamer extends RdfStream implements Runnable {
int observationIndex = 0;
int timeIndex = 0;
String ontologyURI = "http://onto";
String ontologyURI = "http://semanticweb.org/STEaMINg/ContextOntology-COInd4";
String ns = ontologyURI + "#";
String pre_SOSAOnt = "http://www.w3.org/ns/sosa/";
String pre_TIME = "http://www.w3.org/2006/time#";
......@@ -67,10 +67,7 @@ public class SensorsStreamer extends RdfStream implements Runnable {
while(true){
try{
result = random.nextInt(5);
//ZonedDateTime zdt = ZonedDateTime.now();
//java.util.Date date = java.util.Date.from( zdt.toInstant() );
Timestamp date = new Timestamp(System.currentTimeMillis());
//observationIndex = random.nextInt(Integer.MAX_VALUE);
//RdfQuadruple q = new RdfQuadruple(baseUri + "M", baseUri + "hosts", baseUri + "sensorTM", System.currentTimeMillis());
//System.out.println(q);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment