Morph-streams: SPARQLStream OBDA in action Jean-Paul Calbimonte - - PowerPoint PPT Presentation

morph streams sparqlstream obda in action
SMART_READER_LITE
LIVE PREVIEW

Morph-streams: SPARQLStream OBDA in action Jean-Paul Calbimonte - - PowerPoint PPT Presentation

Stream Reasoning for Linked Data M. Balduini, J-P Calbimonte, O. Corcho, D. Dell'Aglio, E. Della Valle http://streamreasoning.org/events/sr4ld2014 Morph-streams: SPARQLStream OBDA in action Jean-Paul Calbimonte Jean-paul.calbimonte@epfl.ch


slide-1
SLIDE 1

Stream Reasoning for Linked Data

  • M. Balduini, J-P Calbimonte, O. Corcho,
  • D. Dell'Aglio, E. Della Valle

http://streamreasoning.org/events/sr4ld2014

Morph-streams: SPARQLStream OBDA in action

Jean-Paul Calbimonte

Jean-paul.calbimonte@epfl.ch Lsir.epfl.ch

slide-2
SLIDE 2

http://streamreasoning.org/events/sr4ld2014

Share, Remix, Reuse — Legally

§ This work is licensed under the Creative Commons Attribution 3.0 Unported License. § You are free:

  • to Share — to copy, distribute and transmit the work
  • to Remix — to adapt the work

§ Under the following conditions

  • Attribution — You must attribute the work by inserting

