From 240c4a4d8efbb302feedccac76edd5c28d6d7150 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Mon, 24 Oct 2011 15:38:19 +0000 Subject: [PATCH] In some cases Comparator matched incorrect resources. git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22935 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../interop/test/GraphComparator.java | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java index 82b7bfb..ab9c679 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -221,6 +221,12 @@ public class GraphComparator { Resource r1 = objectsLeft.pop(); Resource r2 = objectsRight.pop(); +// if (r1.getResourceId() == 42543612 || +// r1.getResourceId() == 42729524 || +// r1.getResourceId() == 42729506) { +// System.out.println("test " + r1 + " " + r2); +// } + if (r1.equals(r2)) continue; @@ -323,7 +329,9 @@ public class GraphComparator { } for (Resource ol : objectLeft.getKeys()) { - +// if (ol.getResourceId() == 42729506) { +// System.out.println(); +// } // all statements to the left side object List left = objectLeft.getValues(ol); // all subjects that have statements to the left side object (ol) @@ -334,6 +342,58 @@ public class GraphComparator { sLeft.add(s.getSubject()); sRight.add(comparableResources.getRight(s.getSubject())); } + + // check if object left can be reliably identified by available statements + // if there are any objects on the left side with similar statements, object left cannot be mapped. + boolean hasSimilar = false; + MapList comparableOLeft = new MapList(); + for (Resource sl : sLeft) { + for (Statement s : subjectLeft.getValues(sl)) { + if (!s.getObject().equals(ol)) { + comparableOLeft.add(s.getObject(),s); + } + } + } + + for (Resource similarOl : comparableOLeft.getKeys()) { + List similarLeft = comparableOLeft.getValues(similarOl); + if (similarLeft.size() == left.size()) { + boolean useL[] = new boolean[left.size()]; + boolean useSL[] = new boolean[left.size()]; + for (int i = 0; i < left.size(); i++) { + useL[i] = false; + useSL[i] = false; + } + for (int i = 0; i < left.size(); i++) { + for (int j = 0; j < left.size(); j++) { + if (useSL[j]) + continue; + Resource pl = left.get(i).getPredicate(); + Resource psl = similarLeft.get(j).getPredicate(); + if (pl.equals(psl)) { + useL[i] = true; + useSL[j] = true; + break; + } + } + } + boolean diff = false; + for (int i = 0; i < left.size(); i++) { + if (!useL[i] || !useSL[i]) { + diff = true; + } + } + if (!diff) { + hasSimilar = true; + break; + } + } + } + + if (hasSimilar) + continue; + + // all objects that subjects on the right side point to. Object left has its matching resource among these, if it has matching resource MapList possibleOR = new MapList(); for (Resource sr : sRight) { @@ -546,6 +606,11 @@ public class GraphComparator { } private void addComparable(Statement left, Statement right, boolean process) { +// if (left.getObject().getResourceId() == 42543612 || +// left.getObject().getResourceId() == 42729524 || +// left.getObject().getResourceId() == 42729506) { +// System.out.println("test " + r1 + " " + r2); +// } comparableStatements.map(left, right); if (!process) { comparableResources.map(left.getObject(), right.getObject()); -- 2.47.1