Class: RDF::Normalize::URGNA2012::NormalizationState

Inherits:
RDFC10::NormalizationState show all
Defined in:
lib/rdf/normalize/urgna2012.rb

Instance Attribute Summary

Attributes inherited from RDFC10::NormalizationState

#bnode_to_statements, #canonical_issuer, #hash_algorithm, #hash_to_bnodes, #max_calls, #total_calls

Instance Method Summary collapse

Methods inherited from RDFC10::NormalizationState

#add_bnode_hash, #add_statement, #hash_first_degree_quads, #hash_n_degree_quads, #initialize, #inspect, #inspect_bnode_to_statements, #inspect_hash_to_bnodes

Constructor Details

This class inherits a constructor from RDF::Normalize::RDFC10::NormalizationState

Instance Method Details

Returns the SHA1 hexdigest hash.

Parameters:

  • related (RDF::Node)
  • statement (RDF::Statement)
  • issuer (IdentifierIssuer)
  • position (String)

    one of :s, :o, or :g

Returns:

  • (String)

    the SHA1 hexdigest hash



28
29
30
31
32
33
34
35
# File 'lib/rdf/normalize/urgna2012.rb', line 28

def hash_related_node(related, statement, issuer, position)
  identifier = canonical_issuer.identifier(related) ||
               issuer.identifier(related) ||
               hash_first_degree_quads(related)
  input = "#{position}#{statement.predicate}#{identifier}"
  log_debug("hrel") {"input: #{input.inspect}, hash: #{hexdigest(input)}"}
  hexdigest(input)
end

In URGNA2012, the position parameter passed to the Hash Related Blank Node algorithm was instead modeled as a direction parameter, where it could have the value p, for property, when the related blank node was a subject and the value r, for reverse or reference, when the related blank node was an object. Since URGNA2012 only normalized graphs, not datasets, there was no use of the graph position.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rdf/normalize/urgna2012.rb', line 38

def hash_related_statement(identifier, statement, issuer, map)
  if statement.subject.node? && statement.subject != identifier
    hash = log_depth {hash_related_node(statement.subject, statement, issuer, :p)}
    map[hash] ||= []
    map[hash] << statement.subject unless map[hash].any? {|n| n.eql?(statement.subject)}
  elsif statement.object.node? && statement.object != identifier
    hash = log_depth {hash_related_node(statement.object, statement, issuer, :r)}
    map[hash] ||= []
    map[hash] << statement.object unless map[hash].any? {|n| n.eql?(statement.object)}
  end
end

#hexdigest(val) ⇒ Object (protected)

2012 version uses SHA-1



19
20
21
# File 'lib/rdf/normalize/urgna2012.rb', line 19

def hexdigest(val)
  Digest::SHA1.hexdigest(val)
end