– “[source http://streamreasoning.org/events/sr4ld2014]” at the end of each reused slide – a credits slide stating

  • These slides are partially based on “Streaming Reasoning for Linked

Data 2014” by M. Balduini, J-P Calbimonte, O. Corcho, D. Dell'Aglio, and E. Della Valle, http://streamreasoning.org/events/sr4ld2014

§ To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/

2

slide-3
SLIDE 3

http://streamreasoning.org/events/sr4ld2014

Querying RDF Streams

3 +streams Existing streaming data sources

RDF Stream DSMS CEP Sensor middleware … RDF Stream Processor

users, applications query processing

Where is the data coming from?

Wrap Import Load Continously

+streams

Streams already exist in non-RDF form

slide-4
SLIDE 4

http://streamreasoning.org/events/sr4ld2014

Feed the RDF Stream: Scenarios

4 bob,room1,t1 carl,room1,t2 carl,room2,t3 … … :bob rsp:where :room1 [t1] :carl rsp:where :room1 [t2] :carl rsp:where :room2 [t3]

RDF Stream Processor

:/person/bob rsp:where :room1 [t1] … :person/bob rsp:where :room1 [t1] :person/bob rsp:observedBy :sensor1 [t1] :obst1 a ssn:Observation [t1] :obst1 ssn:observedBy :sensor1 [t1] :obst1 ssn:featureOfInterest :bob [t1] :obst1 ssn:observedValue :room1 [t1] …

Stream

generated by a Sensor

Different RDF representations Dynamic structural changes Multiple RDF views over the same stream

slide-5
SLIDE 5

http://streamreasoning.org/events/sr4ld2014

+streams

Virtual RDF views over data streams

5

SPARQLStream

Virtual RDF Stream DSMS CEP Sensor middleware … rewritten queries

users, applications query processing

RDF Stream Processor

Morph-streams

data layer

slide-6
SLIDE 6

http://streamreasoning.org/events/sr4ld2014

Already seen somewhere…?

6

RDF DBMS Load, import SPARQL Query Processor R2RML Mappings

Similar to RDB2RDF Stream DBMS? Stream SQL?

slide-7
SLIDE 7

http://streamreasoning.org/events/sr4ld2014

Stream Processor Implementations

7

Data Stream Management Systems (DSMS) Complex Event Processors (CEP) Stream Data Middleware

CQL/Stream Borealis TelegraphCQ StreamMill Cayuga GEM CEDR NiagaraCQ Rapide Cosm Hourglass SStreamWare GSN IBM InfoSphere Sybase CEP Microsoft StreamInsight Oracle CEP Esper StreamBase

Diverse query languages Different query capabilities Different query models

slide-8
SLIDE 8

http://streamreasoning.org/events/sr4ld2014

Morph-streams: Overview

8

Query rewriting Query Processing Client

SPARQLStream [tuples] [triples/ bindings] Algebra expression

R2RML Mappings

Morph-streams procesing SPARQLStream queries

SELECT ?proximity FROM STREAM <http://streamreasoning.org/

SensorReadings.srdf> [NOW–5 S]

WHERE { ?obs a ssn:ObservationValue; qudt:numericalValue ?proximity; FILTER (?proximity>10) } SELECT prox FROM sens.win:time(5 sec) WHERE prox >10

π

timed,prox

ω σprox>10

5 Seconds

sens

Data translation SNEE Esper GSN Cosm

pull/push

https://github.com/jpcik/morph-streams

Other

slide-9
SLIDE 9

http://streamreasoning.org/events/sr4ld2014

What do I need for Morph-streams

§ Main ingredients:

9

  • 1. Data streams
  • 2. Ontology
  • 3. R2RML mappings

Link both models

slide-10
SLIDE 10

http://streamreasoning.org/events/sr4ld2014

1st: the data streams

10

(person,room,…)

τi

(bob,room2) τi (alice,room1) τi-­‑1 (alice,room3) τi+1 stream

. . .

(carl,room1) τi (luke,room1) τi+1 . . .

. . .

stream tuples

DSMS, CEP, middleware can evaluate queries over this model

Stream Schema

slide-11
SLIDE 11

http://streamreasoning.org/events/sr4ld2014

2nd: An Ontology!

11

W3C SSN Ontology modeling our streaming data combine with domain ontologies

slide-12
SLIDE 12

http://streamreasoning.org/events/sr4ld2014

Or our simpler ontology…

12

Observation Sensor Person Post Room where discusses who

  • bserves

subClassOf subClassOf authorOf subPropOf

We can use different ontologies for the same data

slide-13
SLIDE 13

http://streamreasoning.org/events/sr4ld2014

3rd: Mapping the two models

13

Observation Sensor Person Room where who

  • bserves

subClassOf

(person, ¡ ¡room,…) detec4ons Define mappings

slide-14
SLIDE 14

http://streamreasoning.org/events/sr4ld2014

R2RML – There is a recommendation!

14

We can use the W3C recommendation

slide-15
SLIDE 15

http://streamreasoning.org/events/sr4ld2014

R2RML - Overview

15

slide-16
SLIDE 16

http://streamreasoning.org/events/sr4ld2014

Encoding in R2RML

16

:triplesMap a rr:TriplesMap; rr:logicalTable [ rr:tableName ”sensors"; ] rr:subjectMap [ rr:template "http://streamreasoning.org/data/Observation/{person}{timed}"; rr:class sr4ld:Observation; rr:graph sr4ld:socialstream.srdf ]; rr:predicateObjectMap [ rr:predicate sr4ld:who ; rr:objectMap [ rr:template “http://streamreasoning.org/data/Person/{person}” ]];.

the stream name

subject URI triple predicate + object Mapping definition

stream attributes

the object (a URI in this case)

slide-17
SLIDE 17

http://streamreasoning.org/events/sr4ld2014

Morph-streams: Overview

17

Query rewriting Query Processing Client

SPARQLStream [tuples] [triples/ bindings] Algebra expression

R2RML Mappings

Morph-streams procesing SPARQLStream queries

SELECT ?proximity FROM STREAM <http://streamreasoning.org/

SensorReadings.srdf> [NOW–5 S]

WHERE { ?obs a ssn:ObservationValue; qudt:numericalValue ?proximity; FILTER (?proximity>10) } SELECT prox FROM sens.win:time(5 sec) WHERE prox >10

π

timed,prox

ω σprox>10

5 Seconds

sens

Data translation SNEE Esper GSN Cosm

pull/push

https://github.com/jpcik/morph-streams

Other

slide-18
SLIDE 18

http://streamreasoning.org/events/sr4ld2014

SPARQLStream Language

18

FROM NAMED STREAM ISTREAM DSTREAM RSTREAM WINDOW Underlying data source restrictions

slide-19
SLIDE 19

http://streamreasoning.org/events/sr4ld2014

SPARQLStream Language

§ NamedStream à ‘FROM’ [‘NAMED’] ‘STREAM’ StreamIRI ‘[’ Window ‘]’ § Window à ‘NOW-’ Integer TimeUnit [UpperBound] [Slide] § UpperBound à ‘TO NOW-’ Integer TimeUnit § Slide à ‘SLIDE’ Integer TimeUnit § TimeUnit à ‘MS’ | ‘S’ | ‘MINUTES’| ‘HOURS’ | ‘DAY’ § Select à ‘SELECT’ [Xstream] [Distinct | Reduced] … § Xstream à ‘RSTREAM’ | ‘ISTREAM’ | ‘DSTREAM’

19

SELECT ISTREAM ?room FROM NAMED STREAM <http://www.streamreasoning.org/streams/socialsensor.srdf> [NOW-10 S] WHERE {…

slide-20
SLIDE 20

http://streamreasoning.org/events/sr4ld2014

SPARQLStream: examples

20

PREFIX sr4ld: <http://www.streamreasoning.org/ontologies/socialsensor,owl#> SELECT ?room FROM NAMED STREAM <http://www.streamreasoning.org/streams/socialsensor.srdf> [NOW-10 S] WHERE { ?obs sr4ld:observedBy ?sensor. ?obs sr4ld:where ?room. }

SPARQLStream

All rooms where something was observed in the last 10s

PREFIX sr4ld: <http://www.streamreasoning.org/ontologies/socialsensor,owl#> SELECT (COUNT(?person) AS ?nmb) ?room FROM NAMED STREAM <http://www.streamreasoning.org/streams/socialsensor.srdf> [NOW-10 S] WHERE { ?obs sr4ld:who ?pers. ?obs sr4ld:where ?room. } GROUP BY ?room

Number of persons observed in each room in the last 10s

slide-21
SLIDE 21

http://streamreasoning.org/events/sr4ld2014

Morph-streams: Overview

21

Query rewriting Query Processing Client

SPARQLStream [tuples] [triples/ bindings] Algebra expression

R2RML Mappings

Morph-streams procesing SPARQLStream queries

SELECT ?proximity FROM STREAM <http://streamreasoning.org/

SensorReadings.srdf> [NOW–5 S]

WHERE { ?obs a ssn:ObservationValue; qudt:numericalValue ?proximity; FILTER (?proximity>10) } SELECT prox FROM sens.win:time(5 sec) WHERE prox >10

π

timed,prox

ω σprox>10

5 Seconds

sens

Data translation SNEE Esper GSN Cosm

pull/push

https://github.com/jpcik/morph-streams

Other

slide-22
SLIDE 22

http://streamreasoning.org/events/sr4ld2014

Underlying Query Processors

Esper

  • CEP/DSMS
  • EPL language

SNEE

  • DSMS/Sensor Network Query Evaluator
  • Compile queries to sensor code

GSN

  • Sensor middleware
  • REST API

Cosm/Xively

  • Sensor middleware
  • Open platform
  • REST API

22

SELECT prox FROM sensors [FROM NOW-5 MINUTES TO NOW] WHERE prox >10 SELECT prox FROM sensors.win:time(5 minute) WHERE prox >10 http://montblanc.slf.ch:22001/ multidata?vs[0]=sensors& field[0]=proximity_field&c_min[0]=10& from=15/05/2012+05:00:00&to=15/05/2012 +10:00:00 http://api.cosm.com/v2/feeds/14321/ datastreams/4? start=2012-05-15T05:00:00Z&end=2012- 05-15T10:00:00Z

slide-23
SLIDE 23

http://streamreasoning.org/events/sr4ld2014

Underlying Query Processors

23

SELECT ?proximity FROM STREAM <http://streamreasoning.org/

SensorReadings.srdf> [NOW–5 S]

WHERE { ?obs a ssn:ObservationValue; qudt:numericalValue ?proximity; FILTER (?proximity>10) } SELECT prox FROM sensors [FROM NOW-5 MINUTES TO NOW] WHERE prox >10 timed, prox

π ω σ

prox>10

5 Seconds

sensors

SELECT prox FROM sensors.win:time(5 minute) WHERE prox >10 http://montblanc.slf.ch:22001/multidata? vs[0]=sensors&field[0]=proximity_field&c_min[0]=10& from=15/05/2012+05:00:00&to=15/05/2012+10:00:00 http://api.cosm.com/v2/feeds/14321/datastreams/4? start=2012-05-15T05:00:00Z&end=2012-05-15T10:00:00Z

Query rewriting

R2RML

SNEE (DSMS) Esper (CEP) GSN (middlwr) Cosm Xively SPARQLStream

slide-24
SLIDE 24

http://streamreasoning.org/events/sr4ld2014

Underlying query processors

Features Esper SNEE GSN Cosm/Xively Projection ✔ ✔ ✔ Fixed Proj expression ✔ ✔ ✖ ✖ Joins ✔ ✔✖ only window ✖ ✖ Union ✖ ✔✖ not windows ✔ ✖ Selection ✔ ✔ ✔ ✖✔ limited Aggregates ✔ ✔ ✔✖ ✖ Time window ✔ ✔ ✔ ✔ Tuple window ✔ ✔ ✔ ✖ R2S ✔ ✔ ✖ ✖ Conjunction, Disj ✔ ✖ ✖ ✖ Repetition pattern ✔ ✖ ✖ ✖ Sequence ✔ ✖ ✖ ✖

24

slide-25
SLIDE 25

http://streamreasoning.org/events/sr4ld2014

Morph-streams: With reasoning!

25

Query rewriting Query Processing Client

SPARQLStream [tuples] [triples/ bindings] Algebra expression

R2RML Mappings

Morph-streams procesing SPARQLStream queries

Data translation SNEE Esper GSN Cosm

pull/push

https://github.com/jpcik/morph-streams

Other Ontology TBox

Rewrite taking into account the ontology TBox

slide-26
SLIDE 26

http://streamreasoning.org/events/sr4ld2014

Reasoning with Morph-streams

§ Rewriting the SPARQLStream queries:

26

SELECT ?x FROM NAMED STREAM <http://linkeddata.es/s/obs.srdf> [NOW - 5 MINUTES] WHERE { ?x ssn:observedBy ?y } SELECT ?x FROM NAMED STREAM <http://linkeddata.es/s/obs.srdf> [NOW - 5 MINUTES] WHERE { {?x ssn:observedBy ?y} UNION {?x a ssn:Observation} UNION {?x a aws:TemperatureObservation} UNION {?x a aws:HumidityObservation} }

slide-27
SLIDE 27

http://streamreasoning.org/events/sr4ld2014

Morph-streams: With reasoning!

27

Query rewriting Query Processing Client

SPARQLStream [tuples] [triples/ bindings] Algebra expression

R2RML Mappings Data translation SNEE Esper GSN Cosm

pull/push

https://github.com/jpcik/morph-streams

Other Ontology TBox

Rewrite only happens once

Query rewriting + translation

Then continuous query is registered

slide-28
SLIDE 28

http://streamreasoning.org/events/sr4ld2014

Now some code

Morph-streams: § Coded in Scala § JAR bundle, use it from Scala or Java code § Maven, Sbt § Examples

  • One off query
  • Register continuous query
  • Pull data
  • Push
  • Basic REST

§ https://github.com/jpcik/morph-streams § https://github.com/jpcik/morph-web

28

slide-29
SLIDE 29

http://streamreasoning.org/events/sr4ld2014

Code examples

§ Parse SPARQLStream val query= “PREFIX sr4ld: <…>. SELECT ?a …”

val syntax= StreamQueryFactory.create(query);

§ Execute One-off query

val query= “PREFIX sr4ld: <…>. SELECT ?a …” mapping=Mapping(new URI(mappings/social.ttl)) val adapter:QueryEvaluator=Application.adapter(system) val results= adapter.executeQuery(query,mapping) 29

Mapping Bindings

slide-30
SLIDE 30

http://streamreasoning.org/events/sr4ld2014

Code examples

§ Register and Pull

val queryid= adapter.registerQuery(query,mapping) val results1=adapter.pull(queryid) val results2=adapter.pull(queryid)

§ Register and Push

class ExampleReceiver extends StreamReceiver{

  • verride def receiveData(s:SparqlResults):Unit=

Logger.debug("got: "+res) } val receiver=new ExampleReceiver val queryid= adapter.listenToQuery(query,mapping,receiver) 30

Query identifier Implement receiver

For Java users: Exactly the same interface!

slide-31
SLIDE 31

http://streamreasoning.org/events/sr4ld2014

SPARQLStream from command line

  • encoded_value=$(python -c "import urllib; print urllib.quote('''SELECT

DISTINCT ?timeto ?obs FROM NAMED STREAM <http:// emt.linkeddata.es/data#busstops.srdf> [NOW - 30 S] WHERE { ?obs a <http://emt.linkeddata.es/data#BusObservation>. ?obs <http:// purl.oclc.org/NET/ssnx/ssn#observedBy><http:// transporte.linkeddata.es/emt/busstop/id/2018>. ?obs <http:// purl.oclc.org/NET/ssnx/ssn#observationResult> ?output. ?output <http://emt.linkeddata.es/data#timeToBusValue> ?av. ?av <http:// data.nasa.gov/qudt/owl/qudt#numericValue> ?timeto. }''')")

  • curl "http://streams.linkeddata.es/emt/sparqlstream?query=

$encoded_value”

31

Disclaimer: Simplistic, not implementing all of the SPARQL protocol

Just encoding query

slide-32
SLIDE 32

http://streamreasoning.org/events/sr4ld2014

Sample result

{ "head": { "vars": [ "timeto" , "obs" ] } , "results": { "bindings": [ { "timeto": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed- literal" , "value": "0" } , "obs": { "type": "uri" , "value": "http://transporte.linkeddata.es/emt/busstop/id/2018/ busline/9/observation/20/09/2013%2010:28:19%20%2B0200" } } ] } } 32

Bindings in JSON

slide-33
SLIDE 33

http://streamreasoning.org/events/sr4ld2014

SPARQLStream

§ Virtual RDF views over data streams § Ontology-based access to data streams

  • Examples
  • Architecture
  • Underlying query processors

§ SPARQLStream language § Query rewriting

  • R2RML mappings

§ Resources

33

slide-34
SLIDE 34

http://streamreasoning.org/events/sr4ld2014

Resources

§ Morph-Streams

  • https://github.com/jpcik/morph-streams

§ See demos

  • http://transporte.linkeddata.es/ (SPARQL-Stream tab)

§ Read out more

  • Enabling Query Technologies for the Semantic Sensor Web.

J.-P. Calbimonte, H. Jeung, O. Corcho and K. Aberer. International Journal on Semantic Web and Information Systems IJSWIS, Volume 8(1)., 2012

§ Contact point

  • jean-paul.calbimonte@epfl.ch
  • corcho@fi.upm.es

34

slide-35
SLIDE 35

Stream Reasoning for Linked Data

  • M. Balduini, J-P Calbimonte, O. Corcho,
  • D. Dell'Aglio, E. Della Valle

http://streamreasoning.org/events/sr4ld2014

Morph-streams: SPARQLStream OBDA in action

Jean-Paul Calbimonte

Jean-paul.calbimonte@epfl.ch Lsir.epfl.ch

slide-36
SLIDE 36

http://streamreasoning.org/events/sr4ld2014

RDF Streams

36

〈s,p,o〉

<aemet:observation1, qudt:hasNumericValue, “15.5”> <aemet:observation1, ssn:observedBy, aemet:Sensor3>

For streams?

(〈s,p,o〉,τ)

(<aemet:observation1, qudt:hasNumericValue, “15.5”>,34532)

timestamped triples

  • Gutierrez et al. (2007) Introducing time into RDF. IEEE TKDE
  • Rodríguez et al. (2009) Semantic management of streaming data. SSN