Skip to content

Commit

Permalink
Finish 3.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Apr 28, 2022
2 parents cde8a35 + 626a54e commit 4b29a2b
Show file tree
Hide file tree
Showing 167 changed files with 66,922 additions and 40,907 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build & deploy documentation
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
name: Update gh-pages with docs
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
- name: Install required gem dependencies
run: gem install yard --no-document
- name: Build YARD Ruby Documentation
run: yardoc
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/yard
publish_branch: gh-pages
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ group :development do
gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
gem 'ld-patch', github: "ruby-rdf/ld-patch", branch: "develop"
gem 'shex', github: "ruby-rdf/shex", branch: "develop"
gem 'erubis', '>= 2.7.0'
gem 'htmlentities', '>= 4.3.4'
gem "equivalent-xml", '>= 0.6.0'
end

Expand Down
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Starting with version 1.1.2, the SPARQL gem uses the 1.1 version of the [RDF.rb]

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`.

### SPARQL 1.2
The gem supports some of the extensions proposed by the [SPARQL 1.2 Community Group](https://github.com/w3c/sparql-12). In particular, the following extensions are now implemented:

* [SEP-0002: better support for Durations, Dates, and Times](https://github.com/w3c/sparql-12/blob/main/SEP/SEP-0002/sep-0002.md)
* This includes full support for `xsd:date`, `xsd:time`, `xsd:duration`, `xsd:dayTimeDuration`, and `xsd:yearMonthDuration` along with associated XPath/XQuery functions including a new `ADJUST` builtin. (**Note: This feature is subject to change or elimination as the standards process progresses.**)
* [SEP-0003: Property paths with a min/max hop](https://github.com/w3c/sparql-12/blob/main/SEP/SEP-0003/sep-0003.md)
* This includes support for non-counting path forms such as `rdf:rest{1,3}` to match the union of paths `rdf:rest`, `rdf:rest/rdf:rest`, and `rdf:rest/rdf:rest/rdf:rest`. (**Note: This feature is subject to change or elimination as the standards process progresses.**)

### SPARQL Extension Functions
Extension functions may be defined, which will be invoked during query evaluation. For example:

Expand Down Expand Up @@ -162,44 +170,31 @@ Note that results can be serialized only when the format supports [RDF-star][].

#### SPARQL results

The SPARQL results formats are extended to serialize embedded triples as described for [RDF4J](https://rdf4j.org/documentation/programming/rdfstar/):
The SPARQL results formats are extended to serialize quoted triples as described for [RDF4J](https://rdf4j.org/documentation/programming/rdfstar/):

{
"head" : {
"vars" : [
"a",
"b",
"c"
]
"vars" : ["a", "b", "c"]
},
"results" : {
"bindings": [
{ "a" : {
"type" : "triple",
"value" : {
"s" : {
"type" : "uri",
"value" : "http://example.org/bob"
},
"p" : {
"type" : "uri",
"value" : "http://xmlns.com/foaf/0.1/name"
},
"s" : {"value" : "http://example.org/bob", "type": "uri"},
"p" : {"value" : "http://xmlns.com/foaf/0.1/name", "type": "uri"},
"o" : {
"datatype" : "http://www.w3.org/2001/XMLSchema#integer",
"value" : "23",
"type" : "literal",
"value" : "23"
"datatype" : "http://www.w3.org/2001/XMLSchema#integer"
}
}
},
"b": {
"type": "uri",
"value": "http://example.org/certainty"
},
"b": {"value": "http://example.org/certainty", "type": "uri"},
"c" : {
"datatype" : "http://www.w3.org/2001/XMLSchema#decimal",
"value" : "0.9",
"type" : "literal",
"value" : "0.9"
"datatype" : "http://www.w3.org/2001/XMLSchema#decimal"
}
}
]
Expand All @@ -214,17 +209,23 @@ You would typically return an instance of `RDF::Graph`, `RDF::Repository` or an
from your Rack application, and let the `Rack::SPARQL::ContentNegotiation` middleware
take care of serializing your response into whatever format the HTTP
client requested and understands.
Content negotiation also transforms `application/x-www-form-urlencoded` to either `application/sparql-query`
or `application/sparql-update` as appropriate for [SPARQL 1.1 Protocol][].

{Sinatra::SPARQL} is a thin Sinatra-specific wrapper around the
{Rack::SPARQL} middleware, which implements SPARQL
content negotiation for Rack applications. {Sinatra::SPARQL} also supports
[SPARQL 1.1 Service Description][].
[SPARQL 1.1 Service Description][] (via {Sinatra::SPARQL::Helpers.service_description} and protocol-based dataset mangement via {Sinatra::SPARQL::Helpers.dataset} for `default-graph-uri` and `named-graph-uri` The `using-graph-uri` and `using-named-graph-uri` query parameters are managed through {SPARQL::Algebra::Operator::Modify#execute}.

The middleware queries [RDF.rb][] for the MIME content types of known RDF
serialization formats, so it will work with whatever serialization extensions
that are currently available for RDF.rb. (At present, this includes support
for N-Triples, N-Quads, Turtle, RDF/XML, RDF/JSON, JSON-LD, RDFa, TriG and TriX.)

### Server

A simple [Sinatra][]-based server is implemented in {SPARQL::Server.application} using {Rack::SPARQL} and {Sinatra::SPARQL} completes the implementation of [SPARQL 1.1 Protocol][] and can be used to compose a server including other capabilities.

### Remote datasets

A SPARQL query containing `FROM` or `FROM NAMED` (also `UPDATE` or `UPDATE NAMED`) will load the referenced IRI unless the repository already contains a graph with that same IRI. This is performed using [RDF.rb][] `RDF::Util::File.open_file` passing HTTP Accept headers for various available RDF formats. For best results, require [Linked Data][] to enable a full set of RDF formats in the `GET` request. Also, consider overriding `RDF::Util::File.open_file` with an implementation with support for HTTP Get headers (such as `Net::HTTP`).
Expand Down Expand Up @@ -454,14 +455,14 @@ A copy of the [SPARQL 1.0 tests][] and [SPARQL 1.1 tests][] are also included in
[SPARQL 1.0 tests]:https://www.w3.org/2001/sw/DataAccess/tests/
[SPARQL 1.1 tests]: https://www.w3.org/2009/sparql/docs/tests/
[SSE]: https://jena.apache.org/documentation/notes/sse.html
[SXP]: https://www.rubydoc.info/github/dryruby/sxp
[SXP]: https://dryruby.github.io/sxp
[grammar]: https://www.w3.org/TR/sparql11-query/#grammar
[RDF 1.1]: https://www.w3.org/TR/rdf11-concepts
[RDF.rb]: https://rubydoc.info/github/ruby-rdf/rdf
[RDF.rb]: https://ruby-rdf.github.io/rdf
[RDF-star]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
[SPARQL-star]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html#sparql-query-language
[Linked Data]: https://rubygems.org/gems/linkeddata
[SPARQL doc]: https://rubydoc.info/github/ruby-rdf/sparql/frames
[SPARQL doc]: https://ruby-rdf.github.io/sparql/frames
[SPARQL XML]: https://www.w3.org/TR/rdf-sparql-XMLres/
[SPARQL JSON]: https://www.w3.org/TR/rdf-sparql-json-res/
[SPARQL EBNF]: https://www.w3.org/TR/sparql11-query/#sparqlGrammar
Expand Down
14 changes: 10 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ end
desc "Create concatenated test manifests"
file "etc/manifest-cache.nt" do
require 'rdf'
require 'json/ld'
require 'rdf/turtle'
require 'rdf/ntriples'
graph = RDF::Graph.new do |g|
Dir.glob("spec/dawg/**/manifest.jsonld").each do |man|
puts "load #{man}"
g.load(man, unique_bnodes: true)
{
"http://w3c.github.io/rdf-tests/sparql11/" => "../w3c-rdf-tests/sparql11/",
"https://w3c.github.io/rdf-star/tests/sparql/" => "../w3c-rdf-star/tests/sparql/",
"https://w3c.github.io/sparql-12/tests/" => "spec/w3c-sparql-12/tests/"
}.each do |base, path|
Dir.glob("#{path}**/manifest.ttl").each do |man|
puts "load #{man}"
g.load(man, unique_bnodes: true, base_uri: man.sub(path, base))
end
end
end
puts "write"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1
3.2.2
9 changes: 9 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sparql"

require "irb"
require 'amazing_print'
IRB.start(__FILE__)
33 changes: 2 additions & 31 deletions bin/sparql
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,10 @@ def run(input, **options)
end

def server(options)
require 'sinatra/sparql'
repository = options.fetch(:dataset, RDF::Repository.new)

app = Sinatra.new do
register Sinatra::SPARQL
set :repository, repository

before do
options[:logger].info "#{request.request_method} [#{request.path_info}], " +
params.merge(Accept: request.accept.map(&:to_s)).map {|k,v| "#{k}=#{v}" unless k.to_s == "content"}.join(" ")
end

get '/' do
if params["query"]
query = params["query"].to_s.match(/^http:/) ? RDF::Util::File.open_file(params["query"]) : ::CGI.unescape(params["query"].to_s)
SPARQL.execute(query, settings.repository)
else
settings.sparql_options.replace(standard_prefixes: true)
settings.sparql_options.merge!(:prefixes => {
ssd: "http://www.w3.org/ns/sparql-service-description#",
void: "http://rdfs.org/ns/void#"
})
service_description(repo: settings.repository, endpoint: url)
end
end

post '/' do
SPARQL.execute(params['query'], settings.repository)
end
end
app = SPARQL::Server.application(**options)
Rack::Server.start(app: app, Port: options.fetch(:port, 9292))
rescue LoadError
$stderr.puts "Running SPARQL server requires Rack to be in environment: #{$!.message}"
$stderr.puts "Running SPARQL server requires Rack and Sinatra to be in environment: #{$!.message}"
end

def usage
Expand Down
8 changes: 5 additions & 3 deletions etc/doap.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

<https://rubygems.org/gems/sparql> a doap:Project;
doap:name "Ruby SPARQL";
doap:shortdesc "SPARQL library for Ruby."@en;
doap:description "SPARQL Implements SPARQL 1.1 Query, Update and result formats for the Ruby RDF.rb library suite."@en;
doap:shortdesc "SPARQL Query and Update library for Ruby."@en;
doap:description "SPARQL Implements SPARQL 1.1 Query, Update, Protocol and result formats for the Ruby RDF.rb library suite."@en;
doap:implements <https://www.w3.org/TR/sparql11-query/>,
<https://www.w3.org/TR/sparql11-protocol/>,
<https://www.w3.org/TR/sparql11-update/>,
<https://www.w3.org/TR/sparql11-results-json/>,
<https://www.w3.org/TR/sparql11-results-csv-tsv/>,
Expand All @@ -33,14 +34,15 @@

<https://greggkellogg.net/foaf#me> a foaf:Person;
foaf:homepage <https://greggkellogg.net/>;
foaf:made <>;
foaf:mbox <mailto:[email protected]>;
foaf:mbox_sha1sum "35bc44e6d0070e5ad50ccbe0d24403c96af2b9bd";
foaf:name "Gregg Kellogg" .

<https://ar.to/#self> a foaf:Person;
foaf:homepage <https://ar.to/>;
foaf:made <>;
foaf:mbox <mailto:arto[email protected]>;
foaf:mbox <mailto:arto@bendiken.net>;
foaf:mbox_sha1sum "a033f652c84a4d73b8c26d318c2395699dd2bdfb",
"d0737cceb55eb7d740578d2db1bc0727e3ed49ce";
foaf:name "Arto Bendiken" .
Loading

0 comments on commit 4b29a2b

Please sign in to comment.