]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
In some cases Comparator matched incorrect resources.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 24 Oct 2011 15:38:19 +0000 (15:38 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:17 +0000 (11:22 +0200)
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22935 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java

index 82b7bfbb2a136177db43fcc08a5dbb3faf20b817..ab9c67943d481fce82f8f64a73217790341c7ae8 100644 (file)
@@ -221,6 +221,12 @@ public class GraphComparator {
                        Resource r1 = objectsLeft.pop();\r
                        Resource r2 = objectsRight.pop();\r
                        \r
+//                     if (r1.getResourceId() == 42543612 ||\r
+//                             r1.getResourceId() == 42729524 ||\r
+//                             r1.getResourceId() == 42729506) {\r
+//                             System.out.println("test " + r1 + " " + r2);\r
+//                     }\r
+                       \r
                        if (r1.equals(r2))\r
                                continue;\r
                \r
@@ -323,7 +329,9 @@ public class GraphComparator {
                }\r
                \r
                for (Resource ol : objectLeft.getKeys()) {\r
-\r
+//                     if (ol.getResourceId() == 42729506) {\r
+//                             System.out.println();\r
+//                     }\r
                        // all statements to the left side object\r
                        List<Statement> left = objectLeft.getValues(ol);\r
                        // all subjects that have statements to the left side object (ol)\r
@@ -334,6 +342,58 @@ public class GraphComparator {
                                sLeft.add(s.getSubject());\r
                                sRight.add(comparableResources.getRight(s.getSubject()));\r
                        }\r
+                       \r
+                       // check if object left can be reliably identified by available statements\r
+                       // if there are any objects on the left side with similar statements, object left cannot be mapped.\r
+                       boolean hasSimilar = false;\r
+                       MapList<Resource, Statement> comparableOLeft = new MapList<Resource, Statement>();\r
+                       for (Resource sl : sLeft) {\r
+                               for (Statement s : subjectLeft.getValues(sl)) {\r
+                                       if (!s.getObject().equals(ol)) {\r
+                                               comparableOLeft.add(s.getObject(),s);\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       for (Resource similarOl : comparableOLeft.getKeys()) {\r
+                               List<Statement> similarLeft = comparableOLeft.getValues(similarOl);\r
+                               if (similarLeft.size() == left.size()) {\r
+                                       boolean useL[] = new boolean[left.size()];\r
+                                       boolean useSL[] = new boolean[left.size()];\r
+                                       for (int i = 0; i < left.size(); i++) {\r
+                                               useL[i] = false;\r
+                                               useSL[i] = false;\r
+                                       }\r
+                                       for (int i = 0; i < left.size(); i++) {\r
+                                               for (int j = 0; j < left.size(); j++) {\r
+                                                       if (useSL[j])\r
+                                                               continue;\r
+                                                       Resource pl = left.get(i).getPredicate();\r
+                                                       Resource psl = similarLeft.get(j).getPredicate();\r
+                                                       if (pl.equals(psl)) {\r
+                                                               useL[i] = true;\r
+                                                               useSL[j] = true;\r
+                                                               break;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       boolean diff = false;\r
+                                       for (int i = 0; i < left.size(); i++) {\r
+                                               if (!useL[i] || !useSL[i]) {\r
+                                                       diff = true;\r
+                                               }\r
+                                       }\r
+                                       if (!diff) {\r
+                                               hasSimilar = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       if (hasSimilar)\r
+                               continue;\r
+                               \r
+                       \r
                        // all objects that subjects on the right side point to. Object left has its matching resource among these, if it has matching resource\r
                        MapList<Resource,Statement> possibleOR = new MapList<Resource, Statement>();\r
                        for (Resource sr : sRight) {\r
@@ -546,6 +606,11 @@ public class GraphComparator {
        }\r
        \r
        private void addComparable(Statement left, Statement right, boolean process) {\r
+//             if (left.getObject().getResourceId() == 42543612 ||\r
+//                     left.getObject().getResourceId() == 42729524 ||\r
+//                     left.getObject().getResourceId() == 42729506) {\r
+//                             System.out.println("test " + r1 + " " + r2);\r
+//                     }\r
                comparableStatements.map(left, right);\r
                if (!process) {\r
                        comparableResources.map(left.getObject(), right.getObject());\r