sparql 3.0.0 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +184 -70
  3. data/UNLICENSE +1 -1
  4. data/VERSION +1 -1
  5. data/bin/sparql +28 -17
  6. data/lib/rack/sparql.rb +1 -1
  7. data/lib/rack/sparql/conneg.rb +3 -3
  8. data/lib/sinatra/sparql.rb +5 -5
  9. data/lib/sparql.rb +14 -10
  10. data/lib/sparql/algebra.rb +15 -23
  11. data/lib/sparql/algebra/aggregate.rb +4 -4
  12. data/lib/sparql/algebra/evaluatable.rb +2 -2
  13. data/lib/sparql/algebra/expression.rb +28 -21
  14. data/lib/sparql/algebra/extensions.rb +142 -16
  15. data/lib/sparql/algebra/operator.rb +37 -16
  16. data/lib/sparql/algebra/operator/abs.rb +2 -2
  17. data/lib/sparql/algebra/operator/add.rb +3 -3
  18. data/lib/sparql/algebra/operator/alt.rb +4 -4
  19. data/lib/sparql/algebra/operator/and.rb +7 -7
  20. data/lib/sparql/algebra/operator/asc.rb +3 -3
  21. data/lib/sparql/algebra/operator/ask.rb +4 -14
  22. data/lib/sparql/algebra/operator/avg.rb +6 -4
  23. data/lib/sparql/algebra/operator/base.rb +10 -10
  24. data/lib/sparql/algebra/operator/bgp.rb +1 -1
  25. data/lib/sparql/algebra/operator/bnode.rb +5 -5
  26. data/lib/sparql/algebra/operator/bound.rb +3 -3
  27. data/lib/sparql/algebra/operator/ceil.rb +2 -2
  28. data/lib/sparql/algebra/operator/clear.rb +3 -3
  29. data/lib/sparql/algebra/operator/coalesce.rb +3 -13
  30. data/lib/sparql/algebra/operator/compare.rb +8 -8
  31. data/lib/sparql/algebra/operator/concat.rb +4 -4
  32. data/lib/sparql/algebra/operator/construct.rb +4 -14
  33. data/lib/sparql/algebra/operator/contains.rb +2 -2
  34. data/lib/sparql/algebra/operator/copy.rb +3 -3
  35. data/lib/sparql/algebra/operator/count.rb +3 -3
  36. data/lib/sparql/algebra/operator/create.rb +3 -3
  37. data/lib/sparql/algebra/operator/dataset.rb +5 -16
  38. data/lib/sparql/algebra/operator/datatype.rb +1 -1
  39. data/lib/sparql/algebra/operator/day.rb +1 -1
  40. data/lib/sparql/algebra/operator/delete.rb +7 -5
  41. data/lib/sparql/algebra/operator/delete_data.rb +3 -3
  42. data/lib/sparql/algebra/operator/delete_where.rb +5 -5
  43. data/lib/sparql/algebra/operator/desc.rb +1 -1
  44. data/lib/sparql/algebra/operator/describe.rb +3 -13
  45. data/lib/sparql/algebra/operator/distinct.rb +4 -14
  46. data/lib/sparql/algebra/operator/divide.rb +1 -1
  47. data/lib/sparql/algebra/operator/drop.rb +3 -3
  48. data/lib/sparql/algebra/operator/encode_for_uri.rb +3 -3
  49. data/lib/sparql/algebra/operator/equal.rb +3 -3
  50. data/lib/sparql/algebra/operator/exists.rb +5 -5
  51. data/lib/sparql/algebra/operator/exprlist.rb +3 -13
  52. data/lib/sparql/algebra/operator/extend.rb +21 -20
  53. data/lib/sparql/algebra/operator/filter.rb +6 -16
  54. data/lib/sparql/algebra/operator/floor.rb +2 -2
  55. data/lib/sparql/algebra/operator/graph.rb +5 -16
  56. data/lib/sparql/algebra/operator/greater_than.rb +5 -5
  57. data/lib/sparql/algebra/operator/greater_than_or_equal.rb +5 -5
  58. data/lib/sparql/algebra/operator/group.rb +25 -25
  59. data/lib/sparql/algebra/operator/group_concat.rb +6 -6
  60. data/lib/sparql/algebra/operator/hours.rb +1 -1
  61. data/lib/sparql/algebra/operator/if.rb +5 -15
  62. data/lib/sparql/algebra/operator/in.rb +4 -14
  63. data/lib/sparql/algebra/operator/insert.rb +6 -4
  64. data/lib/sparql/algebra/operator/insert_data.rb +3 -3
  65. data/lib/sparql/algebra/operator/iri.rb +1 -1
  66. data/lib/sparql/algebra/operator/is_blank.rb +1 -1
  67. data/lib/sparql/algebra/operator/is_iri.rb +1 -1
  68. data/lib/sparql/algebra/operator/is_literal.rb +1 -1
  69. data/lib/sparql/algebra/operator/is_numeric.rb +1 -1
  70. data/lib/sparql/algebra/operator/join.rb +12 -10
  71. data/lib/sparql/algebra/operator/lang.rb +1 -1
  72. data/lib/sparql/algebra/operator/lang_matches.rb +3 -3
  73. data/lib/sparql/algebra/operator/lcase.rb +2 -2
  74. data/lib/sparql/algebra/operator/left_join.rb +15 -12
  75. data/lib/sparql/algebra/operator/less_than.rb +5 -5
  76. data/lib/sparql/algebra/operator/less_than_or_equal.rb +5 -5
  77. data/lib/sparql/algebra/operator/load.rb +3 -3
  78. data/lib/sparql/algebra/operator/max.rb +6 -4
  79. data/lib/sparql/algebra/operator/md5.rb +1 -1
  80. data/lib/sparql/algebra/operator/min.rb +6 -4
  81. data/lib/sparql/algebra/operator/minus.rb +12 -11
  82. data/lib/sparql/algebra/operator/minutes.rb +1 -1
  83. data/lib/sparql/algebra/operator/modify.rb +4 -4
  84. data/lib/sparql/algebra/operator/month.rb +1 -1
  85. data/lib/sparql/algebra/operator/move.rb +3 -3
  86. data/lib/sparql/algebra/operator/multiply.rb +1 -1
  87. data/lib/sparql/algebra/operator/negate.rb +1 -1
  88. data/lib/sparql/algebra/operator/not.rb +1 -1
  89. data/lib/sparql/algebra/operator/not_equal.rb +2 -2
  90. data/lib/sparql/algebra/operator/notexists.rb +4 -4
  91. data/lib/sparql/algebra/operator/notin.rb +4 -14
  92. data/lib/sparql/algebra/operator/notoneof.rb +5 -6
  93. data/lib/sparql/algebra/operator/now.rb +1 -1
  94. data/lib/sparql/algebra/operator/or.rb +7 -7
  95. data/lib/sparql/algebra/operator/order.rb +6 -16
  96. data/lib/sparql/algebra/operator/path.rb +6 -5
  97. data/lib/sparql/algebra/operator/path_opt.rb +16 -16
  98. data/lib/sparql/algebra/operator/path_plus.rb +8 -8
  99. data/lib/sparql/algebra/operator/path_star.rb +4 -4
  100. data/lib/sparql/algebra/operator/plus.rb +3 -3
  101. data/lib/sparql/algebra/operator/prefix.rb +10 -10
  102. data/lib/sparql/algebra/operator/project.rb +4 -14
  103. data/lib/sparql/algebra/operator/rand.rb +1 -1
  104. data/lib/sparql/algebra/operator/reduced.rb +4 -14
  105. data/lib/sparql/algebra/operator/regex.rb +6 -6
  106. data/lib/sparql/algebra/operator/replace.rb +4 -4
  107. data/lib/sparql/algebra/operator/reverse.rb +4 -4
  108. data/lib/sparql/algebra/operator/round.rb +2 -2
  109. data/lib/sparql/algebra/operator/same_term.rb +8 -5
  110. data/lib/sparql/algebra/operator/sample.rb +3 -3
  111. data/lib/sparql/algebra/operator/seconds.rb +1 -1
  112. data/lib/sparql/algebra/operator/seq.rb +5 -6
  113. data/lib/sparql/algebra/operator/sequence.rb +4 -4
  114. data/lib/sparql/algebra/operator/sha1.rb +1 -1
  115. data/lib/sparql/algebra/operator/sha256.rb +1 -1
  116. data/lib/sparql/algebra/operator/sha384.rb +1 -1
  117. data/lib/sparql/algebra/operator/sha512.rb +1 -1
  118. data/lib/sparql/algebra/operator/slice.rb +4 -14
  119. data/lib/sparql/algebra/operator/str.rb +1 -1
  120. data/lib/sparql/algebra/operator/strafter.rb +2 -2
  121. data/lib/sparql/algebra/operator/strbefore.rb +2 -2
  122. data/lib/sparql/algebra/operator/strdt.rb +2 -2
  123. data/lib/sparql/algebra/operator/strends.rb +2 -2
  124. data/lib/sparql/algebra/operator/strlang.rb +2 -2
  125. data/lib/sparql/algebra/operator/strlen.rb +2 -2
  126. data/lib/sparql/algebra/operator/strstarts.rb +2 -2
  127. data/lib/sparql/algebra/operator/struuid.rb +1 -1
  128. data/lib/sparql/algebra/operator/substr.rb +4 -4
  129. data/lib/sparql/algebra/operator/subtract.rb +1 -1
  130. data/lib/sparql/algebra/operator/sum.rb +6 -4
  131. data/lib/sparql/algebra/operator/table.rb +6 -4
  132. data/lib/sparql/algebra/operator/timezone.rb +1 -1
  133. data/lib/sparql/algebra/operator/tz.rb +1 -1
  134. data/lib/sparql/algebra/operator/ucase.rb +2 -2
  135. data/lib/sparql/algebra/operator/union.rb +10 -9
  136. data/lib/sparql/algebra/operator/update.rb +4 -4
  137. data/lib/sparql/algebra/operator/using.rb +4 -4
  138. data/lib/sparql/algebra/operator/uuid.rb +1 -1
  139. data/lib/sparql/algebra/operator/with.rb +6 -6
  140. data/lib/sparql/algebra/operator/year.rb +1 -1
  141. data/lib/sparql/algebra/query.rb +2 -2
  142. data/lib/sparql/algebra/update.rb +2 -2
  143. data/lib/sparql/algebra/version.rb +1 -1
  144. data/lib/sparql/extensions.rb +5 -5
  145. data/lib/sparql/grammar.rb +111 -11
  146. data/lib/sparql/grammar/meta.rb +1372 -333
  147. data/lib/sparql/grammar/parser11.rb +56 -42
  148. data/lib/sparql/grammar/terminals11.rb +1 -0
  149. data/lib/sparql/results.rb +63 -44
  150. data/lib/sparql/version.rb +1 -1
  151. metadata +40 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0bff4a7c42287bdfe66a68fe8b9749ba03a28c79
