• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Ruby
  • License
    The Unlicense
  • Created over 16 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SPARQL client for Ruby.

SPARQL Client for RDF.rb

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

Gem Version Build Status Coverage Status Gitter chat

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 https://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, 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.

Resources

License

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

More Repositories

1

rdf

RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
Ruby
382
star
2

json-ld

Ruby JSON-LD reader/writer for RDF.rb
HTML
231
star
3

sparql

Ruby SPARQL library
Ruby
89
star
4

spira

Spira is a framework for viewing RDF data as model objects
Ruby
58
star
5

linkeddata

A metadistribution of RDF.rb including all parsing/serialization plugins.
Ruby
51
star
6

rdf-vocab

Common RDF Vocabularies
Ruby
50
star
7

rdf-rdfa

Ruby RDFa reader/writer for RDF.rb.
HTML
35
star
8

trinity

[UNMAINTAINED] A minimalistic Ruby web framework for publishing Linked Data.
JavaScript
34
star
9

rdf-microdata

Ruby Microdata parser for RDF.rb
Ruby
33
star
10

rdf-turtle

Turtle reader/writer for Ruby
Ruby
31
star
11

rdf-raptor

RDF.rb extension for parsing/serializing RDF/XML, Turtle and RDFa data using the Raptor RDF library.
Ruby
27
star
12

rack-linkeddata

Rack middleware for Linked Data content negotiation.
Ruby
25
star
13

rdf-n3

Ruby Notation-3 reader/writer for RDF.rb.
HTML
24
star
14

rdf-sesame

RDF.rb plugin for accessing Sesame 2.0-compatible repositories.
Ruby
23
star
15

rdf-reasoner

Creates triples for various entailment regimes of a vocabulary for enabling SPARQL 1.1 Entailment
Ruby
18
star
16

rdf-virtuoso

Ruby Virtuoso repository adapter for RDF.rb
Ruby
17
star
17

rdf-tabular

Tabular Data RDF Reader and JSON serializer
HTML
17
star
18

rdf-rdfxml

Ruby RDF/XML reader/writer for RDF.rb.
Ruby
17
star
19

rdf-json

RDF.rb plugin for parsing/serializing RDF/JSON data.
Ruby
16
star
20

rdfs

[OBSOLETE] A forward-chaining inference engine that implements the RDFS entailment rules.
Ruby
15
star
21

sinatra-linkeddata

Sinatra extension for Linked Data content negotiation.
Ruby
13
star
22

rdf-ldp

A suite of LDP software and middleware for RDF.rb & Rack
Ruby
13
star
23

shex

HTML
12
star
24

rdf-do

DataObjects-backed repositories for RDF.rb
Ruby
12
star
25

rdf-spec

RDF.rb plugin that provides RSpec matchers and shared examples for RDF objects.
Ruby
12
star
26

rdf-trig

TriG reader/writer for RDF.rb
Ruby
9
star
27

shacl

Implementation of Shapes Constraint Language (SHACL) for RDF.rb
Ruby
8
star
28

rdf-blazegraph

A Ruby RDF::Repository for Blazegraph
Ruby
7
star
29

json-ld-preloaded

A meta-release of the json-ld gem including preloaded vocabularies
Ruby
7
star
30

rdf-normalize

RDF Graph normalizer for Ruby.
Ruby
7
star
31

rdf-xsd

Extended XSD Datatypes for RDF.rb
Ruby
6
star
32

rack-sparql

Rack middleware providing a SPARQL 1.0-compatible HTTP endpoint.
Ruby
6
star
33

ld-patch

Ruby implementation of the W3C Linked Data Patch Format
HTML
6
star
34

rdf-talis

[OBSOLETE] Talis storage adapter for RDF.rb
Ruby
5
star
35

rdf-source

[UNMAINTAINED] Module to simplify creation of RDF from existing Ruby stuff
Ruby
5
star
36

rdf-aggregate-repo

An aggregate RDF::Repository supporting a subset of named graphs and zero or more named graphs mapped to the default graph.
Ruby
5
star
37

rdf-trix

RDF.rb plugin for parsing/serializing TriX data.
Ruby
4
star
38

rdf-benchmark

A benchmark framework for RDF.rb
Ruby
4
star
39

rdf-marmotta

RDF::Repository implementation for Marmotta
Ruby
4
star
40

rdf-isomorphic

Isomorphism mixin for RDF.rb
Ruby
4
star
41

rack-sesame

Rack middleware providing a Sesame 2.0-compatible HTTP endpoint.
Ruby
4
star
42

rdf-vcf

RDF.rb reader for Variant Call Format (VCF) files.
Ruby
3
star
43

rdf-rasqal

[OBSOLETE] RDF.rb plugin for SPARQL query evaluation using the Rasqal RDF Query Library.
Ruby
3
star
44

yaml-ld

Ruby YAML-LD reader/writer for RDF.rb
Ruby
3
star
45

ruby-rdf.github.com

Source repository for the ruby-rdf.github.com website.
JavaScript
2
star
46

rdf-ordered-repo

An implementation of RDF::Repository using native hash structures with insertion-order preserving behavior.
Ruby
2
star
47

rdf-bert

[OBSOLETE] RDF.rb plugin for proxying repository operations over BERT-RPC.
Ruby
2
star
48

sparql-service-description

SPARQL Service Description Gem for creating SPARQL service description documents for datasets.
Ruby
1
star
49

rdf-arq

[OBSOLETE] RDF.rb plugin for using the ARQ query engine for SPARQL.
Java
1
star