Class: RDF::Normalize::Carroll2001

Inherits:
Base show all
Includes:
Enumerable
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-normalize-5170ab39c807/lib/rdf/normalize/carroll2001.rb

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Attributes inherited from Base

#dataset

Instance Method Summary collapse

Methods included from Enumerable

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

Methods inherited from Base

#to_hash

Constructor Details

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

Create an enumerable with grounded nodes

Parameters:



10
11
12
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-normalize-5170ab39c807/lib/rdf/normalize/carroll2001.rb', line 10

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



14
15
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
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-normalize-5170ab39c807/lib/rdf/normalize/carroll2001.rb', line 14

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