redlander 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp/
18
18
  .bundle
19
19
  .yardoc/
20
20
  doc/
21
+ bin/
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ redlander (0.5.3)
2
+
3
+ * using crossplatform-compatible FFI (makes MacOSX happy)
4
+ * transaction block returns the result of block evaluation
5
+
1
6
  redlander (0.5.2)
2
7
 
3
8
  * UTF-8 output for Node#value
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redlander (0.5.2)
5
- ffi (~> 1.1)
4
+ redlander (0.5.3)
5
+ ffi (~> 1.3)
6
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.2)
13
- rake (0.9.2.2)
14
- rspec (2.11.0)
15
- rspec-core (~> 2.11.0)
16
- rspec-expectations (~> 2.11.0)
17
- rspec-mocks (~> 2.11.0)
18
- rspec-core (2.11.1)
19
- rspec-expectations (2.11.2)
12
+ ffi (1.3.1)
13
+ rake (10.0.3)
14
+ rspec (2.12.0)
15
+ rspec-core (~> 2.12.0)
16
+ rspec-expectations (~> 2.12.0)
17
+ rspec-mocks (~> 2.12.0)
18
+ rspec-core (2.12.2)
19
+ rspec-expectations (2.12.1)
20
20
  diff-lcs (~> 1.1.3)
21
- rspec-mocks (2.11.1)
21
+ rspec-mocks (2.12.1)
22
22
  xml_schema (0.1.3)
23
23
 
