lib/rdf/isomorphic.rb in rdf-isomorphic-1.0.0 vs lib/rdf/isomorphic.rb in rdf-isomorphic-1.0.1

- old
+ new

@@ -7,13 +7,14 @@ ## # Isomorphism for rdf.rb Enumerables # # RDF::Isomorphic provides the functions isomorphic_with and bijection_to for RDF::Enumerable. # - # @see http://rdf.rubyforge.org + # @see http://ruby-rdf.github.com/rdf # @see http://www.hpl.hp.com/techreports/2001/HPL-2001-293.pdf module Isomorphic + autoload :VERSION, 'rdf/isomorphic/version' # 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 @@ -45,11 +46,11 @@ # repository_a.bijection_to repository_b # @param other [RDF::Enumerable] # @param opts [Hash<Symbol => Any>] options # @return [Hash, nil] def bijection_to(other, opts = {}) - + grounded_stmts_match = (count == other.count) grounded_stmts_match &&= each_statement.all? do | stmt | stmt.has_blank_nodes? || other.has_statement?(stmt) end @@ -105,12 +106,11 @@ # they are isomorphic). If there exists a grounded node in one that is # not in the other, we can just return. Ungrounded nodes might still # conflict, so we don't check them. This is a little bit messy in the # middle of the method, and probably slows down isomorphic checks, but # prevents almost-isomorphic cases from getting nutty. - return nil if these_hashes.values.any? { |hash| - !(other_hashes.values.member?(hash)) } + return nil if these_hashes.values.any? { |hash| !(other_hashes.values.member?(hash)) } return nil if other_hashes.values.any? { |hash| !(these_hashes.values.member?(hash)) } # Using the created hashes, map nodes to other_nodes # Ungrounded hashes will also be equal, but we keep the distinction # around for when we recurse later (we only recurse on ungrounded nodes) @@ -190,11 +190,11 @@ hash_needed = true # We may have to go over the list multiple times. If a node is marked as # grounded, other nodes can then use it to decide their own state of # grounded. - while hash_needed + while hash_needed starting_grounded_nodes = hashes.size nodes.each do | node | unless hashes.member? node grounded, hash = node_hash_for(node, statements, hashes, canonicalize) if grounded @@ -205,14 +205,14 @@ end # after going over the list, any nodes with a unique hash can be marked # as grounded, even if we have not tied them back to a root yet. uniques = {} ungrounded_hashes.each do |node, hash| - uniques[hash] = uniques[hash].is_a?(RDF::Node) ? false : node + uniques[hash] = uniques.has_key?(hash) ? false : node end uniques.each do |hash, node| - hashes[node] = hash unless node == false + hashes[node] = hash if node end hash_needed = starting_grounded_nodes != hashes.size end [hashes,ungrounded_hashes] end @@ -236,11 +236,11 @@ grounded = true statements.each do | statement | if (statement.object == node) || (statement.subject == node) statement_signatures << hash_string_for(statement, hashes, node, canonicalize) [statement.subject, statement.object].each do | resource | - grounded = false unless grounded(resource, hashes) || resource == node + grounded = false unless grounded?(resource, hashes) || resource == node end end end # Note that we sort the signatures--without a canonical ordering, # we might get different hashes for equivalent nodes. @@ -262,10 +262,10 @@ # Returns true if a given node is grounded # A node is groundd if it is not a blank node or it is included # in the given mapping of grounded nodes. # @return [Boolean] # @private - def self.grounded(node, hashes) + def self.grounded?(node, hashes) (!(node.node?)) || (hashes.member? node) end # Provides a string for the given node for use in a string signature # Non-anonymous nodes will return their string form. Grounded anonymous