JENA-805 : Make graph isomorphism strictly "same term"
Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3ea2542c Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3ea2542c Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3ea2542c Branch: refs/heads/master Commit: 3ea2542c307a491071e9ee113841ea2c44f30334 Parents: fa5f8b1 Author: Andy Seaborne <a...@apache.org> Authored: Tue Oct 28 15:01:43 2014 +0000 Committer: Andy Seaborne <a...@apache.org> Committed: Tue Oct 28 15:01:43 2014 +0000 ---------------------------------------------------------------------- .../hp/hpl/jena/graph/impl/GraphMatcher.java | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/3ea2542c/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphMatcher.java ---------------------------------------------------------------------- diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphMatcher.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphMatcher.java index 84fe1da..ab470fc 100644 --- a/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphMatcher.java +++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/impl/GraphMatcher.java @@ -24,7 +24,7 @@ import com.hp.hpl.jena.util.CollectionFactory; import com.hp.hpl.jena.util.iterator.*; import com.hp.hpl.jena.shared.*; -// Purely syntactic: Uses .equals, not .sameVAlueAs (see the one note at "PURE SYNTAX" below) +// Purely syntactic: Uses .equals, not .sameVAlueAs (see the one note at "PURE SYNTAX" below and "containsSameTerm") /** * An implemantation of graph isomorphism for Graph equality. @@ -292,7 +292,7 @@ public class GraphMatcher extends java.lang.Object { Triple s = ss.next(); AnonStatement ass = new AnonStatement(s); if ( ass.pattern == NOVARS ) { - if ( !otherm.contains( s ) ) return -1; + if ( !containsSameTerm( otherm, s ) ) return -1; } else { hash += ass.myHashCode(ass.vars[0]); for (int i=0;i<ass.vars.length;i++) { @@ -310,6 +310,30 @@ public class GraphMatcher extends java.lang.Object { ss.close(); } } + + /** Special "contains" test that always provide "same term", + * not "sameValueAs" semantics on the containment. + * @param otherm + * @param triple + * @return + */ + private static boolean containsSameTerm(Graph otherm, Triple triple) { + boolean b = otherm.contains(triple) ; + Node o = triple.getObject() ; + if ( !o.isConcrete() || !o.isLiteral() ) + return b ; + if ( ! b ) + return false ; + // Force to same term when o is a ground literal. + ExtendedIterator<Triple> iter = otherm.find(triple) ; + while (iter.hasNext()) { + Triple t = iter.next() ; + if ( t.getObject().equals(o) ) + return true ; + } + return false ; + } + private Bucket smallestBucket() { check(HASH_OK); Iterator<Bucket> bit = table.values().iterator();