]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Asserted properties caused wrong change reports. 70/3770/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 9 Jan 2020 16:56:05 +0000 (18:56 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 9 Jan 2020 16:56:05 +0000 (18:56 +0200)
ReadGraph.getStatements(s,L0.HasProperty) returns both instance
statements for s, but also asserted statements. Hence, the same
properties were added to processing list twice, causing skewed
comparison results.

gitlab #10

Change-Id: I2ebc3e3b9303c6716a830aee8cb95b391d68c6fd

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

index 8ec4102a6bea3c6720899ea60fd6c77ef2b375aa..ce7af6d1aee6c3f8ff1f81cffa6c33cfe06f1b86 100644 (file)
@@ -173,17 +173,26 @@ public class GraphChanges {
                for (Modification mod :modifications) {
                        {
                                Statement stm = mod.getLeftStm();
-                               sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+
-                                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                                  truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
-                                          stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                               if (stm != null) {
+                                       sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+
+                                                          NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+                                                          truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
+                                                          mod.getLeftSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                               } else {
+                                       sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+  mod.getLeftSub() + " N/A\n");
+                               }
                        }
                        {
                                Statement stm = mod.getRightStm();
-                               sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+
-                                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                                  truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
-                                          stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                               if (stm != null) {
+                                       sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+
+                                                          NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+                                                          truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
+                                                          mod.getRightSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                               } else {
+                                       sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+  mod.getRightSub() + " N/A\n");
+                               }
+                               
                        }
        }
                return sb.toString();
index ac39e2f4f8f5d3b92c2176500c8751e31f8775d7..ba9bdf099397a90a8a2bc423c26d24354a29a2bf 100644 (file)
@@ -52,7 +52,7 @@ import org.simantics.utils.datastructures.Pair;
  */
 public class GraphComparator {
        
-       private static final boolean DEBUG = true;
+       private static final boolean DEBUG = false;
 
        private Resource r1;
        private Resource r2;
@@ -308,8 +308,6 @@ public class GraphComparator {
                        
                        if (r1.equals(r2))
                                continue;
-                       if (r1.getResourceId() == 610446L)
-                               System.out.println();
                        if (processedResources.contains(r1))
                                continue;
                        processedResources.add(r1);
@@ -789,8 +787,6 @@ public class GraphComparator {
                                throw new DatabaseException("Comparator error: Trying to map " + left + " to " + right + " while mappings " + left + " to " + comparableResources.getRight(left) + " and " + comparableResources.getLeft(right) + " to " + right + " exist.");
                        } else {
                                if (DEBUG) System.out.println(left + " = " + right);
-                               if (left.getResourceId() == 610381L)
-                                       System.out.println();
                                comparableResources.map(left, right);
                        }
                }
@@ -807,6 +803,31 @@ public class GraphComparator {
                return out;
        }
        
+       public List<Statement> filterAssertedDuplicates(Resource r, List<Statement> in) throws DatabaseException {
+               List<Statement> out = new ArrayList<Statement>();
+               for (int i = 0; i < in.size(); i++) {
+                       Statement s = in.get(i);
+                       if (!s.isAsserted(r))
+                               out.add(s);
+                       else {
+                               boolean has = false;
+                               if (i > 1 && in.get(i-1).getPredicate().equals(s.getPredicate()))
+                                       has = true;
+                               else if (i < in.size()-1 && in.get(i+1).getPredicate().equals(s.getPredicate()))
+                                       has = true;
+                               if (!has)
+                                       out.add(s);
+                       }
+                       
+               }
+               for (Statement s : in) {
+                       if (!s.isAsserted(r))
+                               out.add(s);
+                       
+               }
+               return out;
+       }
+       
        
 
        private String printStatement(ReadGraph graph, Statement s) throws DatabaseException {
@@ -1173,6 +1194,9 @@ public class GraphComparator {
                ss1 = filterNonTested(ss1);
                ss2 = filterNonTested(ss2);
                sortStatement(ss1, ss2);
+               // getStatements(r1, b.HasProperty) returns both instance and asserted statements for the same property relation. 
+               ss1 = filterAssertedDuplicates(r1, ss1);
+               ss2 = filterAssertedDuplicates(r2, ss2);
                
                int i1 = 0; 
                int i2 = 0;