From: luukkainen Date: Tue, 27 Sep 2011 14:49:42 +0000 (+0000) Subject: Improved handling of unidentified objects. X-Git-Tag: v1.31.0~108 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=499167aa0bcc2cab0066b87ef4a690c16ea92754;p=simantics%2Finterop.git Improved handling of unidentified objects. git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22442 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 e52a3bf..152d423 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -52,6 +52,7 @@ public class GraphComparator { private Resource r1; private Resource r2; + private Set strong = new HashSet(); // List of relations that identify object, if subject is already identified. private List traversed = new ArrayList(); // list of relations that are traversed (and tested) private List tested = new ArrayList(); // list of relations that are tested, but not traversed private List nonTraversed = new ArrayList(); // list of relations that are not traversed @@ -150,6 +151,10 @@ public class GraphComparator { comparableResources.addAll(matching); } + public void addStrong(Resource r) { + strong.add(r); + } + public void clearRels() { traversed.clear(); tested.clear(); @@ -174,45 +179,66 @@ public class GraphComparator { Set unreliableLeft = new HashSet(); Set unreliableRight = new HashSet(); - while (!objectsLeft.isEmpty()) { - Resource r1 = objectsLeft.pop(); - Resource r2 = objectsRight.pop(); - - if (comparableResources.contains(r1, r2)) { - //System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2)); - continue; - } - comparableResources.map(r1, r2); + while (true) { + if (objectsLeft.isEmpty()) + break; - //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2)); - compareProps(r1, r2); + while (!objectsLeft.isEmpty()) { + Resource r1 = objectsLeft.pop(); + Resource r2 = objectsRight.pop(); - for (Resource rel : tested) { - ss1.addAll(g.getStatements(r1, rel)); - ss2.addAll(g.getStatements(r2, rel)); - ss1 = filterAsserted(r1, ss1); - ss2 = filterAsserted(r2, ss2); - ss1 = filterTraversed(ss1); - ss2 = filterTraversed(ss2); - ss1 = filterNonTested(ss1); - ss2 = filterNonTested(ss2); + if (comparableResources.contains(r1, r2)) { + //System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2)); + continue; + } + comparableResources.map(r1, r2); - compareStatements(ss1, ss2, null, null,null,null); - ss1.clear(); - ss2.clear(); - } - - for (Resource rel : traversed) { - ss1.addAll(g.getStatements(r1, rel)); - ss2.addAll(g.getStatements(r2, rel)); - ss1 = filterAsserted(r1, ss1); - ss2 = filterAsserted(r2, ss2); - compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight); - ss1.clear(); - ss2.clear(); + //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2)); + compareProps(r1, r2); + for (Resource rel : tested) { + ss1.addAll(g.getStatements(r1, rel)); + ss2.addAll(g.getStatements(r2, rel)); + ss1 = filterAsserted(r1, ss1); + ss2 = filterAsserted(r2, ss2); + ss1 = filterTraversed(ss1); + ss2 = filterTraversed(ss2); + ss1 = filterNonTested(ss1); + ss2 = filterNonTested(ss2); + + compareStatements(ss1, ss2, null, null,null,null); + ss1.clear(); + ss2.clear(); + } + + for (Resource rel : traversed) { + ss1.addAll(g.getStatements(r1, rel)); + ss2.addAll(g.getStatements(r2, rel)); + ss1 = filterAsserted(r1, ss1); + ss2 = filterAsserted(r2, ss2); + compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight); + ss1.clear(); + ss2.clear(); + + } } + + processUnreliable(unreliableLeft, unreliableRight,objectsLeft,objectsRight); + } + for (Statement s : unreliableLeft) { + if (!comparableStatements.containsLeft(s)) + addDeletion(s); + } + for (Statement s : unreliableRight) { + if (!comparableStatements.containsRight(s)) + addAddition(s); + } + + + } + + private void processUnreliable(Set unreliableLeft, Set unreliableRight, Stack objectsLeft, Stack objectsRight) { MapList subjectLeft = new MapList(); MapList subjectRight = new MapList(); MapList objectLeft = new MapList(); @@ -307,29 +333,22 @@ public class GraphComparator { List right = matchingOR.getValues(or); Pair indices = matchingStatements.get(or); - comparableResources.map(ol, or); + //comparableResources.map(ol, or); + objectsLeft.add(ol); + objectsRight.add(or); for (int l = 0; l < left.size(); l++) { int r = indices.first[l]; comparableStatements.map(left.get(l), right.get(r)); + unreliableLeft.remove(left.get(l)); + unreliableRight.remove(right.get(r)); } } } - for (Statement s : unreliableLeft) { - if (!comparableStatements.containsLeft(s)) - addDeletion(s); - } - for (Statement s : unreliableRight) { - if (!comparableStatements.containsRight(s)) - addAddition(s); - } - - } - - + } public BijectionMap getComparableStatements() { return comparableStatements; @@ -581,6 +600,14 @@ public class GraphComparator { for (int i2 = off2; i2 < off2 + len2; i2++) { Statement s2 = ss2.get(i2); int d = compareObject(s1.getObject(), s2.getObject()); + if (d == 0) { + for (Resource t : strong) { + if (s1.getPredicate().equals(t) || g.isSubrelationOf(s1.getPredicate(), t)) { + d = 1; + break; + } + } + } diff.add(d); } differences.add(diff); diff --git a/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java b/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java index 5bdb3f0..125d059 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java @@ -8,7 +8,9 @@ import org.simantics.db.exception.ServiceException; import org.simantics.layer0.Layer0; /** - * * Object comparator that uses type and name of objects to check if objects are comparable. + * Object comparator that uses type and name of objects to check if objects are comparable. + * If objects have no name, compare returns unreliable as result. + * * * Difference value is amount of properties that have different values. * @@ -23,10 +25,13 @@ public class NameComparator extends TypeComparator { if (!compareType(g,o1, o2)) { return Integer.MAX_VALUE; } - if(!compareName(g, o1, o2)) - return Integer.MAX_VALUE; + if (hasName(g, o1, o2)) { + if(!compareName(g, o1, o2)) + return Integer.MAX_VALUE; + return propsDiffCount(g,o1, o2); + } + return 0; - return propsDiffCount(g,o1, o2); } protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException { @@ -40,5 +45,15 @@ public class NameComparator extends TypeComparator { return false; } + + protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException { + Layer0 l0 = Layer0.getInstance(g); + String n1 = g.getPossibleRelatedValue(o1, l0.HasName); + String n2 = g.getPossibleRelatedValue(o2, l0.HasName); + if (n1 != null && n2 != null) + return true; + return false; + + } } diff --git a/org.simantics.interop/src/org/simantics/interop/test/ResourceComparator.java b/org.simantics.interop/src/org/simantics/interop/test/ResourceComparator.java index 3d31d22..0b0a7c1 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/ResourceComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/ResourceComparator.java @@ -27,6 +27,7 @@ public abstract class ResourceComparator { * Special values: * Integer.MAX_VALUE: Objects are not comparable. * 0 (zero): Object comparison is not reliable. + * * @param g * @param o1 * @param o2 diff --git a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java index 96ef610..1417588 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java @@ -16,7 +16,8 @@ import org.simantics.layer0.Layer0; /** * Object comparator that uses type of objects to check if objects are comparable. * - * Difference value is amount of properties that have different values. + * Difference value is amount of properties that have different values. If objects have no properties, the result is 0 (unreliable). + * * * @author Marko Luukkainen *