From: Marko Luukkainen Date: Thu, 9 Jan 2020 16:56:05 +0000 (+0200) Subject: Asserted properties caused wrong change reports. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=894fd479af4bd23016e38165b8ba3d6235d27125;p=simantics%2Finterop.git Asserted properties caused wrong change reports. 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 --- diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java index 8ec4102..ce7af6d 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java @@ -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(); 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 ac39e2f..ba9bdf0 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -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 filterAssertedDuplicates(Resource r, List in) throws DatabaseException { + List out = new ArrayList(); + 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;