redlander 0.5.0 → 0.5.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/ChangeLog +5 -0
- data/Gemfile.lock +5 -5
- data/lib/redland.rb +1 -0
- data/lib/redlander/model.rb +2 -2
- data/lib/redlander/query/results.rb +11 -6
- data/lib/redlander/version.rb +1 -1
- data/redlander.gemspec +1 -1
- data/spec/lib/redlander/model_spec.rb +32 -14
- data/spec/lib/redlander/node_spec.rb +1 -1
- metadata +6 -6
data/ChangeLog
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redlander (0.5.
|
4
|
+
redlander (0.5.1)
|
5
5
|
ffi (~> 1.1)
|
6
|
-
xml_schema (~> 0.1.
|
6
|
+
xml_schema (~> 0.1.3)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
diff-lcs (1.1.3)
|
12
|
-
ffi (1.1.
|
12
|
+
ffi (1.1.2)
|
13
13
|
rake (0.9.2.2)
|
14
14
|
rspec (2.11.0)
|
15
15
|
rspec-core (~> 2.11.0)
|
16
16
|
rspec-expectations (~> 2.11.0)
|
17
17
|
rspec-mocks (~> 2.11.0)
|
18
18
|
rspec-core (2.11.1)
|
19
|
-
rspec-expectations (2.11.
|
19
|
+
rspec-expectations (2.11.2)
|
20
20
|
diff-lcs (~> 1.1.3)
|
21
21
|
rspec-mocks (2.11.1)
|
22
|
-
xml_schema (0.1.
|
22
|
+
xml_schema (0.1.3)
|
23
23
|
|
24
24
|
PLATFORMS
|
25
25
|
ruby
|
data/lib/redland.rb
CHANGED
@@ -107,5 +107,6 @@ module Redland
|
|
107
107
|
attach_function :librdf_query_results_as_stream, [:pointer], :pointer
|
108
108
|
attach_function :librdf_query_results_next, [:pointer], :int
|
109
109
|
attach_function :librdf_query_results_finished, [:pointer], :int
|
110
|
+
attach_function :librdf_query_results_get_count, [:pointer], :int
|
110
111
|
attach_function :librdf_free_query_results, [:pointer], :void
|
111
112
|
end
|
data/lib/redlander/model.rb
CHANGED
@@ -99,9 +99,9 @@ module Redlander
|
|
99
99
|
# if given a block, yields each binding hash to it
|
100
100
|
# - nil, if query fails
|
101
101
|
# @raise [RedlandError] if fails to create a query
|
102
|
-
def query(q, options = {})
|
102
|
+
def query(q, options = {}, &block)
|
103
103
|
query = Query::Results.new(q, options)
|
104
|
-
query.process(self)
|
104
|
+
query.process(self, &block)
|
105
105
|
end
|
106
106
|
|
107
107
|
# Merge statements from another model
|
@@ -19,19 +19,21 @@ module Redlander
|
|
19
19
|
def process(model)
|
20
20
|
@rdf_results = Redland.librdf_model_query_execute(model.rdf_model, @rdf_query)
|
21
21
|
|
22
|
-
|
23
|
-
return nil
|
24
|
-
else
|
22
|
+
begin
|
25
23
|
case
|
26
24
|
when bindings?
|
27
25
|
if block_given?
|
26
|
+
return nil if @rdf_results.null?
|
28
27
|
each { yield process_bindings }
|
29
28
|
else
|
29
|
+
return [] if @rdf_results.null?
|
30
30
|
map { process_bindings }
|
31
31
|
end
|
32
32
|
when boolean?
|
33
|
+
return nil if @rdf_results.null?
|
33
34
|
process_boolean
|
34
35
|
when graph?
|
36
|
+
return nil if @rdf_results.null?
|
35
37
|
if block_given?
|
36
38
|
process_graph { |statement| yield statement }
|
37
39
|
else
|
@@ -42,9 +44,9 @@ module Redlander
|
|
42
44
|
else
|
43
45
|
raise RedlandError, "Cannot determine the type of query results"
|
44
46
|
end
|
47
|
+
ensure
|
48
|
+
Redland.librdf_free_query_results(@rdf_results)
|
45
49
|
end
|
46
|
-
ensure
|
47
|
-
Redland.librdf_free_query_results(@rdf_results)
|
48
50
|
end
|
49
51
|
|
50
52
|
def each
|
@@ -82,7 +84,10 @@ module Redlander
|
|
82
84
|
while n > 0
|
83
85
|
name = Redland.librdf_query_results_get_binding_name(@rdf_results, n-1)
|
84
86
|
value = Redland.librdf_query_results_get_binding_value(@rdf_results, n-1)
|
85
|
-
|
87
|
+
unless value.null?
|
88
|
+
bindings[name] = Node.new(value)
|
89
|
+
Redland.librdf_free_node(value)
|
90
|
+
end
|
86
91
|
n -= 1
|
87
92
|
end
|
88
93
|
end
|
data/lib/redlander/version.rb
CHANGED
data/redlander.gemspec
CHANGED
@@ -18,7 +18,7 @@ HERE
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
# gem.add_dependency("librdf0", "~> 1.0.14")
|
21
|
-
gem.add_dependency("xml_schema", "~> 0.1.
|
21
|
+
gem.add_dependency("xml_schema", "~> 0.1.3")
|
22
22
|
gem.add_dependency("ffi", "~> 1.1")
|
23
23
|
gem.add_development_dependency("rspec", "~> 2")
|
24
24
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe Model do
|
@@ -20,27 +21,44 @@ describe Model do
|
|
20
21
|
end
|
21
22
|
|
22
23
|
describe "query" do
|
23
|
-
|
24
|
+
let(:project) { URI("http://rubygems.org/gems/rdf") }
|
24
25
|
subject { model.query(q) }
|
26
|
+
before { model.from_file(Redlander.fixture_path("doap.ttl"), :format => "turtle") }
|
25
27
|
|
26
28
|
describe "SPARQL" do
|
27
29
|
describe "SELECT" do
|
28
|
-
|
30
|
+
context "for a single result" do
|
31
|
+
let(:q) { "PREFIX doap: <http://usefulinc.com/ns/doap#> SELECT ?subject WHERE { ?subject doap:name 'RDF.rb' . ?subject doap:platform 'Ruby' }" }
|
29
32
|
|
30
|
-
|
33
|
+
it { should be_a Enumerable }
|
34
|
+
|
35
|
+
it "should return an array of binding hashes" do
|
36
|
+
expect(subject.size).to eql 1
|
37
|
+
expect(subject.first["subject"]).to be_a Redlander::Node
|
38
|
+
expect(subject.first["subject"].value).to eql project
|
39
|
+
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
context "with a block" do
|
42
|
+
it "should yield a binding hash" do
|
43
|
+
model.query(q) do |binding|
|
44
|
+
expect(binding).to be_a Hash
|
45
|
+
expect(binding["subject"]).to be_a Redlander::Node
|
46
|
+
expect(binding["subject"].value).to eql project
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
38
|
-
context "
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
context "for multiple results" do
|
53
|
+
let(:q) { "PREFIX doap: <http://usefulinc.com/ns/doap#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { <http://rubygems.org/gems/rdf> doap:helper [ foaf:name ?name ] }" }
|
54
|
+
|
55
|
+
it "should yield multiple bindings" do
|
56
|
+
# TODO: librdf screws up the input UTF-8 encoding
|
57
|
+
helpers = ["C\\u0103lin Ardelean", "Danny Gagne", "Joey Geiger", "Fumihiro Kato", "Naoki Kawamukai", "Hellekin O. Wolf", "John Fieber", "Keita Urashima", "Pius Uzamere"]
|
58
|
+
|
59
|
+
expect(subject.size).to eql helpers.size
|
60
|
+
subject.each do |binding|
|
61
|
+
expect(helpers).to include binding["name"].value
|
44
62
|
end
|
45
63
|
end
|
46
64
|
end
|
@@ -125,7 +143,7 @@ describe Model do
|
|
125
143
|
|
126
144
|
it "should be iterated over" do
|
127
145
|
expect {
|
128
|
-
|
146
|
+
model.statements.each { |s| @statements << s }
|
129
147
|
}.to change(@statements, :count).by(1)
|
130
148
|
expect(@statements).to include @statement
|
131
149
|
end
|
@@ -49,7 +49,7 @@ describe Node do
|
|
49
49
|
it "should create an integer number literal" do
|
50
50
|
node = Node.new(10)
|
51
51
|
node.should be_literal
|
52
|
-
node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#
|
52
|
+
node.datatype.should eql URI("http://www.w3.org/2001/XMLSchema#integer")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should create a floating-point number literal" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redlander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xml_schema
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.1.
|
21
|
+
version: 0.1.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.1.
|
29
|
+
version: 0.1.3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: ffi
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
segments:
|
119
119
|
- 0
|
120
|
-
hash:
|
120
|
+
hash: 302731036018920791
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
none: false
|
123
123
|
requirements:
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: 302731036018920791
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
132
|
rubygems_version: 1.8.24
|