Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2013-07-23 15:20:38 +0000
committerMikaƫl Barbero2013-08-19 12:28:55 +0000
commitb7b0e9e562817b02fed04d37657a744f2797ceed (patch)
tree1bbf2738588bf15542e2061ed7450ddbb2932e9d
parentce440ff947d28209813d9a3a51d78554d0dfe036 (diff)
downloadorg.eclipse.emf.compare-b7b0e9e562817b02fed04d37657a744f2797ceed.tar.gz
org.eclipse.emf.compare-b7b0e9e562817b02fed04d37657a744f2797ceed.tar.xz
org.eclipse.emf.compare-b7b0e9e562817b02fed04d37657a744f2797ceed.zip
Tunes the Distance Weights
A few issues have been identified and are fixed with this commit : - subsequent diffs for multi-valued features adds up a lot leading to no-match. - the default weight for "having the same parent" (getParentWeight) is too low in the general case. With these changes I ends up with only 3 results which are different from EMF Compare 1.x and each of them is better. Change-Id: Idee429fcf1558046504a3986c76f8f0eb8f7b882 (cherry picked from commit ac327e08adec64c7015e8ed6652d5fae85b18535) Conflicts: plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java6
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java58
2 files changed, 46 insertions, 18 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
index 2d3a18904..e81ea468c 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2013 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -415,7 +415,7 @@ public class EditionDistance implements DistanceFunction {
* we just want to pick the same positioned object if two exactly similar objects are
* candidates in the same container.
*/
- changes += 1;
+ changes += 5;
}
}
@@ -621,7 +621,7 @@ public class EditionDistance implements DistanceFunction {
* @return a ratio to appli on the amount of maximum un-similarity amount depending on the number of
* features which are considered.
*/
- private double getThresholdRatio(int nbFeatures) {
+ protected double getThresholdRatio(int nbFeatures) {
if (nbFeatures >= thresholds.length) {
// CHECKSTYLE:OFF
return 0.465d;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java
index d5929385c..c0834d8cc 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java
@@ -33,6 +33,36 @@ import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
*/
public class ReflectiveWeightProvider implements WeightProvider {
+ /***
+ * Something not impacting the object identity unless it adds up a lot.
+ */
+ private static final int SMALL = 5;
+
+ /**
+ * A normal change in an object.
+ */
+ private static final int NORMAL = 10;
+
+ /**
+ * Likely to impact the object identity.
+ */
+ private static final int SIGNIFICANT = 20;
+
+ /**
+ * Quite important regarding the Object identity.
+ */
+ private static final int MAJOR = 150;
+
+ /**
+ * Very important regarding the Object identity.
+ */
+ private static final int MASSIVE = 350;
+
+ /**
+ * It is very unlikely the elements are matching if they have differences of this magnitude.
+ */
+ private static final int UNLIKELY_TO_MATCH = 1000;
+
/**
* The list of specific weight to apply on specific Features.
*/
@@ -46,12 +76,12 @@ public class ReflectiveWeightProvider implements WeightProvider {
/**
* Weight coefficient of a change on a reference.
*/
- private int referenceChangeCoef = 2;
+ private int referenceChangeCoef = NORMAL;
/**
* Weight coefficient of a change on an attribute.
*/
- private int attributeChangeCoef = 5;
+ private int attributeChangeCoef = SIGNIFICANT;
/**
* Create the weight provider.
@@ -72,17 +102,17 @@ public class ReflectiveWeightProvider implements WeightProvider {
Integer found = weights.get(feature);
if (found == null) {
- found = Integer.valueOf(1);
+ found = Integer.valueOf(SMALL);
/*
* This is worst than empirical but it works in many cases, if your feature is a "name" its likely
* that it's important for matching the element. At some point I'll have to come up with something
* which is more extensible..
*/
if ("name".equals(feature.getName()) || "id".equals(feature.getName())) { //$NON-NLS-1$
- found = Integer.valueOf(4);
+ found = Integer.valueOf(SIGNIFICANT);
}
if (feature instanceof EReference && ((EReference)feature).isContainment()) {
- found = Integer.valueOf(2);
+ found = Integer.valueOf(NORMAL);
}
}
if (feature instanceof EReference) {
@@ -118,17 +148,17 @@ public class ReflectiveWeightProvider implements WeightProvider {
* these should belong to an Ecore specific class
*/
if (a instanceof EStructuralFeature) {
- return 34;
+ return MASSIVE;
} else if (a instanceof EAnnotation) {
- return 34;
+ return UNLIKELY_TO_MATCH;
} else if (a instanceof EOperation) {
- return 20;
+ return MAJOR;
} else if (a instanceof EParameter) {
- return 30;
+ return UNLIKELY_TO_MATCH;
} else if (a instanceof EStringToStringMapEntryImpl) {
- return 30;
+ return UNLIKELY_TO_MATCH;
}
- return 1;
+ return SIGNIFICANT;
}
// CHECKSTYLE:ON
@@ -140,12 +170,10 @@ public class ReflectiveWeightProvider implements WeightProvider {
/*
* these should belong to an ECore specific class
*/
- // CHECKSTYLE:OFF
if (a instanceof EStructuralFeature || a instanceof EAnnotation || a instanceof EOperation) {
- return 20;
+ return MAJOR;
}
- // CHECKSTYLE:ON
- return 1;
+ return SIGNIFICANT;
}
}

Back to the top