Class: RDF::Dataset

Inherits:
Object
  • Object
show all
Includes:
Durable, Enumerable, Queryable
Defined in:
lib/rdf/model/dataset.rb

Overview

An RDF Dataset

Datasets are immutable by default. Repository provides an interface for mutable Datasets.

A Dataset functions as an a set of named RDF graphs with a default graph. It implements Enumerable and Queryable over the whole set; if no specific graph name is queried, enumerating and querying takes place over the intersection of all the graphs in the Dataset.

The default graph is named with a constant DEFAULT_GRAPH.

Examples:

initializing an RDF::Dataset with existing data

statements = [RDF::Statement.new(RDF::URI(:s), RDF::URI(:p), :o)]
dataset    = RDF::Dataset.new(statements: statements)
dataset.count # => 1

See Also:

Direct Known Subclasses

Repository

Constant Summary

DEFAULT_GRAPH =
false
ISOLATION_LEVELS =
[ :read_uncommitted,
:read_committed,
:repeatable_read,
:snapshot,
:serializable ].freeze

Instance Method Summary collapse

Methods included from Queryable

#first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query, #query_execute

Methods included from Durable

#nondurable?

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Enumerable

#dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #project_graph, #quads, #respond_to_missing?, #statements, #subjects, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!

Methods included from Countable

#count, #empty?

Constructor Details

#initialize(statements: [], **options) {|dataset| ... } ⇒ Dataset

Returns a new instance of Dataset

Parameters:

Yields:

  • (dataset)

    yields itself when a block is given

Yield Parameters:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rdf/model/dataset.rb', line 40

def initialize(statements: [], **options, &block)
  @statements = statements.map do |s| 
    s = s.dup
    s.graph_name ||= DEFAULT_GRAPH
    s.freeze
  end.freeze

  if block_given?
    case block.arity
      when 1 then yield self
      else instance_eval(&block)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

Instance Method Details

#inspectString

Returns a developer-friendly representation of this object.

Returns:

  • (String)


81
82
83
# File 'lib/rdf/model/dataset.rb', line 81

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, uri.to_s)
end

#inspect!

This method returns an undefined value.

Outputs a developer-friendly representation of this object to stderr.



90
91
92
93
# File 'lib/rdf/model/dataset.rb', line 90

def inspect!
  each_statement { |statement| statement.inspect! }
  nil
end

#isolation_levelSymbol

:snapshot, or :serializable.

Returns:

  • (Symbol)

    a representation of the isolation level for reads of this Dataset. One of :read_uncommitted, :read_committed, :repeatable_read,



99
100
101
# File 'lib/rdf/model/dataset.rb', line 99

def isolation_level
  :read_committed
end

#query_pattern(pattern, **options, &block) ⇒ Object (protected)

Implements basic query pattern matching over the Dataset, with handling for a default graph.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rdf/model/dataset.rb', line 116

def query_pattern(pattern, **options, &block)
  return super unless pattern.graph_name == DEFAULT_GRAPH

  if block_given?
    pattern = pattern.dup
    pattern.graph_name = nil

    each_statement do |statement|
      yield statement if (statement.graph_name == DEFAULT_GRAPH ||
                          statement.graph_name.nil?) && pattern === statement
    end
  else
    enum_for(:query_pattern, pattern, options)
  end
end