24
24
  PLATFORMS
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Slava Kravchenko
1
+ Copyright (c) 2012,2013 Slava Kravchenko
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
@@ -0,0 +1,183 @@
1
+ # Redlander
2
+
3
+ Redlander is Ruby bindings to [Redland](http://librdf.org) library written in C,
4
+ which is used to manipulate RDF graphs. This is an alternative implementation
5
+ of Ruby bindings (as opposed to the official bindings), aiming to be more
6
+ intuitive, lightweight, high-performing and as bug-free as possible.
7
+
8
+ # Installing
9
+
10
+ Installing Redlander is simple:
11
+
12
+ $ gem install redlander
13
+
14
+ Note, that you will have to install Redland runtime library (librdf) for Redlander to work.
15
+
16
+ # Usage
17
+
18
+ This README outlines most obvious use cases.
19
+ For more details please refer to YARD documentation of Redlander.
20
+
21
+ To start doing anything useful with Redlander, you need to initialize a model first:
22
+
23
+ $ m = Redlander::Model.new
24
+
25
+ This creates a model where all RDF statements are stored in the memory.
26
+ Depending on the selected storage you may need to supply extra parameters
27
+ like `:user` or `:password`. Look-up the options for `Model.initialize`
28
+ for the list of available options.
29
+ Naturally, you don't need to create a model if you just want to play around
30
+ with independent statements, nodes and the like.
31
+
32
+ ## RDF Statements
33
+
34
+ Now that you have created a model, you can access its RDF statements:
35
+
36
+ $ m.statements
37
+
38
+ Most of Redlander functionality is accessable via these statements.
39
+ The API is almost identical to [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord):
40
+
41
+ $ s = URI.parse('http://example.com/concepts#subject')
42
+ $ p = URI.parse('http://example.com/concepts#label')
43
+ $ o = "subject!"
44
+ $ m.statements.create(:subject => s, :predicate => p, :object => o)
45
+
46
+ $ m.statements.empty? # => false
47
+
48
+ $ st = Redlander::Statement.new(:subject => s, :predicate => p, :object => "another label")
49
+ $ m.statements.add(st)
50
+
51
+ $ m.statements.size # => 2
52
+
53
+ $ m.statements.each { |st| puts st }
54
+
55
+ Finding statements:
56
+
57
+ $ m.statements.find(:first, :object => "subject!")
58
+ $ m.statements.all(:object => "another label")
59
+ $ m.statements.each(:object => "subject!") { |statement|
60
+ puts statement.subject
61
+ }
62
+
63
+ Note that `m.statements.each` is "lazy", while `m.statements.all` (and other finders) is not.
64
+
65
+ You can access the subject, predicate or object of a statement:
66
+
67
+ $ m.statements.first.subject # => (Redlander::Node)
68
+
69
+ Please refer to `Redlander::Node` API doc for details.
70
+
71
+ You can also use different query languages supported by [librdf](http://librdf.org/)
72
+ ("SPARQL 1.0" being a default):
73
+
74
+ $ m.query("SELECT ?s ?p ?o WHERE {}") # => [{"s" => ..., "p" => ..., "o" => ...}, ...]
75
+
76
+ *ASK* queries return true/false, *SELECT* queries return arrays of binding hashes,
77
+ *CONSTRUCT* queries return an instance of a new memory-based model comprised from
78
+ the statements constructed by the query.
79
+ You can also supply a block to `Model#query`, which is ignored by *ASK* queries, but
80
+ yields the statements constructed by *CONSTRUCT* queries and yields the binding
81
+ hash for *SELECT* queries. Binding hash values are instances of `Redlander::Node`.
82
+
83
+ For query options and available query languages refer to `Model#query` documentation.
84
+
85
+
86
+ ## Parsing Input
87
+
88
+ You can fill your model with statements by parsing some external sources like plain or streamed data.
89
+
90
+ $ data = File.read("data.xml")
91
+ $ m.from(data, :format => "rdfxml")
92
+
93
+ If the input is too large, you may prefer streaming it:
94
+
95
+ $ source = URI("http://example.com/data.nt")
96
+ $ m.from(source, :format => "ntriples")
97
+
98
+ If you want to get the data from a local file, you can use "file://" schema for your URI
99
+ or use `from_file` method with a local file name (without schema):
100
+
101
+ $ m.from_file("../data.ttl", :format => "turtle")
102
+
103
+ Most frequently used parsing methods are aliased to save you some typing:
104
+ `from_rdfxml`, `from_ntriples`, `from_turtle`, `from_uri/from_file`.
105
+
106
+ Finally, you can filter the parsed input to prevent certain statements from getting into your model:
107
+
108
+ $ m.from_turtle(data) do |statement|
109
+ statement.object.value == "good"
110
+ end
111
+
112
+ If the block returns `false`, the statement will not be added to the model.
113
+ The above example will add only statements having "literal" objects with a value of "good".
114
+
115
+
116
+ ## Serializing Model
117
+
118
+ Naturally, you can convert your model into a portable syntax:
119
+
120
+ $ m.to(:format => "rdfxml") # => RDF/XML output
121
+
122
+ There are aliases as well: `to_rdfxml`, `to_dot`, etc.
123
+
124
+ You can also dump the output directly into a local file:
125
+
126
+ $ m.to_file("data.nt", :format => "ntriples")
127
+
128
+
129
+ ## Transactions
130
+
131
+ It is possible to wrap all changes you perform on a model in a transaction,
132
+ if transactions are supported by the backend storage. If they are not supported,
133
+ all changes will be instantaneous.
134
+
135
+ $ m.transaction { m.statements.delete_all }
136
+
137
+ There are also dedicated methods to start, commit and rollback a transaction,
138
+ should you not be able to explicitly wrap your changes in a block:
139
+
140
+ $ m.transaction_start
141
+ $ m.delete_all
142
+ $ if lucky?
143
+ m.transaction_commit
144
+ else
145
+ m.transaction_rollback
146
+ end
147
+
148
+ All the above methods have their "banged" counterparts (`transaction_start!`,
149
+ `transaction_commit!` and `transaction_rollback!`) that would raise `RedlandError`
150
+ in case of an error.
151
+
152
+
153
+ # Exceptions
154
+
155
+ If anything unexpected happens, Redlander raises `RedlandError`.
156
+
157
+
158
+ # Known Issues
159
+
160
+ > Fixed in `redland-1.0.15`: [0000478](http://bugs.librdf.org/mantis/view.php?id=478)
161
+
162
+ All Enumerator-based aggregation methods of `Redlander::ModelProxy`
163
+ return invalid results - they are all copies of the last found statement.
164
+ For example,
165
+
166
+ $ model.statements.to_a
167
+
168
+ returns statement copies, while
169
+
170
+ $ model.statements.each { ... }
171
+
172
+ yields proper results in the block.
173
+ Update your `redland` library to 1.0.15 or newer to fix this.
174
+
175
+
176
+ # Authors and Contributors
177
+
178
+ [Slava Kravchenko](https://github.com/cordawyn)
179
+
180
+
181
+ # Thanks
182
+
183
+ Thanks goes to Dave Beckett, the creator of Redland!
@@ -5,8 +5,9 @@ module Redland
5
5
  if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
6
6
  require 'ffi'
7
7
  extend FFI::Library
8
- ffi_lib "rdf.so.0"
8
+ ffi_lib "rdf"
9
9
  else
10
+ # TODO: This might be outdated already, check with Rubinius
10
11
  extend FFI::Library
11
12
  ffi_lib "librdf.so.0"
12
13
  end
@@ -131,8 +131,9 @@ module Redlander
131
131
  def transaction
132
132
  if block_given?
133
133
  transaction_start
134
- yield
134
+ result = yield
135
135
  transaction_commit
136
+ result
136
137
  end
137
138
  rescue
138
139
  transaction_rollback
@@ -1,4 +1,4 @@
1
1
  module Redlander
2
2
  # Redlander version number
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
@@ -17,12 +17,12 @@ HERE
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- # gem.add_dependency("librdf0", "~> 1.0.14")
20
+ # gem.add_dependency("librdf0", "~> 1.0.15")
21
21
  gem.add_dependency("xml_schema", "~> 0.1.3")
22
- gem.add_dependency("ffi", "~> 1.1")
22
+ gem.add_dependency("ffi", "~> 1.3")
23
23
  gem.add_development_dependency("rspec", "~> 2")
24
24
 
25
25
  gem.license = "The MIT License (MIT)"
26
- gem.extra_rdoc_files = ['README.rdoc', 'ChangeLog']
26
+ gem.extra_rdoc_files = ['README.md', 'ChangeLog']
27
27
  gem.has_rdoc = false
28
28
  end
@@ -171,6 +171,39 @@ describe Model do
171
171
 
172
172
  it { should be_nil }
173
173
  end
174
+
175
+ context "for all matching statements" do
176
+ subject { model.statements.find(:all, @conditions) }
177
+
178
+ before do
179
+ @another_statement =
180
+ model.statements.create(statement_attributes.merge(:subject => URI.parse('http://example.com/concepts#another_subject')))
181
+ end
182
+
183
+ context "with empty conditions" do
184
+ before { @conditions = {} }
185
+
186
+ it { should eql [@statement, @another_statement] }
187
+ end
188
+
189
+ context "with one matching statement" do
190
+ before { @conditions = {:subject => @statement.subject} }
191
+
192
+ it { should eql [@statement] }
193
+ end
194
+
195
+ context "with all matching statements" do
196
+ before { @conditions = {:object => @statement.object} }
197
+
198
+ it { should eql [@statement, @another_statement] }
199
+ end
200
+
201
+ context "with no matching statements" do
202
+ before { @conditions = {:object => "no match"} }
203
+
204
+ it { should be_empty }
205
+ end
206
+ end
174
207
  end
175
208
 
176
209
  context "when checked for existance" do
@@ -373,6 +406,10 @@ describe Model do
373
406
  :librdf_model_transaction_rollback => 0)
374
407
  end
375
408
 
409
+ it "should return the output of the block evaluation" do
410
+ subject.transaction { 3+7 }.should eql(10)
411
+ end
412
+
376
413
  context "when start fails" do
377
414
  before { Redland.stub(:librdf_model_transaction_start => -1) }
378
415
 
metadata CHANGED
@@ -1,49 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
5
4
  prerelease:
5
+ version: 0.5.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Slava Kravchenko
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-20 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: xml_schema
16
- requirement: &20744320 !ruby/object:Gem::Requirement
17
- none: false
15
+ type: :runtime
16
+ version_requirements: !ruby/object:Gem::Requirement
18
17
  requirements:
19
18
  - - ~>
20
19
  - !ruby/object:Gem::Version
21
20
  version: 0.1.3
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *20744320
25
- - !ruby/object:Gem::Dependency
26
- name: ffi
27
- requirement: &21431040 !ruby/object:Gem::Requirement
28
21
  none: false
22
+ name: xml_schema
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
29
25
  requirements:
30
26
  - - ~>
31
27
  - !ruby/object:Gem::Version
32
- version: '1.1'
28
+ version: 0.1.3
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
33
31
  type: :runtime
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: '1.3'
37
+ none: false
38
+ name: ffi
34
39
  prerelease: false
35
- version_requirements: *21431040
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &21430560 !ruby/object:Gem::Requirement
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '1.3'
39
45
  none: false
46
+ - !ruby/object:Gem::Dependency
47
+ type: :development
48
+ version_requirements: !ruby/object:Gem::Requirement
40
49
  requirements:
41
50
  - - ~>
42
51
  - !ruby/object:Gem::Version
43
52
  version: '2'
44
- type: :development
53
+ none: false
54
+ name: rspec
45
55
  prerelease: false
46
- version_requirements: *21430560
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '2'
61
+ none: false
47
62
  description: ! 'Redlander is Ruby bindings to Redland library (see http://librdf.org)
48
63
  written in C, which is used to manipulate RDF graphs. This is an alternative implementation
49
64
  of Ruby bindings (as opposed to the official bindings), aiming to be more intuitive,
@@ -55,7 +70,7 @@ email:
55
70
  executables: []
56
71
  extensions: []
57
72
  extra_rdoc_files:
58
- - README.rdoc
73
+ - README.md
59
74
  - ChangeLog
60
75
  files:
61
76
  - .gitignore
@@ -63,7 +78,7 @@ files:
63
78
  - Gemfile
64
79
  - Gemfile.lock
65
80
  - LICENSE
66
- - README.rdoc
81
+ - README.md
67
82
  - Rakefile
68
83
  - lib/redland.rb
69
84
  - lib/redlander.rb
@@ -95,20 +110,26 @@ rdoc_options: []
95
110
  require_paths:
96
111
  - lib
97
112
  required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
113
  requirements:
100
114
  - - ! '>='
101
115
  - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ hash: 202030683622946567
102
119
  version: '0'
103
- required_rubygems_version: !ruby/object:Gem::Requirement
104
120
  none: false
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
122
  requirements:
106
123
  - - ! '>='
107
124
  - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ hash: 202030683622946567
108
128
  version: '0'
129
+ none: false
109
130
  requirements: []
110
131
  rubyforge_project:
111
- rubygems_version: 1.8.11
132
+ rubygems_version: 1.8.24
112
133
  signing_key:
113
134
  specification_version: 3
114
135
  summary: Advanced Ruby bindings for Redland runtime library (librdf).
@@ -1,151 +0,0 @@
1
- = Redlander
2
-
3
- Redlander is Ruby bindings to Redland library (see http://librdf.org) written in C, which is used to manipulate RDF graphs. This is an alternative implementation of Ruby bindings (as opposed to the official bindings), aiming to be more intuitive, lightweight, high-performing and as bug-free as possible.
4
-
5
- = Installing
6
-
7
- Installing Redlander is simple:
8
-
9
- $ gem install redlander
10
-
11
- Note, that you will have to install Redland runtime library (librdf) for Redlander to work.
12
-
13
- = Usage
14
-
15
- This README outlines most obvious use cases. For more details please refer to YARD documentation of Redlander.
16
-
17
- To start doing anything useful with Redlander, you need to initialize a model first:
18
-
19
- $ m = Redlander::Model.new
20
-
21
- This creates a model where all RDF statements are stored in the memory. Depending on the selected storage you may need to supply extra parameters like :user or :password. Look-up the options for Model.initialize for the list of available options.
22
- Naturally, you don't need to create a model if you just want to play around with independent statements, nodes and the like.
23
-
24
- == RDF Statements
25
-
26
- Now that you have created a model, you can access its RDF statements:
27
-
28
- $ m.statements
29
-
30
- Most of Redlander functionality is accessable via these statements. The API is almost identical to ActiveRecord:
31
-
32
- $ s = URI.parse('http://example.com/concepts#subject')
33
- $ p = URI.parse('http://example.com/concepts#label')
34
- $ o = "subject!"
35
- $ m.statements.create(:subject => s, :predicate => p, :object => o)
36
-
37
- $ m.statements.empty? # => false
38
-
39
- $ st = Redlander::Statement.new(:subject => s, :predicate => p, :object => "another label")
40
- $ m.statements.add(st)
41
-
42
- $ m.statements.size # => 2
43
-
44
- $ m.statements.each { |st| puts st }
45
-
46
- Finding statements:
47
-
48
- $ m.statements.find(:first, :object => "subject!")
49
- $ m.statements.all(:object => "another label")
50
- $ m.statements.each(:object => "subject!") { |statement|
51
- puts statement.subject
52
- }
53
-
54
- Note that "m.statements.each" is "lazy", while "m.statements.all" (and other finders) is not.
55
-
56
- You can access the subject, predicate or object of a statement:
57
-
58
- $ m.statements.first.subject # => (Redlander::Node)
59
-
60
- Please refer to Redlander::Node API doc for details.
61
-
62
- You can also use different query languages supported by librdf ("SPARQL 1.0" being a default):
63
-
64
- $ m.query("SELECT ?s ?p ?o WHERE {}") # => [{"s" => ..., "p" => ..., "o" => ...}, ...]
65
-
66
- "ASK" queries return true/false, "SELECT" queries return arrays of binding hashes,
67
- "CONSTRUCT" queries return an instance of a new memory-based model comprised from
68
- the statements constructed by the query.
69
- You can also supply a block to Model#query, which is ignored by ASK queries, but
70
- yields the statements constructed by CONSTRUCT queries and yields the binding
71
- hash for SELECT queries. Binding hash values are instances of Redlander::Node.
72
-
73
- For query options and available query languages refer to Model#query documentation.
74
-
75
-
76
- == Parsing Input
77
-
78
- You can fill your model with statements by parsing some external sources like plain or streamed data.
79
-
80
- $ data = File.read("data.xml")
81
- $ m.from(data, :format => "rdfxml")
82
-
83
- If the input is too large, you may prefer streaming it:
84
-
85
- $ source = URI("http://example.com/data.nt")
86
- $ m.from(source, :format => "ntriples")
87
-
88
- If you want to get the data from a local file, you can use "file://" schema for your URI
89
- or use "from_file" method with a local file name (without schema):
90
-
91
- $ m.from_file("../data.ttl", :format => "turtle")
92
-
93
- Most frequently used parsing methods are aliased to save you some typing:
94
- "from_rdfxml", "from_ntriples", "from_turtle", "from_uri/from_file".
95
-
96
- Finally, you can filter the parsed input to prevent certain statements from getting into your model:
97
-
98
- $ m.from_turtle(data) do |statement|
99
- statement.object.value == "good"
100
- end
101
-
102
- If the block returns "false", the statement will not be added to the model.
103
- The above example will add only statements having "literal" objects with a value of "good".
104
-
105
- == Serializing Model
106
-
107
- Naturally, you can convert your model into a portable syntax:
108
-
109
- $ m.to(:format => "rdfxml") # => RDF/XML output
110
-
111
- There are aliases as well: "to_rdfxml", "to_dot", etc.
112
-
113
- You can also dump the output directly into a local file:
114
-
115
- $ m.to_file("data.nt", :format => "ntriples")
116
-
117
- == Transactions
118
-
119
- It is possible to wrap all changes you perform on a model in a transaction,
120
- if transactions are supported by the backend storage. If they are not supported,
121
- all changes will be instantaneous.
122
-
123
- $ m.transaction { m.statements.delete_all }
124
-
125
- There are also dedicated methods to start, commit and rollback a transaction,
126
- should you not be able to explicitly wrap your changes in a block:
127
-
128
- $ m.transaction_start
129
- $ m.delete_all
130
- $ if lucky?
131
- m.transaction_commit
132
- else
133
- m.transaction_rollback
134
- end
135
-
136
- All the above methods have their "banged" counterparts ("transaction_start!",
137
- "transaction_commit!" and "transaction_rollback!") that would raise RedlandError
138
- in case of an error.
139
-
140
-
141
- = Exceptions
142
-
143
- If anything unexpected happens, Redlander raises RedlandError.
144
-
145
- = Authors and Contributors
146
-
147
- Slava Kravchenko <https://github.com/cordawyn>
148
-
149
- = Thanks
150
-
151
- Thanks goes to Dave Beckett, the creator of Redland!