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 collapse

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

Instance Method Summary collapse

Methods included from Queryable

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

Methods included from Durable

#nondurable?

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Enumerable

#canonicalize, #canonicalize!, #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?, #graph_names, #invalid?, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #statement?, #statements, #subject?, #subjects, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!

Methods included from Countable

#count, #empty?, #enum_for

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

#durable?Boolean

Returns:

  • (Boolean)

See Also:



58
59
60
# File 'lib/rdf/model/dataset.rb', line 58

def durable?
  false
end

#eachObject

See Also:

  • Enumerable#each


65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rdf/model/dataset.rb', line 65

def each
  @statements.each do |st| 
    if st.graph_name.equal?(DEFAULT_GRAPH)
      st = st.dup
      st.graph_name = nil
    end

    yield st
  end
  self
end

#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__, count.to_s)
end

#inspect!void

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

#supports?(feature) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



106
107
108
109
# File 'lib/rdf/model/dataset.rb', line 106

def supports?(feature)
  return true if %i(graph_name quoted_triples).include?(feature)
  super
end