Class: ActiveTriples::ExtendedBoundedDescription

Inherits:
Object
  • Object
show all
Includes:
RDF::Enumerable, RDF::Queryable
Defined in:
lib/active_triples/util/extended_bounded_description.rb

Overview

Note:

this implementation requires that the ‘source_graph` remain unchanged while iterating over the description. The safest way to achive this is to use an immutable `RDF::Dataset` (e.g. a `Repository#snapshot`).

Bounds the scope of an ‘RDF::Queryable` to a subgraph defined from a source graph, a starting node, and a list of “ancestors” terms, by the following process:

Include in the subgraph:

1. All statements in the source graph where the subject of the statement 
   is the starting node.
2. Add the starting node to the ancestors list.
2. Recursively, for all statements already in the subgraph, include in 
   the subgraph the Extended Bounded Description for each object node, 
   unless the object is in the ancestors list.

The list of “ancestors” is empty by default.

This subgraph this process yields can be considered as a description of the starting node.

Compare to Concise Bounded Description (www.w3.org/Submission/CBD/), the common subgraph scope used for SPARQL DESCRIBE queries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_graph, starting_node, ancestors = []) ⇒ ExtendedBoundedDescription

By analogy to Concise Bounded Description.

Parameters:

  • source_graph (RDF::Queryable)
  • starting_node (RDF::Term)
  • ancestors (Array<RDF::Term>) (defaults to: [])

    default: []



46
47
48
49
50
# File 'lib/active_triples/util/extended_bounded_description.rb', line 46

def initialize(source_graph, starting_node, ancestors = [])
  @source_graph  = source_graph
  @starting_node = starting_node
  @ancestors     = ancestors
end

Instance Attribute Details

#ancestorsObject (readonly)



38
39
40
# File 'lib/active_triples/util/extended_bounded_description.rb', line 38

def ancestors
  @ancestors
end

#source_graphObject (readonly)

Returns RDF::Queryable.

Returns:

  • RDF::Queryable



38
# File 'lib/active_triples/util/extended_bounded_description.rb', line 38

attr_reader  :ancestors, :source_graph, :starting_node

#starting_nodeObject (readonly)

Returns the value of attribute starting_node.



38
# File 'lib/active_triples/util/extended_bounded_description.rb', line 38

attr_reader  :ancestors, :source_graph, :starting_node

Instance Method Details

#each_statementObject Also known as: each

See Also:

  • RDF::Enumerable#each


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/active_triples/util/extended_bounded_description.rb', line 54

def each_statement
  ancestors = @ancestors.dup

  if block_given?
    statements = source_graph.query(subject: starting_node).each
    statements.each_statement { |st| yield st }
    
    ancestors << starting_node
    
    statements.each_object do |object|
      next if object.literal?  || ancestors.include?(object)
      ExtendedBoundedDescription
        .new(source_graph, object, ancestors).each do |statement|
        yield statement
      end
    end
  end
  enum_statement
end