sparql 3.0.0 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +184 -70
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/bin/sparql +28 -17
- data/lib/rack/sparql.rb +1 -1
- data/lib/rack/sparql/conneg.rb +3 -3
- data/lib/sinatra/sparql.rb +5 -5
- data/lib/sparql.rb +14 -10
- data/lib/sparql/algebra.rb +15 -23
- data/lib/sparql/algebra/aggregate.rb +4 -4
- data/lib/sparql/algebra/evaluatable.rb +2 -2
- data/lib/sparql/algebra/expression.rb +28 -21
- data/lib/sparql/algebra/extensions.rb +142 -16
- data/lib/sparql/algebra/operator.rb +37 -16
- data/lib/sparql/algebra/operator/abs.rb +2 -2
- data/lib/sparql/algebra/operator/add.rb +3 -3
- data/lib/sparql/algebra/operator/alt.rb +4 -4
- data/lib/sparql/algebra/operator/and.rb +7 -7
- data/lib/sparql/algebra/operator/asc.rb +3 -3
- data/lib/sparql/algebra/operator/ask.rb +4 -14
- data/lib/sparql/algebra/operator/avg.rb +6 -4
- data/lib/sparql/algebra/operator/base.rb +10 -10
- data/lib/sparql/algebra/operator/bgp.rb +1 -1
- data/lib/sparql/algebra/operator/bnode.rb +5 -5
- data/lib/sparql/algebra/operator/bound.rb +3 -3
- data/lib/sparql/algebra/operator/ceil.rb +2 -2
- data/lib/sparql/algebra/operator/clear.rb +3 -3
- data/lib/sparql/algebra/operator/coalesce.rb +3 -13
- data/lib/sparql/algebra/operator/compare.rb +8 -8
- data/lib/sparql/algebra/operator/concat.rb +4 -4
- data/lib/sparql/algebra/operator/construct.rb +4 -14
- data/lib/sparql/algebra/operator/contains.rb +2 -2
- data/lib/sparql/algebra/operator/copy.rb +3 -3
- data/lib/sparql/algebra/operator/count.rb +3 -3
- data/lib/sparql/algebra/operator/create.rb +3 -3
- data/lib/sparql/algebra/operator/dataset.rb +5 -16
- data/lib/sparql/algebra/operator/datatype.rb +1 -1
- data/lib/sparql/algebra/operator/day.rb +1 -1
- data/lib/sparql/algebra/operator/delete.rb +7 -5
- data/lib/sparql/algebra/operator/delete_data.rb +3 -3
- data/lib/sparql/algebra/operator/delete_where.rb +5 -5
- data/lib/sparql/algebra/operator/desc.rb +1 -1
- data/lib/sparql/algebra/operator/describe.rb +3 -13
- data/lib/sparql/algebra/operator/distinct.rb +4 -14
- data/lib/sparql/algebra/operator/divide.rb +1 -1
- data/lib/sparql/algebra/operator/drop.rb +3 -3
- data/lib/sparql/algebra/operator/encode_for_uri.rb +3 -3
- data/lib/sparql/algebra/operator/equal.rb +3 -3
- data/lib/sparql/algebra/operator/exists.rb +5 -5
- data/lib/sparql/algebra/operator/exprlist.rb +3 -13
- data/lib/sparql/algebra/operator/extend.rb +21 -20
- data/lib/sparql/algebra/operator/filter.rb +6 -16
- data/lib/sparql/algebra/operator/floor.rb +2 -2
- data/lib/sparql/algebra/operator/graph.rb +5 -16
- data/lib/sparql/algebra/operator/greater_than.rb +5 -5
- data/lib/sparql/algebra/operator/greater_than_or_equal.rb +5 -5
- data/lib/sparql/algebra/operator/group.rb +25 -25
- data/lib/sparql/algebra/operator/group_concat.rb +6 -6
- data/lib/sparql/algebra/operator/hours.rb +1 -1
- data/lib/sparql/algebra/operator/if.rb +5 -15
- data/lib/sparql/algebra/operator/in.rb +4 -14
- data/lib/sparql/algebra/operator/insert.rb +6 -4
- data/lib/sparql/algebra/operator/insert_data.rb +3 -3
- data/lib/sparql/algebra/operator/iri.rb +1 -1
- data/lib/sparql/algebra/operator/is_blank.rb +1 -1
- data/lib/sparql/algebra/operator/is_iri.rb +1 -1
- data/lib/sparql/algebra/operator/is_literal.rb +1 -1
- data/lib/sparql/algebra/operator/is_numeric.rb +1 -1
- data/lib/sparql/algebra/operator/join.rb +12 -10
- data/lib/sparql/algebra/operator/lang.rb +1 -1
- data/lib/sparql/algebra/operator/lang_matches.rb +3 -3
- data/lib/sparql/algebra/operator/lcase.rb +2 -2
- data/lib/sparql/algebra/operator/left_join.rb +15 -12
- data/lib/sparql/algebra/operator/less_than.rb +5 -5
- data/lib/sparql/algebra/operator/less_than_or_equal.rb +5 -5
- data/lib/sparql/algebra/operator/load.rb +3 -3
- data/lib/sparql/algebra/operator/max.rb +6 -4
- data/lib/sparql/algebra/operator/md5.rb +1 -1
- data/lib/sparql/algebra/operator/min.rb +6 -4
- data/lib/sparql/algebra/operator/minus.rb +12 -11
- data/lib/sparql/algebra/operator/minutes.rb +1 -1
- data/lib/sparql/algebra/operator/modify.rb +4 -4
- data/lib/sparql/algebra/operator/month.rb +1 -1
- data/lib/sparql/algebra/operator/move.rb +3 -3
- data/lib/sparql/algebra/operator/multiply.rb +1 -1
- data/lib/sparql/algebra/operator/negate.rb +1 -1
- data/lib/sparql/algebra/operator/not.rb +1 -1
- data/lib/sparql/algebra/operator/not_equal.rb +2 -2
- data/lib/sparql/algebra/operator/notexists.rb +4 -4
- data/lib/sparql/algebra/operator/notin.rb +4 -14
- data/lib/sparql/algebra/operator/notoneof.rb +5 -6
- data/lib/sparql/algebra/operator/now.rb +1 -1
- data/lib/sparql/algebra/operator/or.rb +7 -7
- data/lib/sparql/algebra/operator/order.rb +6 -16
- data/lib/sparql/algebra/operator/path.rb +6 -5
- data/lib/sparql/algebra/operator/path_opt.rb +16 -16
- data/lib/sparql/algebra/operator/path_plus.rb +8 -8
- data/lib/sparql/algebra/operator/path_star.rb +4 -4
- data/lib/sparql/algebra/operator/plus.rb +3 -3
- data/lib/sparql/algebra/operator/prefix.rb +10 -10
- data/lib/sparql/algebra/operator/project.rb +4 -14
- data/lib/sparql/algebra/operator/rand.rb +1 -1
- data/lib/sparql/algebra/operator/reduced.rb +4 -14
- data/lib/sparql/algebra/operator/regex.rb +6 -6
- data/lib/sparql/algebra/operator/replace.rb +4 -4
- data/lib/sparql/algebra/operator/reverse.rb +4 -4
- data/lib/sparql/algebra/operator/round.rb +2 -2
- data/lib/sparql/algebra/operator/same_term.rb +8 -5
- data/lib/sparql/algebra/operator/sample.rb +3 -3
- data/lib/sparql/algebra/operator/seconds.rb +1 -1
- data/lib/sparql/algebra/operator/seq.rb +5 -6
- data/lib/sparql/algebra/operator/sequence.rb +4 -4
- data/lib/sparql/algebra/operator/sha1.rb +1 -1
- data/lib/sparql/algebra/operator/sha256.rb +1 -1
- data/lib/sparql/algebra/operator/sha384.rb +1 -1
- data/lib/sparql/algebra/operator/sha512.rb +1 -1
- data/lib/sparql/algebra/operator/slice.rb +4 -14
- data/lib/sparql/algebra/operator/str.rb +1 -1
- data/lib/sparql/algebra/operator/strafter.rb +2 -2
- data/lib/sparql/algebra/operator/strbefore.rb +2 -2
- data/lib/sparql/algebra/operator/strdt.rb +2 -2
- data/lib/sparql/algebra/operator/strends.rb +2 -2
- data/lib/sparql/algebra/operator/strlang.rb +2 -2
- data/lib/sparql/algebra/operator/strlen.rb +2 -2
- data/lib/sparql/algebra/operator/strstarts.rb +2 -2
- data/lib/sparql/algebra/operator/struuid.rb +1 -1
- data/lib/sparql/algebra/operator/substr.rb +4 -4
- data/lib/sparql/algebra/operator/subtract.rb +1 -1
- data/lib/sparql/algebra/operator/sum.rb +6 -4
- data/lib/sparql/algebra/operator/table.rb +6 -4
- data/lib/sparql/algebra/operator/timezone.rb +1 -1
- data/lib/sparql/algebra/operator/tz.rb +1 -1
- data/lib/sparql/algebra/operator/ucase.rb +2 -2
- data/lib/sparql/algebra/operator/union.rb +10 -9
- data/lib/sparql/algebra/operator/update.rb +4 -4
- data/lib/sparql/algebra/operator/using.rb +4 -4
- data/lib/sparql/algebra/operator/uuid.rb +1 -1
- data/lib/sparql/algebra/operator/with.rb +6 -6
- data/lib/sparql/algebra/operator/year.rb +1 -1
- data/lib/sparql/algebra/query.rb +2 -2
- data/lib/sparql/algebra/update.rb +2 -2
- data/lib/sparql/algebra/version.rb +1 -1
- data/lib/sparql/extensions.rb +5 -5
- data/lib/sparql/grammar.rb +111 -11
- data/lib/sparql/grammar/meta.rb +1372 -333
- data/lib/sparql/grammar/parser11.rb +56 -42
- data/lib/sparql/grammar/terminals11.rb +1 -0
- data/lib/sparql/results.rb +63 -44
- data/lib/sparql/version.rb +1 -1
- metadata +40 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f623228f6e6d10b6b8221219ba1b7b6fcfdf8410db716cb400ed50b5e59f7d25
|
4
|
+
data.tar.gz: 8678296e2d0744c5d8dbbc0ac424c7c8b0e2540fa730a03960e961b9c2f08b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b53c1cbf504ac9818d2a6ee0b03b9703e447698c5d2edcef697d49a4a7eaca63f563511440ec8e15e2bf64b8a91290b15eaf5aac2261c5fdd59a88a779fa66
|
7
|
+
data.tar.gz: 19a3844b38131cbc1cfa63a8109602fe07c98b58af4c8eef77cbb3bc668a055872582aa529e8b06ab27e873aacbc2b882abb435ab61148294f28fe4391024cdc
|
data/README.md
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
This is a [Ruby][] implementation of [SPARQL][] for [RDF.rb][].
|
4
4
|
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/sparql.png)](
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/sparql.png)](https://badge.fury.io/rb/sparql)
|
6
6
|
|
7
|
-
[![Build Status](https://travis-ci.org/ruby-rdf/sparql.png?branch=master)](
|
7
|
+
[![Build Status](https://travis-ci.org/ruby-rdf/sparql.png?branch=master)](https://travis-ci.org/ruby-rdf/sparql)
|
8
8
|
|
9
9
|
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/sparql/badge.svg)](https://coveralls.io/r/ruby-rdf/sparql)
|
10
10
|
|
11
11
|
## Features
|
12
12
|
|
13
|
-
* 100% free and unencumbered [public domain](
|
13
|
+
* 100% free and unencumbered [public domain](https://unlicense.org/) software.
|
14
14
|
* Complete [SPARQL 1.1 Query][] parsing and execution
|
15
15
|
* SPARQL results as [XML][SPARQL XML], [JSON][SPARQL JSON],
|
16
16
|
[CSV][SPARQL 1.1 Query Results CSV and TSV Formats],
|
@@ -27,6 +27,7 @@ This is a [Ruby][] implementation of [SPARQL][] for [RDF.rb][].
|
|
27
27
|
* Compatible with Ruby >= 2.2.2.
|
28
28
|
* Compatible with older Ruby versions with the help of the [Backports][] gem.
|
29
29
|
* Supports Unicode query strings both on all versions of Ruby.
|
30
|
+
* Provisional support for [SPARQL*][].
|
30
31
|
|
31
32
|
## Description
|
32
33
|
|
@@ -45,20 +46,20 @@ The {SPARQL} gem uses the [SPARQL 1.1 Query][] {file:etc/sparql11.html EBNF gram
|
|
45
46
|
|
46
47
|
The SPARQL gem now implements the following [SPARQL 1.1 Query][] operations:
|
47
48
|
|
48
|
-
* [Functions](
|
49
|
-
* [BIND](
|
50
|
-
* [GROUP BY](
|
51
|
-
* [Aggregates](
|
52
|
-
* [Subqueries](
|
53
|
-
* [Inline Data](
|
54
|
-
* [Inline Data](
|
55
|
-
* [Exists](
|
56
|
-
* [Negation](
|
57
|
-
* [Property Paths](
|
49
|
+
* [Functions](https://www.w3.org/TR/sparql11-query/#SparqlOps)
|
50
|
+
* [BIND](https://www.w3.org/TR/sparql11-query/#bind)
|
51
|
+
* [GROUP BY](https://www.w3.org/TR/sparql11-query/#groupby)
|
52
|
+
* [Aggregates](https://www.w3.org/TR/sparql11-query/#aggregates)
|
53
|
+
* [Subqueries](https://www.w3.org/TR/sparql11-query/#subqueries)
|
54
|
+
* [Inline Data](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data)
|
55
|
+
* [Inline Data](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data)
|
56
|
+
* [Exists](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists)
|
57
|
+
* [Negation](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#negation)
|
58
|
+
* [Property Paths](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#propertypaths)
|
58
59
|
|
59
60
|
The gem also includes the following [SPARQL 1.1 Update][] operations:
|
60
|
-
* [Graph Update](
|
61
|
-
* [Graph Management](
|
61
|
+
* [Graph Update](https://www.w3.org/TR/sparql11-update/#graphUpdate)
|
62
|
+
* [Graph Management](https://www.w3.org/TR/sparql11-update/#graphManagement)
|
62
63
|
|
63
64
|
Not supported:
|
64
65
|
|
@@ -70,15 +71,15 @@ Not supported:
|
|
70
71
|
either in this, or related gems.
|
71
72
|
|
72
73
|
### Updates for RDF 1.1
|
73
|
-
Starting with version 1.1.2, the SPARQL gem uses the 1.1 version of the [RDF.rb][], which adheres to [RDF 1.1 Concepts](
|
74
|
+
Starting with version 1.1.2, the SPARQL gem uses the 1.1 version of the [RDF.rb][], which adheres to [RDF 1.1 Concepts](https://www.w3.org/TR/rdf11-concepts/) rather than [RDF 1.0](https://www.w3.org/TR/rdf-concepts/). The main difference is that there is now no difference between a _Simple Literal_ (a literal with no datatype or language) and a Literal with datatype _xsd:string_; this causes some minor differences in the way in which queries are understood, and when expecting different results.
|
74
75
|
|
75
76
|
Additionally, queries now take a block, or return an `Enumerator`; this is in keeping with much of the behavior of [RDF.rb][] methods, including `Queryable#query`, and with version 1.1 or [RDF.rb][], Query#execute. As a consequence, all queries which used to be of the form `query.execute(repository)` may equally be called as `repository.query(query)`. Previously, results were returned as a concrete class implementing `RDF::Queryable` or `RDF::Query::Solutions`, these are now `Enumerators`.
|
76
77
|
|
77
78
|
### SPARQL Extension Functions
|
78
79
|
Extension functions may be defined, which will be invoked during query evaluation. For example:
|
79
80
|
|
80
|
-
# Register a function using the IRI <
|
81
|
-
crypt_iri = RDF::URI("
|
81
|
+
# Register a function using the IRI <https://rubygems#crypt>
|
82
|
+
crypt_iri = RDF::URI("https://rubygems#crypt")
|
82
83
|
SPARQL::Algebra::Expression.register_extension(crypt_iri) do |literal|
|
83
84
|
raise TypeError, "argument must be a literal" unless literal.literal?
|
84
85
|
RDF::Literal(literal.to_s.crypt)
|
@@ -86,7 +87,7 @@ Extension functions may be defined, which will be invoked during query evaluatio
|
|
86
87
|
|
87
88
|
Then, use the function in a query:
|
88
89
|
|
89
|
-
PREFIX rsp: <
|
90
|
+
PREFIX rsp: <https://rubygems#>
|
90
91
|
PREFIX schema: <http://schema.org/>
|
91
92
|
SELECT ?crypted
|
92
93
|
{
|
@@ -96,6 +97,117 @@ Then, use the function in a query:
|
|
96
97
|
|
97
98
|
See {SPARQL::Algebra::Expression.register_extension} for details.
|
98
99
|
|
100
|
+
### SPARQLStar (SPARQL*)
|
101
|
+
|
102
|
+
The gem supports [SPARQL*][] where patterns may include sub-patterns recursively, for a kind of Reification.
|
103
|
+
|
104
|
+
For example, the following Turtle* file uses a statement as the subject of another statement:
|
105
|
+
|
106
|
+
@prefix : <http://bigdata.com/> .
|
107
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
108
|
+
@prefix ex: <http://example.org/> .
|
109
|
+
|
110
|
+
:bob foaf:name "Bob" .
|
111
|
+
<<:bob foaf:age 23>> ex:certainty 0.9 .
|
112
|
+
|
113
|
+
This can be queried using the following query:
|
114
|
+
|
115
|
+
PREFIX : <http://bigdata.com/>
|
116
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
117
|
+
PREFIX ex: <http://example.org/>
|
118
|
+
|
119
|
+
SELECT ?age ?c WHERE {
|
120
|
+
?bob foaf:name "Bob" .
|
121
|
+
<<?bob foaf:age ?age>> ex:certainty ?c .
|
122
|
+
}
|
123
|
+
|
124
|
+
This treats `<<:bob foaf:age 23>>` as a subject resource, and the pattern `<<?bob foaf:age ?age>>` to match that resource and bind the associated variables.
|
125
|
+
|
126
|
+
**Note: This feature is subject to change or elimination as the standards process progresses.**
|
127
|
+
|
128
|
+
#### BIND
|
129
|
+
|
130
|
+
There is an alternate syntax using the `BIND` operator:
|
131
|
+
|
132
|
+
PREFIX : <http://bigdata.com>
|
133
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
134
|
+
PREFIX dct: <http://purl.org/dc/elements/1.1/>
|
135
|
+
|
136
|
+
SELECT ?a ?b ?c WHERE {
|
137
|
+
?bob foaf:name "Bob" .
|
138
|
+
BIND( <<?bob foaf:age ?age>> AS ?a ) .
|
139
|
+
?t ?b ?c .
|
140
|
+
}
|
141
|
+
|
142
|
+
When binding, the triple can be either in Property Graph (`:PG`) or Separate Assertions (`:SA`) mode, as the query matches based on the pattern matching as a subject (or object) and does not need to be specifically asserted in the graph. When parsing in Property Graph mode, such triples will also be added to the enclosing graph. Thus, querying for `<<?bob foaf:age ?age>>` and `?bob foaf:age ?age` may not represent the same results.
|
143
|
+
|
144
|
+
When binding an embedded triple to a variable, it is the matched triples which are bound, not the pattern. Thus, the example above with `SELECT ?a ?b ?c` would end up binding `?a` to `:bob foaf:name 23`.
|
145
|
+
|
146
|
+
#### Construct
|
147
|
+
|
148
|
+
As well as a `CONSTRUCT`:
|
149
|
+
|
150
|
+
PREFIX : <http://bigdata.com>
|
151
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
152
|
+
PREFIX dct: <http://purl.org/dc/elements/1.1/>
|
153
|
+
|
154
|
+
CONSTRUCT {
|
155
|
+
?bob foaf:name "Bob" .
|
156
|
+
<<?bob foaf:age ?age>> ?b ?c .
|
157
|
+
}
|
158
|
+
WHERE {
|
159
|
+
?bob foaf:name "Bob" .
|
160
|
+
<<?bob foaf:age ?age>> ?b ?c .
|
161
|
+
}
|
162
|
+
|
163
|
+
Note that results can be serialized only when the format supports [RDF*][].
|
164
|
+
|
165
|
+
#### SPARQL results
|
166
|
+
|
167
|
+
The SPARQL results formats are extended to serialize embedded triples as described for [RDF4J](https://rdf4j.org/documentation/programming/rdfstar/):
|
168
|
+
|
169
|
+
{
|
170
|
+
"head" : {
|
171
|
+
"vars" : [
|
172
|
+
"a",
|
173
|
+
"b",
|
174
|
+
"c"
|
175
|
+
]
|
176
|
+
},
|
177
|
+
"results" : {
|
178
|
+
"bindings": [
|
179
|
+
{ "a" : {
|
180
|
+
"type" : "triple",
|
181
|
+
"value" : {
|
182
|
+
"s" : {
|
183
|
+
"type" : "uri",
|
184
|
+
"value" : "http://example.org/bob"
|
185
|
+
},
|
186
|
+
"p" : {
|
187
|
+
"type" : "uri",
|
188
|
+
"value" : "http://xmlns.com/foaf/0.1/name"
|
189
|
+
},
|
190
|
+
"o" : {
|
191
|
+
"datatype" : "http://www.w3.org/2001/XMLSchema#integer",
|
192
|
+
"type" : "literal",
|
193
|
+
"value" : "23"
|
194
|
+
}
|
195
|
+
}
|
196
|
+
},
|
197
|
+
"b": {
|
198
|
+
"type": "uri",
|
199
|
+
"value": "http://example.org/certainty"
|
200
|
+
},
|
201
|
+
"c" : {
|
202
|
+
"datatype" : "http://www.w3.org/2001/XMLSchema#decimal",
|
203
|
+
"type" : "literal",
|
204
|
+
"value" : "0.9"
|
205
|
+
}
|
206
|
+
}
|
207
|
+
]
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
99
211
|
### Middleware
|
100
212
|
|
101
213
|
{Rack::SPARQL} is a superset of [Rack::LinkedData][] to allow content negotiated results
|
@@ -150,12 +262,12 @@ a full set of RDF formats.
|
|
150
262
|
result.inspect
|
151
263
|
end
|
152
264
|
|
153
|
-
### Updating a
|
265
|
+
### Updating a repository
|
154
266
|
|
155
267
|
queryable = RDF::Repository.load("etc/doap.ttl")
|
156
268
|
sse = SPARQL.parse(%(
|
157
269
|
PREFIX doap: <http://usefulinc.com/ns/doap#>
|
158
|
-
INSERT DATA { <
|
270
|
+
INSERT DATA { <https://rubygems> doap:implements <http://www.w3.org/TR/sparql11-update/>}
|
159
271
|
), update: true)
|
160
272
|
sse.execute(queryable)
|
161
273
|
|
@@ -257,14 +369,14 @@ Full documentation available on [Rubydoc.info][SPARQL doc]
|
|
257
369
|
|
258
370
|
## Dependencies
|
259
371
|
|
260
|
-
* [Ruby](
|
261
|
-
* [RDF.rb](
|
372
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.2.2)
|
373
|
+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.0)
|
262
374
|
* [SPARQL::Client](https://rubygems.org/gems/sparql-client) (~> 3.0)
|
263
375
|
* [SXP](https://rubygems.org/gems/sxp) (~> 1.0)
|
264
376
|
* [Builder](https://rubygems.org/gems/builder) (>= 3.0.0)
|
265
377
|
* [JSON](https://rubygems.org/gems/json) (>= 1.8.2)
|
266
378
|
* Soft dependency on [Linked Data][] (>= 3.0)
|
267
|
-
* Soft dependency on [Nokogiri](
|
379
|
+
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.7)
|
268
380
|
Falls back to REXML for XML parsing Builder for XML serializing. Nokogiri is much more efficient
|
269
381
|
* Soft dependency on [Equivalent XML](https://rubygems.org/gems/equivalent-xml) (>= 0.3.0)
|
270
382
|
Equivalent XML performs more efficient comparisons of XML Literals when Nokogiri is included
|
@@ -273,7 +385,7 @@ Full documentation available on [Rubydoc.info][SPARQL doc]
|
|
273
385
|
|
274
386
|
## Installation
|
275
387
|
|
276
|
-
The recommended installation method is via [RubyGems](
|
388
|
+
The recommended installation method is via [RubyGems](https://rubygems.org/).
|
277
389
|
To install the latest official release of the `SPARQL` gem, do:
|
278
390
|
|
279
391
|
% [sudo] gem install sparql
|
@@ -286,13 +398,13 @@ To get a local working copy of the development repository, do:
|
|
286
398
|
|
287
399
|
## Mailing List
|
288
400
|
|
289
|
-
* <
|
401
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
290
402
|
|
291
403
|
## Authors
|
292
404
|
|
293
|
-
* [Gregg Kellogg](
|
294
|
-
* [Arto Bendiken](
|
295
|
-
* [Pius Uzamere](
|
405
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
406
|
+
* [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
|
407
|
+
* [Pius Uzamere](https://github.com/pius) - <https://pius.me/>
|
296
408
|
|
297
409
|
## Contributing
|
298
410
|
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
@@ -312,49 +424,51 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
312
424
|
## License
|
313
425
|
|
314
426
|
This is free and unencumbered public domain software. For more information,
|
315
|
-
see <
|
427
|
+
see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
316
428
|
|
317
|
-
A copy of the [SPARQL EBNF][] and derived parser files are included in the repository, which are not covered under the UNLICENSE. These files are covered via the [W3C Document License](
|
429
|
+
A copy of the [SPARQL EBNF][] and derived parser files are included in the repository, which are not covered under the UNLICENSE. These files are covered via the [W3C Document License](https://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231).
|
318
430
|
|
319
431
|
A copy of the [SPARQL 1.0 tests][] and [SPARQL 1.1 tests][] are also included in the repository, which are not covered under the UNLICENSE; see the references for test copyright information.
|
320
432
|
|
321
|
-
[Ruby]:
|
322
|
-
[RDF]:
|
323
|
-
[RDF::DO]:
|
324
|
-
[RDF::Mongo]:
|
325
|
-
[Rack::LinkedData]:
|
326
|
-
[YARD]:
|
327
|
-
[YARD-GS]:
|
328
|
-
[PDD]:
|
329
|
-
[SPARQL]:
|
330
|
-
[SPARQL 1.0]:
|
331
|
-
[SPARQL 1.0 tests]:
|
332
|
-
[SPARQL 1.1 tests]:
|
333
|
-
[SSE]:
|
334
|
-
[SXP]:
|
335
|
-
[grammar]:
|
336
|
-
[RDF 1.1]:
|
337
|
-
[RDF.rb]:
|
338
|
-
[
|
339
|
-
[
|
340
|
-
[
|
341
|
-
[
|
342
|
-
[SPARQL
|
343
|
-
[SPARQL
|
344
|
-
|
345
|
-
[
|
346
|
-
|
347
|
-
[
|
348
|
-
[
|
349
|
-
|
350
|
-
[
|
351
|
-
|
352
|
-
[SPARQL 1.1
|
353
|
-
[SPARQL 1.1
|
354
|
-
[SPARQL 1.1
|
355
|
-
[SPARQL 1.1 Query
|
356
|
-
[SPARQL Query Results
|
357
|
-
[SPARQL 1.1
|
358
|
-
[SPARQL
|
359
|
-
[SPARQL 1.1
|
433
|
+
[Ruby]: https://ruby-lang.org/
|
434
|
+
[RDF]: https://www.w3.org/RDF/
|
435
|
+
[RDF::DO]: https://rubygems.org/gems/rdf-do
|
436
|
+
[RDF::Mongo]: https://rubygems.org/gems/rdf-mongo
|
437
|
+
[Rack::LinkedData]: https://rubygems.org/gems/rack-linkeddata
|
438
|
+
[YARD]: https://yardoc.org/
|
439
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
440
|
+
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
|
441
|
+
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
|
442
|
+
[SPARQL 1.0]: https://www.w3.org/TR/sparql11-query/
|
443
|
+
[SPARQL 1.0 tests]:https://www.w3.org/2001/sw/DataAccess/tests/
|
444
|
+
[SPARQL 1.1 tests]: https://www.w3.org/2009/sparql/docs/tests/
|
445
|
+
[SSE]: https://jena.apache.org/documentation/notes/sse.html
|
446
|
+
[SXP]: https://www.rubydoc.info/github/dryruby/sxp
|
447
|
+
[grammar]: https://www.w3.org/TR/sparql11-query/#grammar
|
448
|
+
[RDF 1.1]: https://www.w3.org/TR/rdf11-concepts
|
449
|
+
[RDF.rb]: https://rubydoc.info/github/ruby-rdf/rdf
|
450
|
+
[RDF*]: https://lists.w3.org/Archives/Public/public-rdf-star/
|
451
|
+
[SPARQL*]: https://arxiv.org/pdf/1406.3399.pdf
|
452
|
+
[Backports]: https://rubygems.org/gems/backports
|
453
|
+
[Linked Data]: https://rubygems.org/gems/linkeddata
|
454
|
+
[SPARQL doc]: https://rubydoc.info/github/ruby-rdf/sparql/frames
|
455
|
+
[SPARQL XML]: https://www.w3.org/TR/rdf-sparql-XMLres/
|
456
|
+
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
|
457
|
+
[SPARQL EBNF]: https://www.w3.org/TR/sparql11-query/#sparqlGrammar
|
458
|
+
|
459
|
+
[SSD]: https://www.w3.org/TR/sparql11-service-description/
|
460
|
+
[Rack]: https://rack.github.io
|
461
|
+
[Sinatra]: https://www.sinatrarb.com/
|
462
|
+
[conneg]: https://en.wikipedia.org/wiki/Content_negotiation
|
463
|
+
|
464
|
+
[SPARQL 1.1 Query]: https://www.w3.org/TR/sparql11-query/
|
465
|
+
[SPARQL 1.1 Update]: https://www.w3.org/TR/sparql11-update/
|
466
|
+
[SPARQL 1.1 Service Description]: https://www.w3.org/TR/sparql11-service-description/
|
467
|
+
[SPARQL 1.1 Federated Query]: https://www.w3.org/TR/sparql11-federated-query/
|
468
|
+
[SPARQL 1.1 Query Results JSON Format]: https://www.w3.org/TR/sparql11-results-json/
|
469
|
+
[SPARQL 1.1 Query Results CSV and TSV Formats]: https://www.w3.org/TR/sparql11-results-csv-tsv/
|
470
|
+
[SPARQL Query Results XML Format]: https://www.w3.org/TR/rdf-sparql-XMLres/
|
471
|
+
[SPARQL 1.1 Entailment Regimes]: https://www.w3.org/TR/sparql11-entailment/
|
472
|
+
[SPARQL 1.1 Protocol]: https://www.w3.org/TR/sparql11-protocol/
|
473
|
+
[SPARQL 1.1 Graph Store HTTP Protocol]: https://www.w3.org/TR/sparql11-http-rdf-update/
|
360
474
|
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.3
|
data/bin/sparql
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
$:.unshift(
|
3
|
+
$:.unshift("../../lib", __FILE__)
|
4
4
|
require 'sparql'
|
5
5
|
begin
|
6
6
|
require 'linkeddata'
|
@@ -9,16 +9,24 @@ rescue LoadError
|
|
9
9
|
end
|
10
10
|
require 'getoptlong'
|
11
11
|
|
12
|
-
def display_results(res, options)
|
12
|
+
def display_results(res, **options)
|
13
13
|
puts res.inspect if options[:verbose]
|
14
14
|
puts case res
|
15
|
-
when RDF::Graph then res.dump(:ttl, base_uri: query.base_uri, prefixes: query.prefixes, standard_prefixes: true)
|
15
|
+
when RDF::Graph then res.dump(options.fetch(:format, :ttl), base_uri: query.base_uri, prefixes: query.prefixes, standard_prefixes: true)
|
16
16
|
when RDF::Literal then res.inspect
|
17
|
-
else
|
17
|
+
else
|
18
|
+
case options[:format]
|
19
|
+
when :json then res.to_json
|
20
|
+
when :html then res.to_html
|
21
|
+
when :xml then res.to_xml
|
22
|
+
when :csv then res.to_csv
|
23
|
+
when :tsv then res.to_tsv
|
24
|
+
else res.map {|s| s.bindings.map {|k,v| "#{k}: #{v}"}}.join("\n")
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
21
|
-
def run(input, options
|
29
|
+
def run(input, **options)
|
22
30
|
if options[:debug]
|
23
31
|
puts "input graph:\n#{options[:dataset].dump(:trig, standard_prefixes: true)}\n" if options[:dataset]
|
24
32
|
puts "query:\n#{input}\n"
|
@@ -30,17 +38,17 @@ def run(input, options = {})
|
|
30
38
|
end
|
31
39
|
|
32
40
|
query = if options[:sse]
|
33
|
-
SPARQL::Algebra.parse(input,
|
41
|
+
SPARQL::Algebra.parse(input, debug: options[:debug], update: options[:update])
|
34
42
|
else
|
35
43
|
# Only do grammar debugging if we're generating SSE
|
36
|
-
SPARQL::Grammar.parse(input, options)
|
44
|
+
SPARQL::Grammar.parse(input, **options)
|
37
45
|
end
|
38
46
|
|
39
47
|
puts ("\nSSE:\n" + query.to_sse) if options[:debug] || options[:to_sse]
|
40
48
|
|
41
49
|
unless options[:to_sse]
|
42
50
|
res = query.execute(options[:dataset], debug: options[:debug])
|
43
|
-
display_results(res, options)
|
51
|
+
display_results(res, **options)
|
44
52
|
end
|
45
53
|
end
|
46
54
|
|
@@ -54,7 +62,7 @@ def server(options)
|
|
54
62
|
|
55
63
|
get '/' do
|
56
64
|
if params["query"]
|
57
|
-
query = params["query"].to_s.match(/^http:/) ? RDF::Util::File.open_file(params["query"]) : ::
|
65
|
+
query = params["query"].to_s.match(/^http:/) ? RDF::Util::File.open_file(params["query"]) : ::CGI.unescape(params["query"].to_s)
|
58
66
|
SPARQL.execute(query, settings.repository)
|
59
67
|
else
|
60
68
|
settings.sparql_options.replace(standard_prefixes: true)
|
@@ -81,12 +89,13 @@ def usage
|
|
81
89
|
puts " #{$0} query [options] end-point query-file Run the query against a remote end-point"
|
82
90
|
puts " #{$0} server [options] dataset-file Start a server initialized from the specified dataset"
|
83
91
|
puts "Options:"
|
84
|
-
puts " --execute,-e: Use option argument as the SPARQL input if no query-file given"
|
85
92
|
puts " --dataset: File containing RDF graph or dataset"
|
86
93
|
puts " --debug: Display detailed debug output"
|
94
|
+
puts " --debug: Display detailed debug output"
|
95
|
+
puts " --execute,-e: Use option argument as the SPARQL input if no query-file given"
|
96
|
+
puts " --format: Output format for results"
|
87
97
|
puts " --port,-p Port on which to run server; defaults to 9292"
|
88
98
|
puts " --sse: Query input is in SSE format"
|
89
|
-
puts " --debug: Display detailed debug output"
|
90
99
|
puts " --update: Process query as a SPARQL Update"
|
91
100
|
puts " --verbose: Display details of processing"
|
92
101
|
puts " --help,-?: This message"
|
@@ -98,11 +107,12 @@ cmd, input = ARGV.shift, nil
|
|
98
107
|
opts = GetoptLong.new(
|
99
108
|
["--dataset", GetoptLong::REQUIRED_ARGUMENT],
|
100
109
|
["--debug", GetoptLong::NO_ARGUMENT],
|
110
|
+
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
|
111
|
+
["--format", GetoptLong::REQUIRED_ARGUMENT],
|
101
112
|
["--port", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
102
|
-
["--verbose", GetoptLong::NO_ARGUMENT],
|
103
113
|
["--sse", GetoptLong::NO_ARGUMENT],
|
104
114
|
["--update", GetoptLong::NO_ARGUMENT],
|
105
|
-
["--
|
115
|
+
["--verbose", GetoptLong::NO_ARGUMENT],
|
106
116
|
["--help", "-?", GetoptLong::NO_ARGUMENT]
|
107
117
|
)
|
108
118
|
|
@@ -112,11 +122,12 @@ options = {
|
|
112
122
|
|
113
123
|
opts.each do |opt, arg|
|
114
124
|
case opt
|
115
|
-
when '--dataset' then options[:dataset].load(arg)
|
125
|
+
when '--dataset' then options[:dataset].load(arg, rdfstar: :PG)
|
126
|
+
when '--debug' then options[:debug] = true
|
116
127
|
when '--execute' then input = arg
|
128
|
+
when '--format' then options[:format] = arg.to_sym
|
117
129
|
when '--port' then options[:port] = arg.to_i
|
118
130
|
when '--sse' then options[:sse] = true
|
119
|
-
when '--debug' then options[:debug] = true
|
120
131
|
when '--update' then options[:update] = true
|
121
132
|
when '--verbose' then options[:verbose] = true
|
122
133
|
when "--help" then usage
|
@@ -132,7 +143,7 @@ case cmd
|
|
132
143
|
when 'execute', 'parse'
|
133
144
|
options[:to_sse] = true if cmd == 'parse'
|
134
145
|
input ||= ARGV.empty? ? $stdin.read : RDF::Util::File.open_file(ARGV.first).read
|
135
|
-
run(input, options)
|
146
|
+
run(input, **options)
|
136
147
|
when 'query'
|
137
148
|
endpoint = ARGV.shift
|
138
149
|
unless endpoint
|
@@ -142,7 +153,7 @@ when 'query'
|
|
142
153
|
input ||= ARGV.empty? ? $stdin.read : RDF::Util::File.open_file(ARGV.first).read
|
143
154
|
SPARQL::Client.new(endpoint) do |client|
|
144
155
|
res = client.query(input)
|
145
|
-
display_results(res, options)
|
156
|
+
display_results(res, **options)
|
146
157
|
end
|
147
158
|
when 'server'
|
148
159
|
if data_file = ARGV.shift
|