\r
private Resource r1;\r
private Resource r2;\r
+ private Set<Resource> strong = new HashSet<Resource>(); // List of relations that identify object, if subject is already identified. \r
private List<Resource> traversed = new ArrayList<Resource>(); // list of relations that are traversed (and tested)\r
private List<Resource> tested = new ArrayList<Resource>(); // list of relations that are tested, but not traversed\r
private List<Resource> nonTraversed = new ArrayList<Resource>(); // list of relations that are not traversed\r
comparableResources.addAll(matching);\r
}\r
\r
+ public void addStrong(Resource r) {\r
+ strong.add(r);\r
+ }\r
+ \r
public void clearRels() {\r
traversed.clear();\r
tested.clear();\r
Set<Statement> unreliableLeft = new HashSet<Statement>();\r
Set<Statement> unreliableRight = new HashSet<Statement>();\r
\r
- while (!objectsLeft.isEmpty()) {\r
- Resource r1 = objectsLeft.pop();\r
- Resource r2 = objectsRight.pop();\r
- \r
- if (comparableResources.contains(r1, r2)) {\r
- //System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
- continue;\r
- }\r
- comparableResources.map(r1, r2);\r
+ while (true) {\r
+ if (objectsLeft.isEmpty())\r
+ break;\r
\r
- //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
- compareProps(r1, r2);\r
+ while (!objectsLeft.isEmpty()) {\r
+ Resource r1 = objectsLeft.pop();\r
+ Resource r2 = objectsRight.pop();\r
\r
- for (Resource rel : tested) {\r
- ss1.addAll(g.getStatements(r1, rel));\r
- ss2.addAll(g.getStatements(r2, rel));\r
- ss1 = filterAsserted(r1, ss1);\r
- ss2 = filterAsserted(r2, ss2);\r
- ss1 = filterTraversed(ss1);\r
- ss2 = filterTraversed(ss2);\r
- ss1 = filterNonTested(ss1);\r
- ss2 = filterNonTested(ss2);\r
+ if (comparableResources.contains(r1, r2)) {\r
+ //System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
+ continue;\r
+ }\r
+ comparableResources.map(r1, r2);\r
\r
- compareStatements(ss1, ss2, null, null,null,null);\r
- ss1.clear();\r
- ss2.clear();\r
- }\r
- \r
- for (Resource rel : traversed) {\r
- ss1.addAll(g.getStatements(r1, rel));\r
- ss2.addAll(g.getStatements(r2, rel));\r
- ss1 = filterAsserted(r1, ss1);\r
- ss2 = filterAsserted(r2, ss2);\r
- compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight);\r
- ss1.clear();\r
- ss2.clear();\r
+ //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
+ compareProps(r1, r2);\r
\r
+ for (Resource rel : tested) {\r
+ ss1.addAll(g.getStatements(r1, rel));\r
+ ss2.addAll(g.getStatements(r2, rel));\r
+ ss1 = filterAsserted(r1, ss1);\r
+ ss2 = filterAsserted(r2, ss2);\r
+ ss1 = filterTraversed(ss1);\r
+ ss2 = filterTraversed(ss2);\r
+ ss1 = filterNonTested(ss1);\r
+ ss2 = filterNonTested(ss2);\r
+ \r
+ compareStatements(ss1, ss2, null, null,null,null);\r
+ ss1.clear();\r
+ ss2.clear();\r
+ }\r
+ \r
+ for (Resource rel : traversed) {\r
+ ss1.addAll(g.getStatements(r1, rel));\r
+ ss2.addAll(g.getStatements(r2, rel));\r
+ ss1 = filterAsserted(r1, ss1);\r
+ ss2 = filterAsserted(r2, ss2);\r
+ compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight);\r
+ ss1.clear();\r
+ ss2.clear();\r
+ \r
+ }\r
}\r
+ \r
+ processUnreliable(unreliableLeft, unreliableRight,objectsLeft,objectsRight);\r
+ \r
}\r
+ for (Statement s : unreliableLeft) {\r
+ if (!comparableStatements.containsLeft(s))\r
+ addDeletion(s);\r
+ }\r
+ for (Statement s : unreliableRight) {\r
+ if (!comparableStatements.containsRight(s))\r
+ addAddition(s);\r
+ }\r
+ \r
+ \r
+ }\r
+ \r
+ private void processUnreliable(Set<Statement> unreliableLeft, Set<Statement> unreliableRight, Stack<Resource> objectsLeft, Stack<Resource> objectsRight) {\r
MapList<Resource,Statement> subjectLeft = new MapList<Resource, Statement>();\r
MapList<Resource,Statement> subjectRight = new MapList<Resource, Statement>();\r
MapList<Resource,Statement> objectLeft = new MapList<Resource, Statement>();\r
List<Statement> right = matchingOR.getValues(or);\r
Pair<int[], int[]> indices = matchingStatements.get(or);\r
\r
- comparableResources.map(ol, or);\r
+ //comparableResources.map(ol, or);\r
+ objectsLeft.add(ol);\r
+ objectsRight.add(or);\r
for (int l = 0; l < left.size(); l++) {\r
int r = indices.first[l];\r
comparableStatements.map(left.get(l), right.get(r));\r
+ unreliableLeft.remove(left.get(l));\r
+ unreliableRight.remove(right.get(r));\r
}\r
\r
}\r
\r
}\r
\r
- for (Statement s : unreliableLeft) {\r
- if (!comparableStatements.containsLeft(s))\r
- addDeletion(s);\r
- }\r
- for (Statement s : unreliableRight) {\r
- if (!comparableStatements.containsRight(s))\r
- addAddition(s);\r
- }\r
- \r
\r
- }\r
- \r
- \r
+ }\r
\r
public BijectionMap<Statement, Statement> getComparableStatements() {\r
return comparableStatements;\r
for (int i2 = off2; i2 < off2 + len2; i2++) {\r
Statement s2 = ss2.get(i2);\r
int d = compareObject(s1.getObject(), s2.getObject());\r
+ if (d == 0) {\r
+ for (Resource t : strong) {\r
+ if (s1.getPredicate().equals(t) || g.isSubrelationOf(s1.getPredicate(), t)) {\r
+ d = 1;\r
+ break;\r
+ }\r
+ }\r
+ }\r
diff.add(d);\r
}\r
differences.add(diff);\r
import org.simantics.layer0.Layer0;\r
\r
/**\r
- * * Object comparator that uses type and name of objects to check if objects are comparable. \r
+ * Object comparator that uses type and name of objects to check if objects are comparable.\r
+ * If objects have no name, compare returns unreliable as result.\r
+ * \r
* \r
* Difference value is amount of properties that have different values.\r
* \r
if (!compareType(g,o1, o2)) {\r
return Integer.MAX_VALUE;\r
}\r
- if(!compareName(g, o1, o2))\r
- return Integer.MAX_VALUE;\r
+ if (hasName(g, o1, o2)) {\r
+ if(!compareName(g, o1, o2))\r
+ return Integer.MAX_VALUE;\r
+ return propsDiffCount(g,o1, o2);\r
+ }\r
+ return 0;\r
\r
- return propsDiffCount(g,o1, o2);\r
}\r
\r
protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
return false;\r
\r
}\r
+ \r
+ protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
+ Layer0 l0 = Layer0.getInstance(g);\r
+ String n1 = g.getPossibleRelatedValue(o1, l0.HasName);\r
+ String n2 = g.getPossibleRelatedValue(o2, l0.HasName);\r
+ if (n1 != null && n2 != null)\r
+ return true;\r
+ return false;\r
+ \r
+ }\r
\r
}\r