Skip to content

Commit

Permalink
Added CLI toggle for Match Merging
Browse files Browse the repository at this point in the history
  • Loading branch information
uuqjz committed Aug 5, 2023
1 parent 2b341e0 commit c513eca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private static ClusteringOptions getClusteringOptions(CliOptions options) {
}

private static MergingParameters getMergingParameters(CliOptions options) {
return new MergingParameters().withMergeBuffer(options.merging.mergeBuffer).withSeperatingThreshold(options.merging.seperatingThreshold);
return new MergingParameters().withEnable(options.merging.enable).withMergeBuffer(options.merging.mergeBuffer)
.withSeperatingThreshold(options.merging.seperatingThreshold);
}

private String generateDescription() {
Expand Down
7 changes: 5 additions & 2 deletions cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ public static class ClusteringEnabled {
}

public static class Merging {
@Option(names = {"--match-merging"}, description = "Enables match merging (default: false)%n")
public boolean enable;

@Option(names = {
"--merge-buffer"}, description = "Defines how much lower the length of a match can be than the minimum match length (default: 0)\n")
"--merge-buffer"}, description = "Defines how much lower the length of a match can be than the minimum match length (default: 0)%n")
public int mergeBuffer;

@Option(names = {
"--seperating-threshold"}, description = "Defines how many token there can be between two neighboring matches (default: 0)\n")
"--seperating-threshold"}, description = "Defines how many token there can be between two neighboring matches (default: 0)%n")
public int seperatingThreshold;

}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/de/jplag/JPlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static JPlagResult run(JPlagOptions options) throws ExitException {
JPlagResult result = comparisonStrategy.compareSubmissions(submissionSet);

// Use Match Merging against obfuscation
result = new MatchMerging(result, options).run();
if (options.mergingParameters().enable()) {
result = new MatchMerging(result, options).run();
}

if (logger.isInfoEnabled())
logger.info("Total time for comparing submissions: {}", TimeUtil.formatDuration(result.getDuration()));
Expand Down
12 changes: 8 additions & 4 deletions core/src/main/java/de/jplag/merging/MergingParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
* @param mergeBuffer describes how shorter a match can be than the Minimum Token Match (Defaults to 0).
* @param seperatingThreshold describes how many tokens can be between to neighboring matches (Defaults to 0).
*/
public record MergingParameters(int mergeBuffer, int seperatingThreshold) {
public record MergingParameters(boolean enable, int mergeBuffer, int seperatingThreshold) {

public MergingParameters() {
this(0, 0);
this(false, 0, 0);
}

public MergingParameters withEnable(boolean enable) {
return new MergingParameters(enable, mergeBuffer, seperatingThreshold);
}

public MergingParameters withMergeBuffer(int mergeBuffer) {
return new MergingParameters(mergeBuffer, seperatingThreshold);
return new MergingParameters(enable, mergeBuffer, seperatingThreshold);
}

public MergingParameters withSeperatingThreshold(int seperatingThreshold) {
return new MergingParameters(mergeBuffer, seperatingThreshold);
return new MergingParameters(enable, mergeBuffer, seperatingThreshold);
}
}
4 changes: 2 additions & 2 deletions core/src/test/java/de/jplag/merging/MergingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* This class extends on {@link TestBase} and performs several test on Match Merging, in order to check its
* functionality. Therefore it uses two java programs and feds them into the JPlag pipeline. Results are stored before-
* and after Match Merging and used for all tests.
* and after Match Merging and used for all tests. The two samples are from PROGpedia and under the CC BY 4.0 license.
*/
class MergingTest extends TestBase {
private JPlagOptions options;
Expand All @@ -37,7 +37,7 @@ class MergingTest extends TestBase {
private final int SEPERATING_THRESHOLD = 2;

MergingTest() throws ExitException {
options = getDefaultOptions("merging").withMergingParameters(new MergingParameters(MERGE_BUFFER, SEPERATING_THRESHOLD));
options = getDefaultOptions("merging").withMergingParameters(new MergingParameters(true, MERGE_BUFFER, SEPERATING_THRESHOLD));

GreedyStringTiling coreAlgorithm = new GreedyStringTiling(options);
ComparisonStrategy comparisonStrategy = new ParallelComparisonStrategy(options, coreAlgorithm);
Expand Down

0 comments on commit c513eca

Please sign in to comment.