From 0692c4fa4550fc0639a598db682e90872b151124 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Fri, 4 Aug 2023 11:41:12 +0200 Subject: [PATCH] Timur changes I --- .../main/java/de/jplag/cli/CliOptions.java | 2 +- core/src/main/java/de/jplag/Submission.java | 2 +- .../java/de/jplag/merging/MatchMerging.java | 22 ++++++++----------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index b02dcd484..4957e30e2 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -59,7 +59,7 @@ public class CliOptions implements Runnable { @ArgGroup(validate = false, heading = "Clustering%n") public Clustering clustering = new Clustering(); - @ArgGroup(validate = false, heading = "Match Merging%nDefense mechanism against obfuscation that merges neighboring matches based on these parameters:\n") + @ArgGroup(validate = false, heading = "Match Merging defense mechanism against obfuscation that merges neighboring matches based on these parameters:%n") public Merging merging = new Merging(); /** diff --git a/core/src/main/java/de/jplag/Submission.java b/core/src/main/java/de/jplag/Submission.java index 5bbdfc9fc..f47db6d60 100644 --- a/core/src/main/java/de/jplag/Submission.java +++ b/core/src/main/java/de/jplag/Submission.java @@ -296,7 +296,7 @@ private List getOrder(List tokenList) { } /** - * @return Submission containing a deep copy of the tokenList and shallow copies of the remaining fields. + * @return Submission containing shallow copies of its fields. */ public Submission copy() { Submission copy = new Submission(name, submissionRootFile, isNew, files, language); diff --git a/core/src/main/java/de/jplag/merging/MatchMerging.java b/core/src/main/java/de/jplag/merging/MatchMerging.java index 4c422f7bc..c8756e9ea 100644 --- a/core/src/main/java/de/jplag/merging/MatchMerging.java +++ b/core/src/main/java/de/jplag/merging/MatchMerging.java @@ -13,26 +13,24 @@ import de.jplag.options.JPlagOptions; /** - * This class implements match merging against obfuscation. Based on configurable parameters MergeBuffer and - * SeperatingThreshold, it alters prior results and merges all neighboring matches that fit the specified thresholds. - * When neighboring matches get merged they become one and the tokens separating them get removed from the submission - * clone. MergeBuffer describes how shorter a match can be than the Minimum Token Match. SeperatingThreshold describes - * how many tokens can be between two neighboring matches. Both are set in {@link JPlagOptions} as - * {@link MergingParameters} and default to 0 (which deactivates merging). + * This class implements a match merging algorithm which serves as defense mechanism against obfuscation attacks. Based + * on configurable parameters MergeBuffer and SeperatingThreshold, it alters prior results and merges all neighboring + * matches that fit the specified thresholds. When neighboring matches get merged they become one and the tokens + * separating them get removed from the submission clone. MergeBuffer describes how shorter a match can be than the + * Minimum Token Match. SeperatingThreshold describes how many tokens can be between two neighboring matches. Both are + * set in {@link JPlagOptions} as {@link MergingParameters} and default to 0 (which deactivates merging). */ public class MatchMerging { - private int minimumTokenMatch; private Submission firstSubmission; private Submission secondSubmission; private List globalMatches; private List> neighbors; - private int seperatingThreshold; private JPlagResult result; private List comparisons; private JPlagOptions options; /** - * Constructor for class MatchMerging + * Instantiates the match merging algorithm for a comparison result and a set of specific options. * @param result is the initially computed result object * @param options encapsulates the adjustable options */ @@ -40,8 +38,6 @@ public MatchMerging(JPlagResult result, JPlagOptions options) { this.result = result; this.comparisons = new ArrayList<>(result.getAllComparisons()); this.options = options; - this.minimumTokenMatch = options.minimumTokenMatch(); - this.seperatingThreshold = options.mergingParameters().seperatingThreshold(); } /** @@ -88,7 +84,7 @@ private void mergeNeighbors() { int seperatingSecond = neighbors.get(i).get(1).startOfSecond() - neighbors.get(i).get(0).endOfSecond() - 1; double seperating = (seperatingFirst + seperatingSecond) / 2.0; // Checking length is not necessary as GST already checked length while computing matches - if (seperating <= seperatingThreshold) { + if (seperating <= options.mergingParameters().seperatingThreshold()) { globalMatches.removeAll(neighbors.get(i)); globalMatches .add(new Match(neighbors.get(i).get(0).startOfFirst(), neighbors.get(i).get(0).startOfSecond(), lengthUpper + lengthLower)); @@ -127,7 +123,7 @@ private void removeToken(int startFirst, int startSecond, int lengthUpper, int s private void removeBuffer() { List toRemove = new ArrayList<>(); for (Match match : globalMatches) { - if (match.length() < minimumTokenMatch) { + if (match.length() < options.minimumTokenMatch()) { toRemove.add(match); } }