Class: RdfContext::AbstractStore
- Inherits:
-
Object
- Object
- RdfContext::AbstractStore
- Defined in:
- lib/rdf_context/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.
-
#uri_binding ⇒ Object
readonly
Returns the value of attribute uri_binding.
Instance Method Summary collapse
-
#add(triple, context = nil, quoted = false) ⇒ Triple
Add triple to store.
-
#bind(namespace) ⇒ Namespace
Bind a namespace to the store.
-
#bnodes(context = nil) ⇒ Array<BNode>
Get all BNodes with usage count used within graph.
- #close(commit_pending_transactions = false) ⇒ Object
- #commit ⇒ Object
-
#contains?(triple, context = nil) ⇒ Boolean
Check to see if this store contains the specified triple.
-
#context_aware? ⇒ false
Is store Context Aware, capable of being used for named graphs?.
-
#contexts(triple = nil) ⇒ Array<Graph>
Return contexts in the store (optionally matching triple), or empty if not context aware.
- #destroy(configuration = {}) ⇒ Object
-
#formula_aware? ⇒ false
Is store Formulae Aware, capable of storing variables?.
-
#initialize(identifier = nil, configuration = {}) ⇒ AbstractStore
constructor
Create a new AbstractStore Store, should be subclassed @param configuration Specific to type of storage.
-
#inspect ⇒ Object
Default (sub-optimal) implemenations of interfaces.
-
#item(item, context = nil) ⇒ Array<Triple>
Return an indexed element from the graph.
-
#namespace(prefix) ⇒ Namespace
Namespace for prefix.
-
#objects(context = nil) ⇒ Array<Resource>
List of distinct objects in graph.
- #open(configuration = {}) ⇒ Object
-
#predicates(context = nil) ⇒ Array<Resource>
List of distinct predicates in graph.
-
#prefix(namespace) ⇒ String
Prefix for namespace.
-
#remove(triple, context = nil)
Remove a triple from the store.
- #rollback ⇒ Object
-
#size(context = nil) ⇒ Integer
Number of Triples in the graph.
-
#subjects(context = nil) ⇒ Array<Resource>
List of distinct subjects in graph.
-
#transaction_aware? ⇒ false
Is store Transaction Aware, capable of rollback?.
-
#triples(triple, context = nil) {|triple, context| ... } ⇒ Array<Triplle>
A generator over all matching triples.
Constructor Details
#initialize(identifier = nil, configuration = {}) ⇒ AbstractStore
Create a new AbstractStore Store, should be subclassed @param configuration Specific to type of storage
10 11 12 13 14 15 16 |
# File 'lib/rdf_context/store/abstract_store.rb', line 10 def initialize(identifier = nil, configuration = {}) @nsbinding = {} # Reverse namespace binding @uri_binding = {} @identifier = identifier || BNode.new end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/rdf_context/store/abstract_store.rb', line 4 def identifier @identifier end |
#nsbinding ⇒ Object (readonly)
Returns the value of attribute nsbinding.
4 5 6 |
# File 'lib/rdf_context/store/abstract_store.rb', line 4 def nsbinding @nsbinding end |
#uri_binding ⇒ Object (readonly)
Returns the value of attribute uri_binding.
4 5 6 |
# File 'lib/rdf_context/store/abstract_store.rb', line 4 def uri_binding @uri_binding end |
Instance Method Details
#add(triple, context = nil, quoted = false) ⇒ Triple
Add triple to store
50 |
# File 'lib/rdf_context/store/abstract_store.rb', line 50 def add(triple, context = nil, quoted = false); raise StoreException, "not implemented"; end |
#bind(namespace) ⇒ Namespace
Bind a namespace to the store.
88 89 90 91 92 93 94 95 96 |
# File 'lib/rdf_context/store/abstract_store.rb', line 88 def bind(namespace) # Over-write an empty prefix uri = namespace.uri.to_s @uri_binding.delete(uri) @nsbinding.delete_if {|prefix, ns| namespace.prefix == prefix} @uri_binding[uri] = namespace @nsbinding[namespace.prefix.to_s] = namespace end |
#bnodes(context = nil) ⇒ Array<BNode>
Get all BNodes with usage count used within graph
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rdf_context/store/abstract_store.rb', line 115 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.predicate.is_a?(BNode) bn[t.predicate] ||= 0 bn[t.predicate] += 1 end if t.object.is_a?(BNode) bn[t.object] ||= 0 bn[t.object] += 1 end end bn end |
#close(commit_pending_transactions = false) ⇒ Object
79 |
# File 'lib/rdf_context/store/abstract_store.rb', line 79 def close(commit_pending_transactions = false); end |
#commit ⇒ Object
80 |
# File 'lib/rdf_context/store/abstract_store.rb', line 80 def commit; end |
#contains?(triple, context = nil) ⇒ Boolean
Check to see if this store contains the specified triple
64 |
# File 'lib/rdf_context/store/abstract_store.rb', line 64 def contains?(triple, context = nil); raise StoreException, "not implemented"; end |
#context_aware? ⇒ false
Is store Context Aware, capable of being used for named graphs?
20 |
# File 'lib/rdf_context/store/abstract_store.rb', line 20 def context_aware?; false; end |
#contexts(triple = nil) ⇒ Array<Graph>
Return contexts in the store (optionally matching triple), or empty if not context aware
68 69 70 |
# File 'lib/rdf_context/store/abstract_store.rb', line 68 def contexts(triple = nil) return [] end |
#destroy(configuration = {}) ⇒ Object
77 |
# File 'lib/rdf_context/store/abstract_store.rb', line 77 def destroy(configuration = {}); end |
#formula_aware? ⇒ false
Is store Formulae Aware, capable of storing variables?
24 |
# File 'lib/rdf_context/store/abstract_store.rb', line 24 def formula_aware?; false; end |
#inspect ⇒ Object
Default (sub-optimal) implemenations of interfaces
73 74 75 |
# File 'lib/rdf_context/store/abstract_store.rb', line 73 def inspect "#{self.class}[identifier=#{identifier.inspect}]" end |
#item(item, context = nil) ⇒ Array<Triple>
Return an indexed element from the graph
159 |
# File 'lib/rdf_context/store/abstract_store.rb', line 159 def item(item, context = nil) triples(Triple.new(nil, nil, nil), context)[item]; end |
#namespace(prefix) ⇒ Namespace
Namespace for prefix
101 102 103 |
# File 'lib/rdf_context/store/abstract_store.rb', line 101 def namespace(prefix) @nsbinding[prefix.to_s] end |
#objects(context = nil) ⇒ Array<Resource>
List of distinct objects in graph
153 |
# File 'lib/rdf_context/store/abstract_store.rb', line 153 def objects(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.object}.uniq; end |
#open(configuration = {}) ⇒ Object
78 |
# File 'lib/rdf_context/store/abstract_store.rb', line 78 def open(configuration = {}); end |
#predicates(context = nil) ⇒ Array<Resource>
List of distinct predicates in graph
148 |
# File 'lib/rdf_context/store/abstract_store.rb', line 148 def predicates(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.predicate}.uniq; end |
#prefix(namespace) ⇒ String
Prefix for namespace
108 109 110 |
# File 'lib/rdf_context/store/abstract_store.rb', line 108 def prefix(namespace) namespace.is_a?(Namespace) ? @uri_binding[namespace.uri.to_s].prefix : @uri_binding[namespace].prefix end |
#remove(triple, context = nil)
This method returns an undefined value.
Remove a triple from the store
57 |
# File 'lib/rdf_context/store/abstract_store.rb', line 57 def remove(triple, context = nil); raise StoreException, "not implemented"; end |
#rollback ⇒ Object
81 |
# File 'lib/rdf_context/store/abstract_store.rb', line 81 def rollback; end |
#size(context = nil) ⇒ Integer
Number of Triples in the graph
138 |
# File 'lib/rdf_context/store/abstract_store.rb', line 138 def size(context = nil); triples(Triple.new(nil, nil, nil), context).size; end |
#subjects(context = nil) ⇒ Array<Resource>
List of distinct subjects in graph
143 |
# File 'lib/rdf_context/store/abstract_store.rb', line 143 def subjects(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.subject}.uniq; end |
#transaction_aware? ⇒ false
Is store Transaction Aware, capable of rollback?
28 |
# File 'lib/rdf_context/store/abstract_store.rb', line 28 def transaction_aware?; false; end |
#triples(triple, context = nil) {|triple, context| ... } ⇒ Array<Triplle>
A generator over all matching triples
40 41 42 |
# File 'lib/rdf_context/store/abstract_store.rb', line 40 def triples(triple, context = nil) # :yields: triple, context raise StoreException, "not implemented" end |