Re: example of RSP-QL query to kick-off the RSP-QL syntax discussion

Hi, All!

Many thanks to Emanuele for a fun and interesting example! I got the impression from the last telco that another version is on the way, but nevertheless I wanted to see how this one would look like in RDF and SPARQL, so I created a version for INSTANS<http://instans.org>. The complete set of queries and sample input and result files are available in the INSTANS github repository<https://github.com/aaltodsg/instans/tree/master/tests/input/rsp/couplecount>.

The queries<https://github.com/aaltodsg/instans/blob/master/tests/input/rsp/couplecount/couplecount_basic_v1.rq> are currently built to count all new couples - from points of interest classified as bars - for whom the following holds true:
- Arrival within 4 hours
- Exit within the same minute
- Were close to each other for 30 minutes or more
- Neither one was close to anyone else for 30 minutes or more
- Neither one knew the other beforehand

I hope this was the correct interpretation of the task. I did not impose any system-wide windowing on the events, as it would have required extra calculations and unnecessarily delayed the results. The current queries are simply filtering based on the event (enters, exits) and state (isCloseTo) timestamps.

I manually created a test file which covers some, but not nearly all the combinations. If anyone is interested, further contributions to the test set are very welcome! :-) I inserted one deliberate error (two persons enter different bars, but are detected close to each other) and a query, which flags this case. Other exception cases (e.g. a person enters one bar and exits another, enters twice without exiting etc.) could be added, depending on how precise monitoring for data integrity is needed.

The incoming events<https://github.com/aaltodsg/instans/blob/master/tests/input/rsp/couplecount/stream1.ttl> look like this:
---
[] a e:enters ;
   e:person :Kim ;
   e:time 1 ;
   e:poi :Gallehault .

[] a e:isCloseTo ;
   e:person :Barney ;
   e:person :Arnold ;
   e:start 9 ;
   e:end 45 .
---
And the results<https://github.com/aaltodsg/instans/blob/master/tests/input/rsp/couplecount/samplerun.ttl> are formatted like this:
---
_:61 e:somebody :Christine;
     e:someoneElse :Mel;
     e:poi :Brewdog;
     :couplecount 2 .
---

I realize this exercise doesn't contribute much to the creation of new query language extensions, but maybe it can serve as one candidate for comparison during development.

BR,

Mikko

--
Mikko Rinne<https://people.aalto.fi/index.html#mikko_rinne>


On 17. Nov 2014, at 21:25, Emanuele Della Valle <emanuele.dellavalle@polimi.it<mailto:emanuele.dellavalle@polimi.it>> wrote:

Hi all,

following a proposal of Oscar I put the query on github https://github.com/streamreasoning/RSP-QL

In this way we can comment on specific lines by forking and doing a pull request.

Cheers,

Emanuele


On 14 Nov 2014, at 21:18, Emanuele Della Valle <emanuele.dellavalle@polimi.it<mailto:emanuele.dellavalle@polimi.it>> wrote:

Hi all,

as promised during today phone-call, I prepared an example of RSP-QL query to kick-off the RSP-QL syntax discussion.

Please find it here: https://www.w3.org/community/rsp/wiki/Example_of_RSP-QL_query

I’m also putting it hereafter just in case you want to directly comment it.

Cheers,

Emanuele

——8——

This query continuously look for bars where people are falling in love like Paolo and Francesca in Dante's Divine Comedy<http://en.wikipedia.org/wiki/Francesca_da_Rimini#In_Inferno> because of a book by Gallehault<http://en.wikipedia.org/wiki/Galehaut>.

PREFIX e: <http://somevocabulary.org/>
PREFIX s: <http://someinvasivesensornetwork.org/streams#>
PREFIX g: <http://somesocialnetwork.org/graphs#>
PREFIX : <http://acrasycompany.org/rsp>
REGISTER STREAM :GallehaultWasTheBar
UNDER ENTAILMENT REGIME <http://www.w3.org/ns/entailment/RIF>
AS
FROM STREAM s:1
FROM NAMED STREAM s:1 [RANGE PT1H STEP PT5M] AS :longWindow
FROM NAMED STREAM s:1 [RANGE PT10M STEP PT5M] AS :shortWindow
FROM NAMED GRAPH g:SocialGraph
FROM GRAPH g:POIs
CONSTRUCT ISTREAM {
 ?poi rdf:type :Gallehault ;
      :count ?howmanycouples ;
      :for (?somebody ?someoneelse)
}
WHERE {
 ?poi rdf:type e:bar .
 STREAM s:1 {
     { ?somebody e:enters ?poi }
     SEQ
     { ?someoneelse ex:enters ?poi } WITHIN PT4H
 }
 WINDOW :longWindow {
     { ?somebody e:isCloseTo ?someoneelse
       MINUS { ?somebody e:sitsWith ?yetanotherone . FILTER (?yetanotherone != ?someoneelse) }
     } WITH DURATION ?longtime
     FILTER (?longtime>"PT30M"^^xsd:duration)
 }
 WINDOW :shortWindow {
     { ?somebody e:exits ?bar} AT ?t1
     { ?someoneelse e:exits ?bar } AT ?t2
     FILTER (abs(?t2-?t1)<"PT1M"^^xsd:duration )
 }
 GRAPH g:1 {
     FILTER NOT EXIST { ?somebody e:knows ?someoneelse }
 }
 FILTER (?somebody != ?someoneelse)
}
AGGREGATE {
 GROUP BY ?bar
 COUNT(?somebody) AS ?howmanycouples
}


The query checks :

  *   over the default graph containing the points of interest (POIs) of http://somesocialnetwork.org/ that the POI is a bar.
  *   over the entire stream from http://someinvasivesensornetwork.org<http://someinvasivesensornetwork.org/>, that pairs of people entered in the poi in different moments within 4 hours.
  *   over the same stream, with a long lasting time window of 1 hour, that pairs of those people have been staying close by for at least 30 minutes. Note: that this may require some resoning being the property isCloseBy symmetric.
  *   over the same stream but with a short time window of 10 minutes, that the same pairs exit together.

As output, for each bar, it streams out an RDF graph with the list of pairs and the total number of pairs that felt in love at each query evaluation.

Note that this example query covers features of C-SPARQL, CQELS, SPARQL-Stream, EP-SPARQL as well as new features missing in all RSP languages:

  *    From C-SPARQL it takes the REGISTER clause, the FROM STREAM clause as dataset clause, the AT clause to access the timestamp (in C-SPARQL, AT is implemented with the timestamp() function) and the aggregates (which are computed in parallel without shrinking the result set, but extending it).
  *   From CQELS it takes the idea of the STREAM keyword in the WHERE clause.
  *   From SPARQL-Stream it takes the ISTREAM clasue that ask the RSP engine to use the R2S operator.
  *   From EP-SPARQL, it takes the SEQ and the WITH DURATION clauses (in EP-SPARQL, WITHIN DURATION is implemented with the getDuration() function).

The new features are:

  *   the usage of an IRI tuo identify the query (and its stream of results)
  *   the optional UNDER ENTAILMENT REGIME clause
  *   the FROM NAMED STREAM <<stream iri>> <<window>> AS << window name>> clause in the dataset declaration
  *   the WINDOW keyword in the WHERE clause

--
Emanuele Della Valle
DEIB - Politecnico di Milano
w. http://emanueledellavalle.org<http://emanueledellavalle.org/>

Received on Wednesday, 10 December 2014 05:01:52 UTC