@@ -25,70 +25,92 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
2525## Examples
2626
2727### Querying a remote SPARQL endpoint
28- require 'sparql/client'
2928
30- sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
29+ ``` ruby
30+ require ' sparql/client'
31+ sparql = SPARQL ::Client .new (" http://dbpedia.org/sparql" )
32+ ```
33+ ### Querying a remote SPARQL endpoint with a specified default graph
3134
32- ### Querying a ` RDF::Repository ` instance
35+ ``` ruby
36+ require ' sparql/client'
37+ sparql = SPARQL ::Client .new (" http://dbpedia.org/sparql" , { :graph => " http://dbpedia.org" })
38+ ```
3339
34- require 'rdf/trig'
35- repository = RDF::Repository.load("http://example/dataset.trig")
3640
37- sparql = SPARQL::Client.new(repository)
41+ ### Querying a ` RDF::Repository ` instance
3842
39- ### Executing a boolean query and outputting the result
43+ ``` ruby
44+ require ' rdf/trig'
45+ repository = RDF ::Repository .load (" http://example/dataset.trig" )
46+ sparql = SPARQL ::Client .new (repository)
47+ ```
4048
41- # ASK WHERE { ?s ?p ?o }
42- result = sparql.ask.whether([:s, :p, :o]).true?
49+ ### Executing a boolean query and outputting the result
4350
44- puts result.inspect #=> true or false
51+ ``` ruby
52+ # ASK WHERE { ?s ?p ?o }
53+ result = sparql.ask.whether([:s , :p , :o ]).true?
54+ puts result.inspect # => true or false
55+ ```
4556
4657### Executing a tuple query and iterating over the returned solutions
4758
48- # SELECT * WHERE { ?s ?p ?o } OFFSET 100 LIMIT 10
49- query = sparql.select.where([:s, :p, :o]).offset(100).limit(10)
59+ ``` ruby
60+ # SELECT * WHERE { ?s ?p ?o } OFFSET 100 LIMIT 10
61+ query = sparql.select .where([:s , :p , :o ]).offset(100 ).limit(10 )
5062
51- query.each_solution do |solution|
52- puts solution.inspect
53- end
63+ query.each_solution do |solution |
64+ puts solution.inspect
65+ end
66+ ```
5467
5568### Executing a graph query and iterating over the returned statements
5669
57- # CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } LIMIT 10
58- query = sparql.construct([:s, :p, :o]).where([:s, :p, :o]).limit(10)
5970
60- query.each_statement do |statement|
61- puts statement.inspect
62- end
71+ ``` ruby
72+ # CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } LIMIT 10
73+ query = sparql.construct([:s , :p , :o ]).where([:s , :p , :o ]).limit(10 )
74+
75+ query.each_statement do |statement |
76+ puts statement.inspect
77+ end
78+ ```
6379
6480### Executing an arbitrary textual SPARQL query string
6581
66- result = sparql.query("ASK WHERE { ?s ?p ?o }")
82+ ``` ruby
83+ result = sparql.query(" ASK WHERE { ?s ?p ?o }" )
6784
68- puts result.inspect #=> true or false
85+ puts result.inspect # => true or false
86+ ```
6987
7088### Inserting data into a graph
7189
72- # INSERT DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
73- data = RDF::Graph.new do |graph|
74- graph << [RDF::URI('http://example.org/jhacker'), RDF::Vocab::FOAF.name, "J. Random Hacker"]
75- end
76- sparql.insert_data(data)
90+ ``` ruby
91+ # INSERT DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
92+ data = RDF ::Graph .new do |graph |
93+ graph << [RDF ::URI (' http://example.org/jhacker' ), RDF ::Vocab ::FOAF .name, " J. Random Hacker" ]
94+ end
95+ sparql.insert_data(data)
96+ ```
7797
7898### Deleting data from a graph
7999
80- # DELETE DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
81- data = RDF::Graph.new do |graph|
82- graph << [RDF::URI('http://example.org/jhacker'), RDF::Vocab::FOAF.name, "J. Random Hacker"]
83- end
84- sparql.delete_data(data)
100+ ``` ruby
101+ # DELETE DATA { <http://example.org/jhacker> <http://xmlns.com/foaf/0.1/name> "J. Random Hacker" .}
102+ data = RDF ::Graph .new do |graph |
103+ graph << [RDF ::URI (' http://example.org/jhacker' ), RDF ::Vocab ::FOAF .name, " J. Random Hacker" ]
104+ end
105+ sparql.delete_data(data)
106+ ```
85107
86108## Documentation
87109
88- * { SPARQL::Client}
89- * { SPARQL::Client::Query}
90- * { SPARQL::Client::Repository}
91- * { SPARQL::Client::Update}
110+ * [ SPARQL::Client] ( https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client )
111+ * [ SPARQL::Client::Query] ( https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Query )
112+ * [ SPARQL::Client::Repository] ( https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Repository )
113+ * [ SPARQL::Client::Update] ( https://www.rubydoc.info/github/ruby-rdf/sparql-client/SPARQL/Client/Update )
92114
93115## Dependencies
94116
0 commit comments