Skip to content
SPARQL client for Ruby.
Ruby
Branch: develop
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
etc Fix doap file. Jul 3, 2013
examples Use Travis "trusty" build and wildcard Ruby versions. Mar 31, 2017
lib/sparql Add `Client#close` to shutdown any HTTP connection and object finaliz… Jul 2, 2019
spec
.gitignore match code style in spec Nov 13, 2018
.travis.yml Run 2.2.2 on Travis. Jul 2, 2019
.yardopts Renamed the CONTRIBUTORS file to CREDITS. Sep 6, 2010
AUTHORS Corrected my email address in the AUTHORS file. Jan 11, 2013
CONTRIBUTING.md
CREDITS disable webmock for rdf-spec repo tests and reenable repo tests Oct 3, 2014
Gemfile Remove jruby-openssl from Gemfiles. Jul 2, 2019
Gemfile-pure Remove jruby-openssl from Gemfiles. Jul 2, 2019
README.md Add `Client#close` to shutdown any HTTP connection and object finaliz… Jul 2, 2019
Rakefile Remove require of 'sparql/client' from Rakefile. Sep 6, 2016
UNLICENSE Unlicensed the project into the public domain. Dec 20, 2009
VERSION Version 3.0.1. Dec 3, 2018
dependencyci.yml Skip depencency checking on rdf-isomorphic. Sep 2, 2016
sparql-client.gemspec Add `Client#close` to shutdown any HTTP connection and object finaliz… Jul 2, 2019

README.md

SPARQL Client for RDF.rb

This is a Ruby implementation of a SPARQL client for RDF.rb.

Gem Version Build Status Coverage Status

Features

  • Executes queries against any SPARQL 1.0/1.1-compatible endpoint over HTTP, or against an RDF::Queryable instance, using the SPARQL gem.
  • Provides a query builder DSL for ASK, SELECT, DESCRIBE and CONSTRUCT 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}.

Examples

Querying a remote SPARQL endpoint

require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")

Querying a remote SPARQL endpoint with a custom User-Agent

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'})

Querying a remote SPARQL endpoint with a specified default graph

require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql", { :graph => "http://dbpedia.org" })

Querying a RDF::Repository instance

require 'rdf/trig'
repository = RDF::Repository.load("http://example/dataset.trig")
sparql = SPARQL::Client.new(repository)

Executing a boolean query and outputting the result

# ASK WHERE { ?s ?p ?o }
result = sparql.ask.whether([:s, :p, :o]).true?
puts result.inspect   #=> true or false

Executing a tuple query and iterating over the returned solutions

# 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

Executing a graph query and iterating over the returned statements

# 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

Executing an arbitrary textual SPARQL query string

result = sparql.query("ASK WHERE { ?s ?p ?o }")

puts result.inspect   #=> true or false

Inserting data into a graph

# 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)

Deleting data from a graph

# 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)

Documentation

Dependencies

Installation

The recommended installation method is via RubyGems. To install the latest official release of the SPARQL::Client gem, do:

% [sudo] gem install sparql-client

Download

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 http://github.com/ruby-rdf/sparql-client/tarball/master

Mailing List

Authors

Contributors

Contributing

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 or AUTHORS 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 the README. 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.

Resources

License

This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying {file:UNLICENSE} file.

You can’t perform that action at this time.