Skip to content

Commit bdd9826

Browse files
authored
updated readme
1 parent d519a14 commit bdd9826

File tree

1 file changed

+55
-65
lines changed

1 file changed

+55
-65
lines changed

README.md

+55-65
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,70 @@
11
# RSP-SPIN Modeling Vocabulary
22

3-
This is the RSP-QL extension of the SPIN modeling vocabulary, which enables RSP-QL queries (see [link](https://github.com/streamreasoning/RSP-QL)) to be represented as RDF. In combination with the provided API queries can be converted to and from RDF, as well as support parameterization of queries into reusable query templates.
3+
This is the RSP-QL extension of the SPIN modeling vocabulary, which enables RSP-QL queries (see [link](https://github.com/streamreasoning/RSP-QL)) to be represented as RDF. In combination with the provided API queries can be converted to and from RDF, and queries can be parameterized into reusable query templates that support parameter constraints.
44

55
Below is a sample query demonstrating how an RSP-QL query would be represented as RDF:
66
```
7-
# Sample query 1 (https://github.com/streamreasoning/RSP-QL)
8-
# Get the number of taxi rides that exceeded 2 miles in the last hour.
7+
# Based on sample query 1 (https://github.com/streamreasoning/RSP-QL)
8+
# Get the number of taxi rides that exceeded ?limit miles in the last hour.
99
PREFIX : <http://debs2015.org/streams/>
10-
PREFIX debs: <http://debs2015.org/onto#>
10+
PREFIX onto: <http://debs2015.org/onto#>
1111
12-
REGISTER STREAM :rideCount AS
12+
REGISTER STREAM ?outputStream AS
1313
14-
SELECT (count(?ride) AS ?rideCount)
15-
FROM NAMED WINDOW :wind ON :trips [RANGE PT1H STEP PT1H]
14+
SELECT ISTREAM (COUNT(?ride) AS ?rideCount)
15+
FROM NAMED WINDOW :wind ON ?inputStream [RANGE PT1H STEP PT1H]
1616
WHERE
1717
{ WINDOW :win
18-
{ ?ride debs:distance ?distance
19-
FILTER ( ?distance > 2 )
18+
{ ?ride onto:distance ?distance
19+
FILTER ( ?distance > ?limit )
2020
}
2121
}
2222
```
2323
Using the RSP-SPIN modeling vocabulary it would be represented in RDF as:
2424
```
25-
@prefix : <http://debs2015.org/streams/> .
2625
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
27-
@prefix debs: <http://debs2015.org/onto#> .
2826
@prefix sp: <http://spinrdf.org/sp#> .
2927
@prefix rsp: <http://w3id.org/rsp/spin#> .
3028
31-
[ a sp:Select ;
32-
rsp:registerAs :rideCount ;
33-
rsp:fromNamedWindow [ a rsp:LogicalWindow ;
34-
rsp:range "PT1H"^^xsd:duration ;
35-
rsp:logicalStep "PT1H"^^xsd:duration ;
36-
rsp:streamIri :trips ;
37-
rsp:windowIri :wind
38-
] ;
39-
sp:resultVariables ( [ sp:expression [ a sp:Count ;
40-
sp:expression [ sp:varName "ride"^^xsd:string ]
41-
] ;
42-
sp:varName "rideCount"^^xsd:string
43-
] ) ;
44-
sp:where ( [ a rsp:NamedWindow ;
45-
sp:elements ( [ sp:object [ sp:varName "distance"^^xsd:string ] ;
46-
sp:predicate debs:distance ;
47-
sp:subject [ sp:varName "ride"^^xsd:string ]
48-
] [ a sp:Filter ;
49-
sp:expression [ a sp:gt ;
50-
sp:arg1 [ sp:varName "distance"^^xsd:string ] ;
51-
sp:arg2 2
52-
]
53-
] ) ;
54-
rsp:windowNameNode :win
55-
] ) .
56-
```
29+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
30+
@prefix sp: <http://spinrdf.org/sp#> .
31+
@prefix rsp: <http://w3id.org/rsp/spin#> .
5732
58-
Now, let's assume we wish to use this query to create a template that allows us to specify the distance to filter on as a query template parameter. We modify the query slightly, replacing ```FILTER ( ?distance > 2 )``` with ```FILTER ( ?distance > ?limit )``` and to make the template even more flexible let's assume that we also replace the name of the output stream (```:rideCount```) and input stream (```:trips```) with the variables ```?input``` and ```?output```.
59-
```
60-
# Modifed query
61-
# Get the number of taxi rides that exceeded a certain distance in miles in the last hour.
62-
PREFIX : <http://debs2015.org/streams/>
63-
PREFIX debs: <http://debs2015.org/onto#>
33+
<http://example.org/query/1>
34+
a sp:Select ;
35+
rsp:hasOutputStream [ sp:varName "outputStream" ] ;
36+
rsp:hasOutputStreamOperator rsp:Istream
37+
sp:resultVariables ( _:b0 ) ;
38+
rsp:fromNamedWindow [ a rsp:LogicalWindow ;
39+
rsp:logicalRange "PT1H"^^xsd:duration ;
40+
rsp:logicalStep "PT1H"^^xsd:duration ;
41+
rsp:streamUri [ sp:varName "inputStream" ] ;
42+
rsp:windowUri <http://debs2015.org/streams/wind>
43+
] ;
44+
sp:where ( _:b1 )
45+
.
6446
65-
REGISTER STREAM ?output AS
47+
_:b0 sp:expression [ a sp:Count ;
48+
sp:expression [ sp:varName "ride" ]
49+
] ;
50+
sp:varName "rideCount" .
6651
67-
SELECT (count(?ride) AS ?rideCount)
68-
FROM NAMED WINDOW :wind ON ?input [RANGE PT1H STEP PT1H]
69-
WHERE
70-
{ WINDOW :win
71-
{ ?ride debs:distance ?distance
72-
FILTER ( ?distance > ?limit )
73-
}
74-
}
52+
_:b1 a rsp:NamedWindow ;
53+
sp:elements ( _:b3 _:b2 ) ;
54+
rsp:windowNameNode <http://debs2015.org/streams/win> .
55+
56+
_:b2 a sp:Filter ;
57+
sp:expression [ a sp:gt ;
58+
sp:arg1 [ sp:varName "distance" ] ;
59+
sp:arg2 [ sp:varName "limit" ]
60+
] .
61+
62+
_:b3 sp:subject [ sp:varName "ride" ] ;
63+
sp:predicate <http://debs2015.org/onto#distance> ;
64+
sp:object [ sp:varName "distance" ] .
7565
```
76-
We can now specify a template over the query, and we can instantiate it multiple time with different sets of bindings for the three parameters (```spl:Argument```):
66+
67+
Now, let's use define a template over this query allowing us to specify the ```limit``` variable of the query as an integer with a default value, and require that the ```inputStream``` and ```outputStream``` are provided as URIs.
7768
```
7869
@prefix : <http://debs2015.org/streams/> .
7970
@prefix spin: <http://spinrdf.org/spin#> .
@@ -84,7 +75,7 @@ We can now specify a template over the query, and we can instantiate it multiple
8475
@prefix spl: <http://spinrdf.org/spl#> .
8576
8677
:t1 a spin:Template ;
87-
spin:body :q1 ;
78+
spin:body <http://example.org/query/1> ;
8879
spin:constraint [ a spl:Argument ;
8980
rdfs:comment "Get the taxi rides that exceeded this limit in the last hour." ;
9081
spl:defaultValue 2 ;
@@ -94,18 +85,17 @@ We can now specify a template over the query, and we can instantiate it multiple
9485
] ;
9586
spin:constraint [ a spl:Argument ;
9687
rdfs:comment "Represents the URI identifier of the input stream." ;
97-
spl:optional false ;
98-
spl:predicate arg:input ;
99-
spl:valueType rdfs:Resource
100-
] ;
101-
spin:constraint [ a spl:Argument ;
102-
rdfs:comment "Represents the URI identifier of the resulting stream." ;
103-
spl:optional false ;
104-
spl:predicate arg:output ;
105-
spl:valueType rdfs:Resource
106-
] .
88+
spl:optional false ;
89+
spl:predicate arg:inputStream ;
90+
spl:valueType rdfs:Resource
91+
] ;
92+
spin:constraint [ a spl:Argument ;
93+
rdfs:comment "Represents the URI identifier of the resulting stream." ;
94+
spl:optional false ;
95+
spl:predicate arg:outputStream ;
96+
spl:valueType rdfs:Resource
97+
] .
10798
```
10899

109100

110101
See <http://spinrdf.org/spin.html> for details about the SPIN Modeling Vocabulary.
111-

0 commit comments

Comments
 (0)