Module: RDF::Isomorphic

Included in:
Enumerable
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-isomorphic-aef35942fe54/lib/rdf/isomorphic.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-isomorphic-aef35942fe54/lib/rdf/isomorphic/version.rb

Overview

Isomorphism for rdf.rb Enumerables

RDF::Isomorphic provides the functions isomorphic_with and bijection_to for RDF::Enumerable.

Defined Under Namespace

Modules: VERSION

Instance Method Summary collapse

Instance Method Details

#bijection_to(other, opts = {}) ⇒ Hash?

Returns a hash of RDF:Nodes: RDF::Nodes representing an isomorphic bijection of this RDF::Enumerable's to another RDF::Enumerable's blank nodes, or nil if a bijection cannot be found.

Takes a canonicalize: true argument. If true, RDF::Literals will be canonicalized while producing a bijection. This results in broader matches for isomorphism in the case of equivalent literals with different representations.

Examples:

repository_a.bijection_to repository_b

Parameters:

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-isomorphic-aef35942fe54/lib/rdf/isomorphic.rb', line 50

def bijection_to(other, opts = {})

  grounded_stmts_match = (count == other.count)

  grounded_stmts_match &&= each_statement.all? do | stmt |
    stmt.node? || other.has_statement?(stmt)
  end

  if grounded_stmts_match
    # blank_stmts and other_blank_stmts are just a performance
    # consideration--we could just as well pass in self and other.  But we
    # will be iterating over this list quite a bit during the algorithm, so
    # we break it down to the parts we're interested in.
    blank_stmts = find_all { |statement| statement.node? }
    other_blank_stmts = other.find_all { |statement| statement.node? }

    nodes = RDF::Isomorphic.blank_nodes_in(blank_stmts)
    other_nodes = RDF::Isomorphic.blank_nodes_in(other_blank_stmts)
    build_bijection_to blank_stmts, nodes, other_blank_stmts, other_nodes, {}, {}, opts
  else
    nil
  end

end

#isomorphic_with?(other, opts = {}) ⇒ Boolean Also known as: isomorphic?

Returns true if this RDF::Enumerable is isomorphic with another.

Takes a canonicalize: true argument. If true, RDF::Literals will be canonicalized while producing a bijection. This results in broader matches for isomorphism in the case of equivalent literals with different representations.

Examples:

repository_a.isomorphic_with repository_b #=> true

Parameters:

Returns:

  • (Boolean)


29
30
31
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-isomorphic-aef35942fe54/lib/rdf/isomorphic.rb', line 29

def isomorphic_with?(other, opts = {})
  !(bijection_to(other, opts).nil?)
end