Skip to content

Commit

Permalink
Timur changes I
Browse files Browse the repository at this point in the history
  • Loading branch information
uuqjz committed Aug 4, 2023
1 parent ec3f506 commit 0692c4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/de/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private List<Integer> getOrder(List<Token> 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);
Expand Down
22 changes: 9 additions & 13 deletions core/src/main/java/de/jplag/merging/MatchMerging.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,31 @@
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<Match> globalMatches;
private List<List<Match>> neighbors;
private int seperatingThreshold;
private JPlagResult result;
private List<JPlagComparison> 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
*/
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();
}

/**
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -127,7 +123,7 @@ private void removeToken(int startFirst, int startSecond, int lengthUpper, int s
private void removeBuffer() {
List<Match> toRemove = new ArrayList<>();
for (Match match : globalMatches) {
if (match.length() < minimumTokenMatch) {
if (match.length() < options.minimumTokenMatch()) {
toRemove.add(match);
}
}
Expand Down

0 comments on commit 0692c4f

Please sign in to comment.