This is a Ruby implementation of a SPARQL client for RDF.rb.
- Executes queries against any SPARQL 1.0/1.1-compatible endpoint over HTTP,
or against an
RDF::Queryable
instance, using theSPARQL
gem. - Provides a query builder DSL for
ASK
,SELECT
,DESCRIBE
andCONSTRUCT
queries. - Includes preliminary support for some SPARQL 1.1 Update operations.
- Supports tuple result sets in both XML, JSON, CSV and TSV formats, with JSON being the preferred default for content-negotiation purposes.
- Supports graph results in any RDF serialization format understood by RDF.rb.
- Returns results using the RDF.rb object model.
- Supports accessing endpoints as read/write
RDF::Repository
instances {SPARQL::Client::Repository}.
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
By default, SPARQL::Client adds a User-Agent
field to requests, but applications may choose to provide their own, using the headers
option:
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", headers: {'User-Agent' => 'MyBotName'})
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", graph: "http://dbpedia.org")
require 'rdf/trig'
repository = RDF::Repository.load("http://example/dataset.trig")
sparql = SPARQL::Client.new(repository)
# ASK WHERE { ?s ?p ?o }
result = sparql.ask.whether([:s, :p, :o]).true?
puts result.inspect #=> true or false
# SELECT * WHERE { ?s ?p ?o } OFFSET 100 LIMIT 10
query = sparql.select.where([:s, :p, :o]).offset(100).limit(10)
query.each_solution do |solution|
puts solution.inspect
end
# CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } LIMIT 10
query = sparql.construct([:s, :p, :o]).where([:s, :p, :o]).limit(10)
query.each_statement do |statement|
puts statement.inspect
end
result = sparql.query("ASK WHERE { ?s ?p ?o }")
puts result.inspect #=> true or false
# INSERT DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
data = RDF::Graph.new do |graph|
graph << [RDF::URI('http://example.org/jhacker'), RDF::Vocab::FOAF.name, "J. Random Hacker"]
end
sparql.insert_data(data)
# DELETE DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
data = RDF::Graph.new do |graph|
graph << [RDF::URI('http://example.org/jhacker'), RDF::Vocab::FOAF.name, "J. Random Hacker"]
end
sparql.delete_data(data)
- Ruby (>= 3.0)
- RDF.rb (~> 3.3)
- Net::HTTP::Persistent (~> 4.0, >= 4.0.1)
- Soft dependency on SPARQL (~> 3.3)
- Soft dependency on Nokogiri (>= 1.15)
The recommended installation method is via RubyGems.
To install the latest official release of the SPARQL::Client
gem, do:
% [sudo] gem install sparql-client
To get a local working copy of the development repository, do:
% git clone git://github.com/ruby-rdf/sparql-client.git
Alternatively, download the latest development version as a tarball as follows:
% wget https://github.com/ruby-rdf/sparql-client/tarball/master
- Arto Bendiken - https://ar.to/
- Ben Lavender - https://bhuga.net/
- Gregg Kellogg - https://greggkellogg.net/
- Christoph Badura - https://github.com/bad
- James Hetherington - https://twitter.com/jamespjh
- Gabriel Horner - https://tagaholic.me/
- Nicholas Humfrey - https://www.aelius.com/njh/
- Fumihiro Kato - https://fumi.me/
- David Nielsen - https://github.com/drankard
- Thamaraiselvan Poomalai - https://softonaut.blogspot.com/
- Michael Sokol - https://sokolmichael.com/
- Yves Raimond - https://moustaki.org/
- Thomas Feron - https://github.com/thoferon
- Nick Gottlieb - https://www.nicholasgottlieb.com
This repository uses Git Flow to mange development and release activity. All submissions must be on a feature branch based on the develop branch to ease staging and integration.
- Do your best to adhere to the existing coding conventions and idioms.
- Don't use hard tabs, and don't leave trailing whitespace on any line.
- Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.
- Don't touch the
.gemspec
,VERSION
orAUTHORS
files. If you need to change them, do so on your private branch only. - Do feel free to add yourself to the
CREDITS
file and the corresponding list in the theREADME
. Alphabetical order applies. - Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you, which you will be asked to agree to on the first commit to a repo within the organization. Note that the agreement applies to all repos in the Ruby RDF organization.
- https://ruby-rdf.github.io/sparql-client/
- https://github.com/ruby-rdf/sparql-client
- https://rubygems.org/gems/sparql-client
- https://raa.ruby-lang.org/project/sparql-client/
- https://www.ohloh.net/p/rdf
This is free and unencumbered public domain software. For more information, see https://unlicense.org/ or the accompanying {file:UNLICENSE} file.