Explorar el Código

Add similarityThreshold option

Philipp Bauch hace 6 años
padre
commit
fc2ae065dc

+ 20 - 0
jplag/src/main/java/jplag/JPlagOptions.java

@@ -57,6 +57,12 @@ public class JPlagOptions {
    */
   private boolean storePercent = false;
 
+  /**
+   * Percentage value (must be between 0 and 100). Matches with a similarity below this threshold
+   * will be ignored. The default value of 0 allows all matches to be stored.
+   */
+  private float similarityThreshold = 0;
+
   /**
    * Tune the sensitivity of the comparison. A smaller <n> increases the sensitivity
    */
@@ -185,6 +191,10 @@ public class JPlagOptions {
     return numberOfSubmissionsToCompareTo;
   }
 
+  public float getSimilarityThreshold() {
+    return similarityThreshold;
+  }
+
   public void setNumberOfSubmissionsToCompareTo(int numberOfSubmissionsToCompareTo) {
     this.numberOfSubmissionsToCompareTo = numberOfSubmissionsToCompareTo;
   }
@@ -240,4 +250,14 @@ public class JPlagOptions {
   public void setVerbosity(Verbosity verbosity) {
     this.verbosity = verbosity;
   }
+
+  public void setSimilarityThreshold(float similarityThreshold) {
+    if (similarityThreshold > 100) {
+      this.similarityThreshold = 100;
+    } else if (similarityThreshold < 0) {
+      this.similarityThreshold = 0;
+    } else {
+      this.similarityThreshold = similarityThreshold;
+    }
+  }
 }

+ 4 - 2
jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java

@@ -63,8 +63,10 @@ public class NormalComparisonStrategy extends AbstractComparisonStrategy {
           comparison.bcMatchesB = baseCodeMatches.get(comparison.subB.name);
         }
 
-        comparisons.add(comparison);
-
+        if (comparison.percent() >= this.options.getSimilarityThreshold()) {
+          comparisons.add(comparison);
+        }
+        
         // Previously:
         // registerMatch(comparison, avgMatches, maxMatches, null, i, j);
       }