Class: RDF::Oxigraph::Repository

Inherits:
Repository
  • Object
show all
Defined in:
lib/rdf/oxigraph/repository.rb

Overview

An RDF.rb-compatible Repository backed by the native oxigraph store.

Implements the storage backend protocol (insert/delete/each/count) over the tagged-tuple bridge; the RDF::Enumerable/Queryable/Mutable mixins build the rest of the RDF.rb surface on top.

Instance Method Summary collapse

Constructor Details

#initialize(**options, &block) ⇒ Repository

Returns a new instance of Repository.



9
10
11
12
# File 'lib/rdf/oxigraph/repository.rb', line 9

def initialize(**options, &block)
  @store = RDF::Oxigraph::Store.new
  super(**options, &block)
end

Instance Method Details

#countObject



26
27
28
# File 'lib/rdf/oxigraph/repository.rb', line 26

def count
  @store.size
end

#delete_statement(statement) ⇒ Object



48
49
50
51
# File 'lib/rdf/oxigraph/repository.rb', line 48

def delete_statement(statement)
  s, p, o, g = Conversion.serialize_statement(statement)
  @store.delete(s, p, o, g)
end

#dump(format, **options) ⇒ Object

Fast native serialization of the whole repository for supported formats; falls back to RDF::Enumerable#dump otherwise.



66
67
68
69
70
# File 'lib/rdf/oxigraph/repository.rb', line 66

def dump(format, **options)
  native = format.is_a?(Symbol) && RDF::Oxigraph::FORMATS[format]
  return super if native == false || native.nil?
  @store.dump(native)
end

#durable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rdf/oxigraph/repository.rb', line 22

def durable?
  false # in-memory; persistent (RocksDB) variant comes later
end

#each_statement(&block) ⇒ Object Also known as: each



34
35
36
37
38
39
# File 'lib/rdf/oxigraph/repository.rb', line 34

def each_statement(&block)
  return enum_for(:each_statement) unless block_given?
  @store.each_quad.each do |quad|
    block.call(Conversion.deserialize_statement(quad))
  end
end

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rdf/oxigraph/repository.rb', line 30

def empty?
  count.zero?
end

#insert_statement(statement) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
# File 'lib/rdf/oxigraph/repository.rb', line 42

def insert_statement(statement)
  raise ArgumentError, "incomplete statement: #{statement.inspect}" if statement.incomplete?
  s, p, o, g = Conversion.serialize_statement(statement)
  @store.insert(s, p, o, g)
end

#load(filename, **options) ⇒ Object

Fast bulk load via oxigraph's native parser (skips per-statement Ruby inserts). Falls back to RDF::Mutable#load for unsupported formats or when a graph_name override is requested.



56
57
58
59
60
61
62
# File 'lib/rdf/oxigraph/repository.rb', line 56

def load(filename, **options)
  format = options[:format] || RDF::Format.for(file_name: filename.to_s)&.to_sym
  native = RDF::Oxigraph::FORMATS[format]
  return super if native.nil? || options[:graph_name]
  @store.load(File.read(filename), native)
  self
end

#shacl_validate(shapes, shapes_format: :turtle) ⇒ Object

Validate this repository's data against SHACL shapes (a serialized-RDF string). Returns an RDF::Oxigraph::SHACL::Report.



87
88
89
90
91
92
93
94
# File 'lib/rdf/oxigraph/repository.rb', line 87

def shacl_validate(shapes, shapes_format: :turtle)
  RDF::Oxigraph::SHACL.validate(
    data: @store.dump("ntriples"),
    data_format: :ntriples,
    shapes: shapes,
    shapes_format: shapes_format
  )
end

#sparql(query_string) ⇒ Object

Execute a SPARQL query string via oxigraph's native engine. Returns RDF.rb-native results: RDF::Query::Solutions (SELECT), RDF::Graph (CONSTRUCT/DESCRIBE), or true/false (ASK).



75
76
77
# File 'lib/rdf/oxigraph/repository.rb', line 75

def sparql(query_string)
  RDF::Oxigraph::SPARQL.results(@store.query(query_string))
end

#sparql_update(update_string) ⇒ Object

Execute a SPARQL 1.1 Update string against this repository.



80
81
82
83
# File 'lib/rdf/oxigraph/repository.rb', line 80

def sparql_update(update_string)
  @store.update(update_string)
  self
end

#supports?(feature) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/rdf/oxigraph/repository.rb', line 14

def supports?(feature)
  case feature.to_sym
  when :graph_name then true   # quad store
  when :literal_equality then true
  else false
  end
end