4
- data.tar.gz: 1922e7c06a6387ec9dd8b4797fb262f8d8b2b70d
2
+ SHA256:
3
+ metadata.gz: f623228f6e6d10b6b8221219ba1b7b6fcfdf8410db716cb400ed50b5e59f7d25
4
+ data.tar.gz: 8678296e2d0744c5d8dbbc0ac424c7c8b0e2540fa730a03960e961b9c2f08b33
5
5
  SHA512:
6
- metadata.gz: 12f7636ac3e765bebe48ffff2de8255bdc8465279576a4a7ceeea7c196412ee0410b115418646bcc329b9a187e204469438b2d0f01676d0c7e9332bae9797b9c
7
- data.tar.gz: 0f7cba620c3a2548d1e7645b25713f1071135290f34ba583a2c70054700a9e0c1b5ea7d0176d3fc049f0e7dfc2c0e334108893fd2d491f5354c01a03821408d8
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)](http://badge.fury.io/rb/sparql)
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)](http://travis-ci.org/ruby-rdf/sparql)
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](http://unlicense.org/) software.
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](http://www.w3.org/TR/sparql11-query/#SparqlOps)
49
- * [BIND](http://www.w3.org/TR/sparql11-query/#bind)
50
- * [GROUP BY](http://www.w3.org/TR/sparql11-query/#groupby)
51
- * [Aggregates](http://www.w3.org/TR/sparql11-query/#aggregates)
52
- * [Subqueries](http://www.w3.org/TR/sparql11-query/#subqueries)
53
- * [Inline Data](http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data)
54
- * [Inline Data](http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data)
55
- * [Exists](http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists)
56
- * [Negation](http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#negation)
57
- * [Property Paths](http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#propertypaths)
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](http://www.w3.org/TR/sparql11-update/#graphUpdate)
61
- * [Graph Management](http://www.w3.org/TR/sparql11-update/#graphManagement)
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](http://www.w3.org/TR/rdf11-concepts/) rather than [RDF 1.0](http://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
+ 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 <http://rubygems.org/gems/sparql#crypt>
81
- crypt_iri = RDF::URI("http://rubygems.org/gems/sparql#crypt")
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: <http://rubygems.org/gems/sparql#>
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 respository
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 { <http://rubygems.org/gems/sparql> doap:implements <http://www.w3.org/TR/sparql11-update/>}
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](http://ruby-lang.org/) (>= 2.2.2)
261
- * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
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](http://rubygems.org/gems/nokogiri) (>= 1.7)
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](http://rubygems.org/).
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
- * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
401
+ * <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
290
402
 
291
403
  ## Authors
292
404
 
293
- * [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
294
- * [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
295
- * [Pius Uzamere](http://github.com/pius) - <http://pius.me/>
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 <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
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](http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231).
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]: http://ruby-lang.org/
322
- [RDF]: http://www.w3.org/RDF/
323
- [RDF::DO]: http://rubygems.org/gems/rdf-do
324
- [RDF::Mongo]: http://rubygems.org/gems/rdf-mongo
325
- [Rack::LinkedData]: http://rubygems.org/gems/rack-linkeddata
326
- [YARD]: http://yardoc.org/
327
- [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
328
- [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
329
- [SPARQL]: http://en.wikipedia.org/wiki/SPARQL
330
- [SPARQL 1.0]: http://www.w3.org/TR/sparql11-query/
331
- [SPARQL 1.0 tests]:http://www.w3.org/2001/sw/DataAccess/tests/
332
- [SPARQL 1.1 tests]: http://www.w3.org/2009/sparql/docs/tests/
333
- [SSE]: http://openjena.org/wiki/SSE
334
- [SXP]: http://www.rubydoc.info/github/bendiken/sxp-ruby
335
- [grammar]: http://www.w3.org/TR/sparql11-query/#grammar
336
- [RDF 1.1]: http://www.w3.org/TR/rdf11-concepts
337
- [RDF.rb]: http://rubydoc.info/github/ruby-rdf/rdf
338
- [Backports]: http://rubygems.org/gems/backports
339
- [Linked Data]: http://rubygems.org/gems/linkeddata
340
- [SPARQL doc]: http://rubydoc.info/github/ruby-rdf/sparql/frames
341
- [SPARQL XML]: http://www.w3.org/TR/rdf-sparql-XMLres/
342
- [SPARQL JSON]: http://www.w3.org/TR/rdf-sparql-json-res/
343
- [SPARQL EBNF]: http://www.w3.org/TR/sparql11-query/#sparqlGrammar
344
-
345
- [SSD]: http://www.w3.org/TR/sparql11-service-description/
346
- [Rack]: http://rack.github.io
347
- [Sinatra]: http://www.sinatrarb.com/
348
- [conneg]: http://en.wikipedia.org/wiki/Content_negotiation
349
-
350
- [SPARQL 1.1 Query]: http://www.w3.org/TR/sparql11-query/
351
- [SPARQL 1.1 Update]: http://www.w3.org/TR/sparql11-update/
352
- [SPARQL 1.1 Service Description]: http://www.w3.org/TR/sparql11-service-description/
353
- [SPARQL 1.1 Federated Query]: http://www.w3.org/TR/sparql11-federated-query/
354
- [SPARQL 1.1 Query Results JSON Format]: http://www.w3.org/TR/sparql11-results-json/
355
- [SPARQL 1.1 Query Results CSV and TSV Formats]: http://www.w3.org/TR/sparql11-results-csv-tsv/
356
- [SPARQL Query Results XML Format]: http://www.w3.org/TR/rdf-sparql-XMLres/
357
- [SPARQL 1.1 Entailment Regimes]: http://www.w3.org/TR/sparql11-entailment/
358
- [SPARQL 1.1 Protocol]: http://www.w3.org/TR/sparql11-protocol/
359
- [SPARQL 1.1 Graph Store HTTP Protocol]: http://www.w3.org/TR/sparql11-http-rdf-update/
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 <http://unlicense.org/>
24
+ For more information, please refer to <https://unlicense.org/>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.3
data/bin/sparql CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
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 res.map {|s| s.bindings.map {|k,v| "#{k}: #{v}"}}.join("\n")
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, {debug: options[:debug], update: options[:update]})
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"]) : ::URI.decode(params["query"].to_s)
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
- ["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
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