redlander 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ redlander (0.5.1)
2
+
3
+ * fixed a memory leak in Model#query
4
+ * using xml_schema 0.1.3 to handle integer literals and "integer", not "int"
5
+
1
6
  redlander (0.5.0)
2
7
 
3
8
  * Model#query for queries in SPARQL (and other supported languages)
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redlander (0.5.0)
4
+ redlander (0.5.1)
5
5
  ffi (~> 1.1)
6
- xml_schema (~> 0.1.0)
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.0)
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.1)
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.0)
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
@@ -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
- if @rdf_results.null?
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
- bindings[name] = Node.new(value) unless value.null?
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
@@ -1,4 +1,4 @@
1
1
  module Redlander
2
2
  # Redlander version number
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
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.0")
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
- before { model.from_file(Redlander.fixture_path("doap.ttl"), :format => "turtle") }
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
- let(:q) { "PREFIX doap: <http://usefulinc.com/ns/doap#> SELECT ?name WHERE { <http://rubygems.org/gems/rdf> doap:name ?name }" }
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
- it { should be_a Enumerable }
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
- it "should return an array of binding hashes" do
33
- expect(subject.size).to eql 1
34
- expect(subject.first["name"]).to be_a Redlander::Node
35
- expect(subject.first["name"].value).to eql "RDF.rb"
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 "with a block" do
39
- it "should yield a binding hash" do
40
- subject do |binding|
41
- expect(binding).to be_a Hash
42
- expect(binding["name"]).to be_a Redlander::Node
43
- expect(binding["name"].value).to eql "RDF.rb"
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
- subject.each { |s| @statements << s }
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#int")
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.0
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-29 00:00:00.000000000 Z
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.0
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.0
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: -3720732623496571962
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: -3720732623496571962
129
+ hash: 302731036018920791
130
130
  requirements: []
131
131
  rubyforge_project:
132
132
  rubygems_version: 1.8.24