Class: Reddy::AbstractStore
- Inherits:
-
Object
- Object
- Reddy::AbstractStore
- Defined in:
- lib/reddy/store/abstract_store.rb
Overview
Abstract storage module, superclass of other storage classes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#nsbinding ⇒ Object
readonly
Returns the value of attribute nsbinding.
Class Method Summary collapse
Instance Method Summary collapse
-
#bind(namespace) ⇒ Object
Bind namespace to store, returns bound namespace.
-
#bnodes(context = nil) ⇒ Object
Get all BNodes with usage count used within graph.
-
#initialize(identifier = nil, configuration = {}) ⇒ AbstractStore
constructor
A new instance of AbstractStore.
-
#inspect ⇒ Object
Default (sub-optimal) implemenations of interfaces.
- #item(item, context = nil) ⇒ Object
-
#namespace(prefix) ⇒ Object
Namespace for prefix.
- #objects(context = nil) ⇒ Object
- #predicates(context = nil) ⇒ Object
-
#prefix(namespace) ⇒ Object
Prefix for namespace.
- #size(context = nil) ⇒ Object
- #subjects(context = nil) ⇒ Object
Constructor Details
#initialize(identifier = nil, configuration = {}) ⇒ AbstractStore
Returns a new instance of AbstractStore.
6 7 8 9 10 11 12 |
# File 'lib/reddy/store/abstract_store.rb', line 6 def initialize(identifier = nil, configuration = {}) @nsbinding = {} # Reverse namespace binding @prefix = {} @identifier = identifier || BNode.new end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/reddy/store/abstract_store.rb', line 4 def identifier @identifier end |
#nsbinding ⇒ Object (readonly)
Returns the value of attribute nsbinding.
4 5 6 |
# File 'lib/reddy/store/abstract_store.rb', line 4 def nsbinding @nsbinding end |
Class Method Details
.context_aware? ⇒ Boolean
61 |
# File 'lib/reddy/store/abstract_store.rb', line 61 def self.context_aware?; false; end |
.formula_aware? ⇒ Boolean
62 |
# File 'lib/reddy/store/abstract_store.rb', line 62 def self.formula_aware?; false; end |
Instance Method Details
#bind(namespace) ⇒ Object
Bind namespace to store, returns bound namespace
25 26 27 28 |
# File 'lib/reddy/store/abstract_store.rb', line 25 def bind(namespace) @prefix[namespace.uri.to_s] = namespace.prefix @nsbinding[namespace.prefix] ||= namespace end |
#bnodes(context = nil) ⇒ Object
Get all BNodes with usage count used within graph
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reddy/store/abstract_store.rb', line 41 def bnodes(context = nil) bn = {} triples(Triple.new(nil, nil, nil), context) do |t, ctx| if t.subject.is_a?(BNode) bn[t.subject] ||= 0 bn[t.subject] += 1 end if t.object.is_a?(BNode) bn[t.object] ||= 0 bn[t.object] += 1 end end bn end |
#inspect ⇒ Object
Default (sub-optimal) implemenations of interfaces
20 21 22 |
# File 'lib/reddy/store/abstract_store.rb', line 20 def inspect "#{self.class}[identifier=#{identifier}]" end |
#item(item, context = nil) ⇒ Object
60 |
# File 'lib/reddy/store/abstract_store.rb', line 60 def item(item, context = nil) triples(Triple.new(nil, nil, nil), context)[item]; end |
#namespace(prefix) ⇒ Object
Namespace for prefix
31 32 33 |
# File 'lib/reddy/store/abstract_store.rb', line 31 def namespace(prefix) @nsbinding[prefix] end |
#objects(context = nil) ⇒ Object
59 |
# File 'lib/reddy/store/abstract_store.rb', line 59 def objects(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.object}.uniq; end |
#predicates(context = nil) ⇒ Object
58 |
# File 'lib/reddy/store/abstract_store.rb', line 58 def predicates(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.predicate}.uniq; end |
#prefix(namespace) ⇒ Object
Prefix for namespace
36 37 38 |
# File 'lib/reddy/store/abstract_store.rb', line 36 def prefix(namespace) namespace.is_a?(Namespace) ? @prefix[namespace.uri.to_s] : @prefix[namespace] end |