X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;fp=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;h=58e2c0531cb41bec456b451663450b6a6a030881;hb=624443b2a7c97a1808a42470dddf1437ed59cd21;hp=71fc67e8d272e8a2aeae384396b06542a89bf896;hpb=2ec792783adec802ae15dae3a5e2ebc355d59942;p=simantics%2Finterop.git 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 71fc67e..58e2c05 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -309,7 +309,7 @@ public class GraphComparator { } } - private void processUnreliable(Set unreliableLeft, Set unreliableRight) { + private void processUnreliable(Set unreliableLeft, Set unreliableRight) throws DatabaseException { MapList subjectLeft = new MapList(); MapList subjectRight = new MapList(); MapList objectLeft = new MapList(); @@ -352,7 +352,7 @@ public class GraphComparator { } } - private void processUnreliable(Set unreliableLeft, Set unreliableRight, Stack objectsLeft, Stack objectsRight) { + private void processUnreliable(Set unreliableLeft, Set unreliableRight, Stack objectsLeft, Stack objectsRight) throws DatabaseException { MapList subjectLeft = new MapList(); MapList subjectRight = new MapList(); MapList objectLeft = new MapList(); @@ -498,9 +498,9 @@ public class GraphComparator { List right = matchingOR.getValues(or); Pair indices = matchingStatements.get(or); - comparableResources.map(ol, or); objectsLeft.add(ol); objectsRight.add(or); + addComparable(ol, or, false); for (int l = 0; l < left.size(); l++) { int r = indices.first[l]; Statement sl = left.get(l); @@ -517,7 +517,7 @@ public class GraphComparator { } - private void processUnreliableDeep(Set unreliableLeft, Set unreliableRight, Stack objectsLeft, Stack objectsRight) throws ManyObjectsForFunctionalRelationException, ServiceException { + private void processUnreliableDeep(Set unreliableLeft, Set unreliableRight, Stack objectsLeft, Stack objectsRight) throws DatabaseException { MapList subjectLeft = new MapList(); MapList subjectRight = new MapList(); MapList objectLeft = new MapList(); @@ -565,23 +565,31 @@ public class GraphComparator { for (Path leftPath : pathsLeft) { possiblePathsRight.addAll(findComparableRight(leftPath, or)); } - if (possiblePathsRight.size() == pathsLeft.size()) { + if (hasMatchingPaths(pathsLeft, possiblePathsRight)) { matchingPaths.put(or, possiblePathsRight); } } if (matchingPaths.size() > 0) { if (matchingPaths.size() == 1) { Resource or = matchingPaths.keySet().iterator().next(); + objectsLeft.add(ol); objectsRight.add(or); - comparableResources.map(ol, or); + addComparable(ol, or, false); Collection statementsLeft = objectLeft.getValues(ol); Collection statementsRight = objectRight.getValues(or); unreliableLeft.removeAll(statementsLeft); unreliableRight.removeAll(statementsRight); - System.out.println("Compare not implemented"); + BijectionMap map = getMatchingPaths(pathsLeft, matchingPaths.get(or)); + for (Path left : map.getLeftSet()) { + Path right = map.getRight(left); + for (int i = 0; i < left.getLength(); i++) { + addComparable(left.getStatements().get(i),right.getStatements().get(i),false); + } + } + //System.out.println("Compare not implemented"); } else { - System.out.println("Compare not implemented"); + //System.out.println("Compare not implemented"); } } } @@ -590,6 +598,31 @@ public class GraphComparator { } + private boolean hasMatchingPaths(Set leftPaths, Set rightPaths) { + if (leftPaths.size() != rightPaths.size()) + return false; + BijectionMap map = getMatchingPaths(leftPaths, rightPaths); + return map.size() == leftPaths.size(); + + } + + private BijectionMap getMatchingPaths(Set leftPaths, Set rightPaths) { + BijectionMap map = new BijectionMap(); + for (Path leftPath : leftPaths) { + for (Path rightPath : rightPaths) { + if (map.containsRight(rightPath)) + continue; + if (leftPath.getLength() != rightPath.getLength()) + continue; + if (comparableResources.contains(leftPath.getEnd(), rightPath.getEnd())) { + map.map(leftPath, rightPath); + break; + } + } + } + return map; + } + private void expand(Set paths) throws ManyObjectsForFunctionalRelationException, ServiceException { Set stepPathsLeft = new HashSet(); if (paths.size() == 0) @@ -642,11 +675,23 @@ public class GraphComparator { return new GraphChanges(r1,r2,changes1,changes2,modifications,comparableResources); } - private void addComparable(Statement left, Statement right, boolean process) { + private void addComparable(Statement left, Statement right, boolean process) throws DatabaseException { + addComparable(left.getObject(), right.getObject(), process); comparableStatements.map(left, right); comparableResources.map(left.getObject(), right.getObject()); } + private void addComparable(Resource left, Resource right, boolean process) throws DatabaseException { + if(!comparableResources.contains(r1, r2)) { + if (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2)) { + throw new DatabaseException("Comparator error: Trying to map " + r1 + " to " + r2 + " while mappings " + r1 + " to " + comparableResources.getRight(r1) + " and " + comparableResources.getLeft(r2) + " to " + r2 + " exist."); + } else { + comparableResources.map(left, right); + } + } + + } + public List filterAsserted(Resource r, Collection in) throws ServiceException { List out = new ArrayList(); for (Statement s : in) { @@ -934,6 +979,8 @@ public class GraphComparator { Statement s2 = ss2.get(i2+off2); if (objectsLeft != null) { + if (s1.getObject().getResourceId() == 52825217 || s1.getObject().getResourceId() == 52825127) + System.out.println(); objectsLeft.add(s1.getObject()); objectsRight.add(s2.getObject()); } @@ -1004,7 +1051,7 @@ public class GraphComparator { * @throws DoesNotContainValueException * @throws ValidationException */ - private void compareProps(Resource r1, Resource r2) throws ServiceException, DoesNotContainValueException, ValidationException { + private void compareProps(Resource r1, Resource r2) throws DatabaseException { System.out.println("compareProps " + r1 + " " + NameUtils.getSafeName(g, r1) + " " + r2 + " " + NameUtils.getSafeName(g, r2)); ArrayList ss1 = new ArrayList(); ArrayList ss2 = new ArrayList();