Class: Reddy::MemoryStore

Inherits:
AbstractStore show all
Defined in:
lib/reddy/store/memory_store.rb

Overview

An integer-key-optimized-context-aware-in-memory store.

Uses nested dictionaries to store triples and context. Each triple is stored in six such indices as follows cspo[s][o] = 1 and cpos[p][s] = 1 and cosp[o][p] = 1 as well as spo[p] = [c] and pos[o] = [c] and pos[s] = [c]

Context information is used to track the ‘source’ of the triple data for merging, unmerging, remerging purposes. context aware store stores consume more memory size than non context stores.

Querying or removing triples using the store identifier (or nil) as context operate across all contexts within the store; otherwise, operations are specifiec to the specified context.

Based on Python RdfLib IOMemory

Instance Attribute Summary collapse

Attributes inherited from AbstractStore

#identifier, #nsbinding

Instance Method Summary collapse

Methods inherited from AbstractStore

#bind, #bnodes, context_aware?, formula_aware?, #inspect, #item, #namespace, #objects, #predicates, #prefix, #size, #subjects

Constructor Details

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

Returns a new instance of MemoryStore.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/reddy/store/memory_store.rb', line 27

def initialize(identifier = nil, configuration = {})
  super
  # indexed by [context][subject][predicate][object] = 1
  @cspo = {}
  # indexed by [context][predicate][object][subject] = 1
  @cpos = {}
  # indexed by [context][object][subject][predicate] = 1
  @cosp = {}
  # indexed by [subject][predicate][object] = [context]
  @spo = {}
  # indexed by [predicate][object][subject] = [context]
  @pos = {}
  # indexed by [object][subject][predicate] = [context]
  @osp = {}
  # indexes integer keys to identifiers
  @forward = {}
  # reverse index of forward
  @reverse = {}
end

Instance Attribute Details

#default_contextObject

Returns the value of attribute default_context.



19
20
21
# File 'lib/reddy/store/memory_store.rb', line 19

def default_context
  @default_context
end

Instance Method Details

#context_aware?Boolean

Supports contexts

Returns:

  • (Boolean)


22
# File 'lib/reddy/store/memory_store.rb', line 22

def context_aware?; true; end

#formula_aware?Boolean

Supports formulae

Returns:

  • (Boolean)


25
# File 'lib/reddy/store/memory_store.rb', line 25

def formula_aware?; true; end