From c513eca9a367a6c90007888bcb614e73c7215a4a Mon Sep 17 00:00:00 2001 From: uuqjz Date: Sat, 5 Aug 2023 07:44:05 +0200 Subject: [PATCH] Added CLI toggle for Match Merging --- cli/src/main/java/de/jplag/cli/CLI.java | 3 ++- cli/src/main/java/de/jplag/cli/CliOptions.java | 7 +++++-- core/src/main/java/de/jplag/JPlag.java | 4 +++- .../java/de/jplag/merging/MergingParameters.java | 12 ++++++++---- core/src/test/java/de/jplag/merging/MergingTest.java | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/CLI.java b/cli/src/main/java/de/jplag/cli/CLI.java index dfa9965f9..bdcc2b284 100644 --- a/cli/src/main/java/de/jplag/cli/CLI.java +++ b/cli/src/main/java/de/jplag/cli/CLI.java @@ -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() { diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index 4957e30e2..02fd50ea2 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -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; } diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index a27cb93b3..d1d57885b 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -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())); diff --git a/core/src/main/java/de/jplag/merging/MergingParameters.java b/core/src/main/java/de/jplag/merging/MergingParameters.java index 7fdbd569b..fdf3565f7 100644 --- a/core/src/main/java/de/jplag/merging/MergingParameters.java +++ b/core/src/main/java/de/jplag/merging/MergingParameters.java @@ -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); } } diff --git a/core/src/test/java/de/jplag/merging/MergingTest.java b/core/src/test/java/de/jplag/merging/MergingTest.java index d16fcb568..886b3c662 100644 --- a/core/src/test/java/de/jplag/merging/MergingTest.java +++ b/core/src/test/java/de/jplag/merging/MergingTest.java @@ -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; @@ -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);