+
+ /**
+ * priority matching has a flaw, if lowest priority produces conflicting results, it is not able to match anything.
+ * This matching logic looks for a best match, and if it is non conflicting applies the match.
+ *
+ * TODO: now this applies all unique lowest priority matches for each object. Should this pick only the object with global lowest priority,
+ * so that new matches improve situation with conflicting (non unique) matches?
+ *
+ * @param ss1
+ * @param off1
+ * @param len1
+ * @param ss2
+ * @param off2
+ * @param len2
+ * @param differences
+ * @param priorities
+ * @param used1
+ * @param used2
+ * @param objectsLeft
+ * @param objectsRight
+ * @throws DatabaseException
+ */
+ private void bestMatching(List<Statement> ss1, int off1, int len1, List<Statement> ss2, int off2, int len2, List<List<Integer>> differences, MapList<Integer, Integer> priorities, boolean used1[],boolean used2[], Collection<Resource> objectsLeft, Collection<Resource> objectsRight) throws DatabaseException {
+ for (int i1 = 0; i1 < differences.size(); i1++) {
+ if (used1[i1])
+ continue;
+ List<Integer> diffs = differences.get(i1);
+ int min = Integer.MAX_VALUE;
+ int minIndex = -1;
+ for (int j = 0; j < diffs.size(); j++) {
+ int p = diffs.get(j);
+ if (p < 0)
+ continue;
+ if (p < min) {
+ min = p;
+ minIndex = j;
+ } else if (p == min) {
+ minIndex = -1;
+ }
+ }
+ if (minIndex >= 0 && min > 0) {
+ int i2 = minIndex;
+ if (!used2[i2]) {
+ used1[i1] = true;
+ used2[i2] = true;
+ Statement s1 = ss1.get(i1+off1);
+ Statement s2 = ss2.get(i2+off2);
+
+ if (objectsLeft != null) {
+ objectsLeft.add(s1.getObject());
+ objectsRight.add(s2.getObject());
+ }
+ addComparable(s1, s2);
+ }
+ }
+ }
+ }