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

#initialize(identifier = nil, configuration = {}) ⇒ AbstractStore

Create a new AbstractStore Store, should be subclassed @param configuration Specific to type of storage

Parameters:

  • identifier (Resource) (defaults to: nil)


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

#identifierObject (readonly)

Returns the value of attribute identifier



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

def identifier
  @identifier
end

#nsbindingObject (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_bindingObject (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

Parameters:

  • triple (Triple)
  • context (Graph) (defaults to: nil)

    (nil)

  • quoted (Boolean) (defaults to: false)

    (false) A quoted triple, for Formulae

Returns:

Raises:



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.

Parameters:

  • namespace (Nameespace)

    the namespace to bind

Returns:

  • (Namespace)

    The newly bound or pre-existing namespace.



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

Parameters:

  • context (Graph) (defaults to: nil)

    (nil)

Returns:



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

#commitObject



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

Parameters:

  • triple (Triple)
  • context (Graph) (defaults to: nil)

    (nil) ignored

Returns:

  • (Boolean)

Raises:



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?

Returns:

  • (false)


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

Returns:



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?

Returns:

  • (false)


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

def formula_aware?; false; end

#inspectObject

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

Parameters:

  • item (Integer)

    Index into the serialized store

  • context (Graph) (defaults to: nil)

Returns:



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

Parameters:

Returns:



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

Parameters:

  • context (Graph) (defaults to: nil)

    (nil)

Returns:



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

Parameters:

  • context (Graph) (defaults to: nil)

    (nil)

Returns:



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

Parameters:

Returns:



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

Parameters:

  • triple (Triple)
  • context (Graph) (defaults to: nil)

    (nil)

Raises:



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

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

#rollbackObject



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

def rollback; end

#size(context = nil) ⇒ Integer

Number of Triples in the graph

Parameters:

  • context (Graph) (defaults to: nil)

    (nil)

Returns:

  • (Integer)


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

Parameters:

  • context (Graph) (defaults to: nil)

    (nil)

Returns:



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?

Returns:

  • (false)


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

Parameters:

  • triple (Triple)
  • context (Graph) (defaults to: nil)

    (nil)

Yields:

  • (triple, context)

Yield Parameters:

Returns:

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