rdf-agraph 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +30 -17
- data/VERSION +1 -1
- data/lib/rdf/allegro_graph/abstract_repository.rb +44 -13
- data/lib/rdf/allegro_graph/functors.rb +5 -0
- data/lib/rdf/allegro_graph/query.rb +7 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# rdf-agraph: Ruby AllegroGraph adapter for RDF.rb
|
2
2
|
|
3
|
-
[
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
[AllegroGraph][allegrograph]® is a commercial RDF data store.
|
4
|
+
AllegroGraph supports ACID transactions, federation, Prolog-style queries
|
5
|
+
and social network analysis. You can run [AllegroGraph Free Edition][free]
|
6
|
+
on 64-bit Linux systems and store up to 50 million triples. (See below for
|
7
|
+
installation instructions.)
|
8
|
+
|
9
|
+
[RDF.rb][rdfrb] is an excellent Ruby library for working with RDF. It
|
10
|
+
supports a huge variety of RDF repositories and formats, and it's very
|
11
|
+
convenient to use.
|
7
12
|
|
8
13
|
This gem provides an optimized implementaton of RDF.rb's `Repository`
|
9
14
|
interface. It supports bulk loads, bulk deletes, optimized statement
|
@@ -15,8 +20,8 @@ Note, however, that this gem exposes only a small fraction of
|
|
15
20
|
AllegroGraph's features. To help add more features, see
|
16
21
|
[Contributing](#Contributing_to_rdf-agraph) below.
|
17
22
|
|
18
|
-
* [
|
19
|
-
* [
|
23
|
+
* [Documentation][doc]
|
24
|
+
* [GitHub project][src]
|
20
25
|
|
21
26
|
This code is a wrapper around [phifty's `agraph` gem][agraph_gem], which
|
22
27
|
provides a low-level interface to AllegroGraph over HTTP.
|
@@ -114,8 +119,8 @@ To query for all statements about a subject, try:
|
|
114
119
|
# <http://example.com/susan> <http://xmlns.com/foaf/0.1/knows> <http://example.com/rachel> .
|
115
120
|
# <http://example.com/susan> <http://xmlns.com/foaf/0.1/knows> <http://example.com/richard> .
|
116
121
|
|
117
|
-
|
118
|
-
|
122
|
+
You can also perform fully-optimized queries using RDF.rb's Basic Graph
|
123
|
+
Patterns. For example, to query for all people with known names:
|
119
124
|
|
120
125
|
repo.build_query do |q|
|
121
126
|
q.pattern [:person, RDF.type, FOAF.Person]
|
@@ -183,7 +188,7 @@ For more ideas, check out the following websites:
|
|
183
188
|
* [Spira][spira]: Define Ruby model objects for RDF data.
|
184
189
|
|
185
190
|
[agraph_doc]: http://www.franz.com/agraph/support/documentation/v4/
|
186
|
-
[sna]: http://www.franz.com/agraph/support/documentation/v4/python-tutorial/python-tutorial-40.html#Social
|
191
|
+
[sna]: http://www.franz.com/agraph/support/documentation/v4/python-tutorial/python-tutorial-40.html#Social%20Network%20Analysis
|
187
192
|
[spira]: http://spira.rubyforge.org/
|
188
193
|
|
189
194
|
## Comparisons with Other Gems
|
@@ -195,7 +200,8 @@ this information may be out of date!
|
|
195
200
|
### agraph vs. rdf-agraph
|
196
201
|
|
197
202
|
`rdf-agraph` is a wrapper around [phifty's `agraph` gem][agraph_gem], which
|
198
|
-
provides a low-level interface to AllegroGraph over HTTP.
|
203
|
+
provides a low-level interface to AllegroGraph over HTTP. This gem relies
|
204
|
+
heavily on his work!
|
199
205
|
|
200
206
|
* `agraph` provides a richer API for working with geometric primitives,
|
201
207
|
which we don't yet export.
|
@@ -203,8 +209,8 @@ provides a low-level interface to AllegroGraph over HTTP.
|
|
203
209
|
builder, and better support for Social Network Analysis.
|
204
210
|
* `agraph` works with raw, serialized RDF values. URLs, for example are
|
205
211
|
represented as `"<http://example.com/>"` and strings are represented as
|
206
|
-
`"\"Hello\""`. The `rdf-agraph` gem uses high-level
|
207
|
-
by RDF.rb.
|
212
|
+
`"\"Hello\""`. The `rdf-agraph` gem, on the other hand, uses high-level
|
213
|
+
Ruby objects defined by RDF.rb.
|
208
214
|
* `rdf-agraph` is compatible with the huge range of RDF formats and
|
209
215
|
repositories supported by RDF.rb.
|
210
216
|
|
@@ -218,7 +224,8 @@ it has very few optimizations.
|
|
218
224
|
* `rdf-sesame` tends to silently ignore network errors and return default
|
219
225
|
values.
|
220
226
|
* At the time of writing, `rdf-sesame` sends HTTP requests of the form `GET
|
221
|
-
http://example.com/path HTTP/1.1`, which do not work with AllegroGraph
|
227
|
+
http://example.com/path HTTP/1.1`, which do not work with AllegroGraph's
|
228
|
+
Sesame endpoint.
|
222
229
|
|
223
230
|
### sparql-client vs. rdf-agraph
|
224
231
|
|
@@ -228,8 +235,8 @@ it has very few optimizations.
|
|
228
235
|
Instead, it implements a custom SPARQL DSL (domain-specific language).
|
229
236
|
This means that it can perform sophisticated queries, but it can't update
|
230
237
|
the contents of the repository.
|
231
|
-
* `rdf-agraph` can run raw SPARQL and queries, but does not provide
|
232
|
-
complete DSL for building either kind of query.
|
238
|
+
* `rdf-agraph` can run raw SPARQL and Prolog queries, but does not provide
|
239
|
+
a complete DSL for building either kind of query.
|
233
240
|
|
234
241
|
## Installing AllegroGraph
|
235
242
|
|
@@ -261,7 +268,7 @@ Save this as `/usr/local/bin/agraph-service` and run:
|
|
261
268
|
|
262
269
|
## A Warning About `fork`
|
263
270
|
|
264
|
-
If you
|
271
|
+
If you insert statements containing blank nodes into an
|
265
272
|
RDF::AllegroGraph::Repository, the repository will generate and store a
|
266
273
|
list of blank node IDs. If you later call `fork` (perhaps because you are
|
267
274
|
running Unicorn or Spork), you may cause this cache of unused blank node
|
@@ -290,7 +297,7 @@ on constructing the ideal patch:
|
|
290
297
|
in the past. :-)
|
291
298
|
* Provide [RSpec][rspec] specifications for the fix. This may feel like a
|
292
299
|
nuisance, but it ensures that your new feature will still work correctly
|
293
|
-
two releases from now
|
300
|
+
two releases from now. I can help you with this if you're not familiar
|
294
301
|
with RSpec.
|
295
302
|
* Document any new APIs using [yard][yard].
|
296
303
|
|
@@ -303,3 +310,9 @@ Thank you for contributing to `rdf-agraph`!
|
|
303
310
|
[git_commit_message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
304
311
|
[rspec]: http://relishapp.com/rspec
|
305
312
|
[yard]: http://yardoc.org/
|
313
|
+
|
314
|
+
## Acknowledgements
|
315
|
+
|
316
|
+
Many thanks to the following people for helping to improve `rdf-agraph`:
|
317
|
+
|
318
|
+
* Aymeric Brisse: Unit tests for AllegroGraph inference.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -167,10 +167,16 @@ module RDF::AllegroGraph
|
|
167
167
|
# @see RDF::Queryable#query
|
168
168
|
# @see RDF::Query#execute
|
169
169
|
def query_execute(query, &block)
|
170
|
+
query_options =
|
171
|
+
if query.respond_to?(:query_options)
|
172
|
+
query.query_options
|
173
|
+
else
|
174
|
+
{}
|
175
|
+
end
|
170
176
|
if query.respond_to?(:requires_prolog?) && query.requires_prolog?
|
171
|
-
prolog_query(query.to_prolog(self), &block)
|
177
|
+
prolog_query(query.to_prolog(self), query_options, &block)
|
172
178
|
else
|
173
|
-
sparql_query(query_to_sparql(query), &block)
|
179
|
+
sparql_query(query_to_sparql(query), query_options, &block)
|
174
180
|
end
|
175
181
|
end
|
176
182
|
protected :query_execute
|
@@ -191,13 +197,17 @@ module RDF::AllegroGraph
|
|
191
197
|
# @return [Enumerator<RDF::Query::Solution>]
|
192
198
|
#
|
193
199
|
# @param [String] query The query to run.
|
200
|
+
# @param [Hash{Symbol => Object}] query_options
|
201
|
+
# The query options (see build_query).
|
194
202
|
# @return [void]
|
195
203
|
# @note This function returns a single-use Enumerator! If you want to
|
196
204
|
# to treat the results as an array, call `to_a` on it, or you will
|
197
205
|
# re-run the query against the server repeatedly. This curious
|
198
206
|
# decision is made for consistency with RDF.rb.
|
199
|
-
|
200
|
-
|
207
|
+
#
|
208
|
+
# @see #build_query
|
209
|
+
def sparql_query(query, query_options={}, &block)
|
210
|
+
raw_query(:sparql, query, query_options, &block)
|
201
211
|
end
|
202
212
|
|
203
213
|
# Run a raw Prolog query.
|
@@ -212,19 +222,32 @@ module RDF::AllegroGraph
|
|
212
222
|
# @return [Enumerator<RDF::Query::Solution>]
|
213
223
|
#
|
214
224
|
# @param [String] query The query to run.
|
225
|
+
# @param [Hash{Symbol => Object}] query_options
|
226
|
+
# The query options (see build_query).
|
215
227
|
# @return [void]
|
216
228
|
# @note This function returns a single-use Enumerator! If you want to
|
217
229
|
# to treat the results as an array, call `to_a` on it, or you will
|
218
230
|
# re-run the query against the server repeatedly. This curious
|
219
231
|
# decision is made for consistency with RDF.rb.
|
220
|
-
|
221
|
-
|
232
|
+
#
|
233
|
+
# @see #build_query
|
234
|
+
def prolog_query(query, query_options={}, &block)
|
235
|
+
raw_query(:prolog, query, query_options, &block)
|
222
236
|
end
|
223
237
|
|
224
238
|
# Run a raw query in the specified language.
|
225
|
-
def raw_query(language, query, &block)
|
226
|
-
|
227
|
-
|
239
|
+
def raw_query(language, query, query_options={}, &block)
|
240
|
+
# Build our query parameters.
|
241
|
+
params = {
|
242
|
+
:query => query,
|
243
|
+
:queryLn => language.to_s
|
244
|
+
}
|
245
|
+
params[:infer] = query_options[:infer].to_s if query_options[:infer]
|
246
|
+
|
247
|
+
# Run the query and process the results.
|
248
|
+
json = @repo.request_json(:get, path, :parameters => params,
|
249
|
+
:expected_status_code => 200)
|
250
|
+
results = json_to_query_solutions(json)
|
228
251
|
if block_given?
|
229
252
|
results.each {|s| yield s }
|
230
253
|
else
|
@@ -235,6 +258,10 @@ module RDF::AllegroGraph
|
|
235
258
|
|
236
259
|
# Construct an AllegroGraph-specific query.
|
237
260
|
#
|
261
|
+
# @param [Hash{Symbol => Object}] query_options
|
262
|
+
# @option query_options [true,false,String] :infer
|
263
|
+
# The AllegroGraph inference mode to use. Defaults to `false`. The
|
264
|
+
# value `true` is equivalent to `'rdfs++'`.
|
238
265
|
# @yield query
|
239
266
|
# @yieldparam [Query] The query to build. Use the Query API to add
|
240
267
|
# patterns and functors.
|
@@ -243,8 +270,8 @@ module RDF::AllegroGraph
|
|
243
270
|
#
|
244
271
|
# @see Query
|
245
272
|
# @see RDF::Query
|
246
|
-
def build_query(&block)
|
247
|
-
Query.new(self, &block)
|
273
|
+
def build_query(query_options={}, &block)
|
274
|
+
Query.new(self, query_options, &block)
|
248
275
|
end
|
249
276
|
|
250
277
|
|
@@ -351,8 +378,12 @@ module RDF::AllegroGraph
|
|
351
378
|
protected
|
352
379
|
|
353
380
|
# Build a repository-relative path.
|
354
|
-
def path(relative_path)
|
355
|
-
|
381
|
+
def path(relative_path=nil)
|
382
|
+
if relative_path
|
383
|
+
"#{@repo.path}/#{relative_path}"
|
384
|
+
else
|
385
|
+
@repo.path
|
386
|
+
end
|
356
387
|
end
|
357
388
|
|
358
389
|
# Deserialize an RDF::Value received from the server, or an array of such
|
@@ -1,4 +1,9 @@
|
|
1
1
|
# AllegroGraph functors for use in Prolog queries.
|
2
|
+
#
|
3
|
+
# Note that we only support a few functors right now. For a list of all
|
4
|
+
# available AllegroGraph functors, see
|
5
|
+
# <http://www.franz.com/agraph/support/documentation/v4/lisp-reference.html>.
|
6
|
+
# Adding new functors is easy; see SnaFunctors for examples.
|
2
7
|
module RDF::AllegroGraph::Functors
|
3
8
|
autoload :SnaFunctors, 'rdf/allegro_graph/functors/sna_functors'
|
4
9
|
end
|
@@ -19,10 +19,16 @@ module RDF::AllegroGraph
|
|
19
19
|
# Include our APIs.
|
20
20
|
include Functors::SnaFunctors
|
21
21
|
|
22
|
+
# Our query options.
|
23
|
+
#
|
24
|
+
# @see AbstractRepository#build_query
|
25
|
+
attr_reader :query_options
|
26
|
+
|
22
27
|
# Create a new query.
|
23
28
|
# @private
|
24
|
-
def initialize(repository, &block)
|
29
|
+
def initialize(repository, query_options={}, &block)
|
25
30
|
@repository = repository
|
31
|
+
@query_options = query_options
|
26
32
|
super(&block)
|
27
33
|
end
|
28
34
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-agraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Kidd
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-19 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
requirements: []
|
220
220
|
|
221
221
|
rubyforge_project: rdf-agraph
|
222
|
-
rubygems_version: 1.
|
222
|
+
rubygems_version: 1.4.1
|
223
223
|
signing_key:
|
224
224
|
specification_version: 3
|
225
225
|
summary: AllegroGraph adapter for RDF.rb
|