Class: RDF::Normalize::Carroll2001

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Base, Utils
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-normalize-e113452533ce/lib/rdf/normalize/carroll2001.rb

Instance Attribute Summary

Attributes included from Base

#dataset

Instance Method Summary collapse

Methods included from Enumerable

add_entailment, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #entail, #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, #supports?, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Isomorphic

#bijection_to, #isomorphic_with?

Methods included from Countable

#count, #empty?

Constructor Details

#initialize(enumerable, options) ⇒ RDF::Enumerable

Create an enumerable with grounded nodes

Parameters:



12
13
14
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-normalize-e113452533ce/lib/rdf/normalize/carroll2001.rb', line 12

def initialize(enumerable, options)
  @dataset = enumerable
end

Dynamic Method Handling

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

Instance Method Details

#each(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-normalize-e113452533ce/lib/rdf/normalize/carroll2001.rb', line 16

def each(&block)
  ground_statements, anon_statements = [], []
  dataset.each_statement do |statement|
    (statement.has_blank_nodes? ? anon_statements : ground_statements) << statement
  end

  nodes = anon_statements.map(&:to_quad).flatten.compact.select(&:node?).uniq

  # Create a hash signature of every node, based on the signature of
  # statements it exists in.  
  # We also save hashes of nodes that cannot be reliably known; we will use
  # that information to eliminate possible recursion combinations.
  # 
  # Any mappings given in the method parameters are considered grounded.
  hashes, ungrounded_hashes = hash_nodes(anon_statements, nodes, {})

  # FIXME: likely need to iterate until hashes and ungrounded_hashes are the same size
  while hashes.size != ungrounded_hashes.size
    raise "Not done"
  end

  # Enumerate all statements, replacing nodes with new ground nodes using the hash as an identifier
  ground_statements.each(&block)
  anon_statements.each do |statement|
    quad = statement.to_quad.compact.map do |term|
      term.node? ? RDF::Node.intern(hashes[term]) : term
    end
    block.call RDF::Statement.from(quad)
  end
end