Module: RDF::Repository::Implementation
- Defined in:
- lib/rdf/repository.rb
Overview
Constant Summary collapse
- DEFAULT_CONTEXT =
false
Class Method Summary collapse
Instance Method Summary collapse
- #count ⇒ Object
- #durable? ⇒ Boolean
- #each_context(&block) ⇒ Object
- #each_statement(&block) ⇒ Object (also: #each)
- #empty? ⇒ Boolean
- #has_context?(value) ⇒ Boolean
- #has_statement?(statement) ⇒ Boolean
- #supports?(feature) ⇒ Boolean
Class Method Details
.extend_object(obj) ⇒ Object
217 218 219 220 |
# File 'lib/rdf/repository.rb', line 217 def self.extend_object(obj) obj.instance_variable_set(:@data, obj..delete(:data) || {}) super end |
Instance Method Details
#count ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/rdf/repository.rb', line 250 def count count = 0 @data.each do |c, ss| ss.each do |s, ps| ps.each do |p, os| count += os.size end end end count end |
#durable? ⇒ Boolean
236 237 238 |
# File 'lib/rdf/repository.rb', line 236 def durable? false end |
#each_context(&block) ⇒ Object
307 308 309 310 311 312 313 314 |
# File 'lib/rdf/repository.rb', line 307 def each_context(&block) if block_given? contexts = @data.keys contexts.delete(DEFAULT_CONTEXT) contexts.each(&block) end enum_context end |
#each_statement(&block) ⇒ Object Also known as: each
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/rdf/repository.rb', line 277 def each_statement(&block) if block_given? # Note that to iterate in a more consistent fashion despite # possible concurrent mutations to `@data`, we use `#dup` to make # shallow copies of the nested hashes before beginning the # iteration over their keys and values. @data.dup.each do |c, ss| ss.dup.each do |s, ps| ps.dup.each do |p, os| os.dup.each do |o| block.call(RDF::Statement.new(s, p, o, :context => c.equal?(DEFAULT_CONTEXT) ? nil : c)) end end end end end enum_statement end |
#empty? ⇒ Boolean
243 244 245 |
# File 'lib/rdf/repository.rb', line 243 def empty? @data.empty? end |
#has_context?(value) ⇒ Boolean
300 301 302 |
# File 'lib/rdf/repository.rb', line 300 def has_context?(value) @data.keys.include?(value) end |
#has_statement?(statement) ⇒ Boolean
265 266 267 268 269 270 271 272 |
# File 'lib/rdf/repository.rb', line 265 def has_statement?(statement) s, p, o, c = statement.to_quad c ||= DEFAULT_CONTEXT @data.has_key?(c) && @data[c].has_key?(s) && @data[c][s].has_key?(p) && @data[c][s][p].include?(o) end |
#supports?(feature) ⇒ Boolean
225 226 227 228 229 230 231 |
# File 'lib/rdf/repository.rb', line 225 def supports?(feature) case feature.to_sym when :context then true # statement contexts / named graphs when :inference then false # forward-chaining inference else false end end |