Class: RdfContext::AbstractStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf_context/store/abstract_store.rb

Overview

Abstract storage module, superclass of other storage classes

Direct Known Subclasses

AbstractSQLStore, ListStore, MemoryStore

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AbstractStore) initialize(identifier = nil, configuration = {})

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

- (Object) identifier (readonly)

Returns the value of attribute identifier



4
5
6
# File 'lib/rdf_context/store/abstract_store.rb', line 4

def identifier
  @identifier
end

- (Object) nsbinding (readonly)

Returns the value of attribute nsbinding



4
5
6
# File 'lib/rdf_context/store/abstract_store.rb', line 4

def nsbinding
  @nsbinding
end

- (Object) uri_binding (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

- (Triple) add(triple, context = nil, quoted = false)

Add triple to store

Raises:



50
# File 'lib/rdf_context/store/abstract_store.rb', line 50

def add(triple, context = nil, quoted = false); raise StoreException, "not implemented"; end

- (Namespace) bind(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

- (Array<BNode>) bnodes(context = nil)

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

- (Object) close(commit_pending_transactions = false)



79
# File 'lib/rdf_context/store/abstract_store.rb', line 79

def close(commit_pending_transactions = false); end

- (Object) commit



80
# File 'lib/rdf_context/store/abstract_store.rb', line 80

def commit; end

- (Boolean) contains?(triple, context = nil)

Check to see if this store contains the specified triple

Raises:



64
# File 'lib/rdf_context/store/abstract_store.rb', line 64

def contains?(triple, context = nil); raise StoreException, "not implemented"; end

- (false) context_aware?

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

- (Array<Graph>) contexts(triple = nil)

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

- (Object) destroy(configuration = {})



77
# File 'lib/rdf_context/store/abstract_store.rb', line 77

def destroy(configuration = {}); end

- (false) formula_aware?

Is store Formulae Aware, capable of storing variables?



24
# File 'lib/rdf_context/store/abstract_store.rb', line 24

def formula_aware?; false; end

- (Object) inspect

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

- (Array<Triple>) item(item, context = nil)

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) namespace(prefix)

Namespace for prefix



101
102
103
# File 'lib/rdf_context/store/abstract_store.rb', line 101

def namespace(prefix)
  @nsbinding[prefix.to_s]
end

- (Array<Resource>) objects(context = nil)

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

- (Object) open(configuration = {})



78
# File 'lib/rdf_context/store/abstract_store.rb', line 78

def open(configuration = {}); end

- (Array<Resource>) predicates(context = nil)

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

- (String) prefix(namespace)

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

Raises:



57
# File 'lib/rdf_context/store/abstract_store.rb', line 57

def remove(triple, context = nil); raise StoreException, "not implemented"; end

- (Object) rollback



81
# File 'lib/rdf_context/store/abstract_store.rb', line 81

def rollback; end

- (Integer) size(context = nil)

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

- (Array<Resource>) subjects(context = nil)

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

- (false) transaction_aware?

Is store Transaction Aware, capable of rollback?



28
# File 'lib/rdf_context/store/abstract_store.rb', line 28

def transaction_aware?; false; end

- (Array<Triplle>) triples(triple, context = nil) {|triple, context| ... }

A generator over all matching triples

Yields:

  • (triple, context)

Yield Parameters:

Raises:



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