Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match merging: Use default values for CLI #1563

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.jplag.clustering.ClusteringOptions;
import de.jplag.clustering.algorithm.InterClusterSimilarity;
import de.jplag.java.JavaLanguage;
import de.jplag.merging.MergingOptions;
import de.jplag.options.JPlagOptions;
import de.jplag.options.SimilarityMetric;

Expand Down Expand Up @@ -116,14 +117,15 @@ public static class ClusteringEnabled {
}

public static class Merging {
@Option(names = {"--match-merging"}, description = "Enables match merging (default: false)%n")
public boolean enabled;
@Option(names = {"--match-merging"}, description = "Enables match merging (default: ${DEFAULT-VALUE})%n")
public boolean enabled = MergingOptions.DEFAULT_ENABLED;

@Option(names = {"--neighbor-length"}, description = "Defines how short a match can be, to be considered (default: 2)%n")
public int minimumNeighborLength;
@Option(names = {"--neighbor-length"}, description = "Defines how short a match can be, to be considered (default: ${DEFAULT-VALUE})%n")
public int minimumNeighborLength = MergingOptions.DEFAULT_NEIGHBOR_LENGTH;

@Option(names = {"--gap-size"}, description = "Defines how many token there can be between two neighboring matches (default: 6)%n")
public int maximumGapSize;
@Option(names = {
"--gap-size"}, description = "Defines how many token there can be between two neighboring matches (default: ${DEFAULT-VALUE})%n")
public int maximumGapSize = MergingOptions.DEFAULT_GAP_SIZE;

}

Expand Down
19 changes: 19 additions & 0 deletions cli/src/test/java/de/jplag/cli/MergingOptionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;

import de.jplag.merging.MergingOptions;

public class MergingOptionsTest extends CommandLineInterfaceTest {
uuqjz marked this conversation as resolved.
Show resolved Hide resolved
@Test
uuqjz marked this conversation as resolved.
Show resolved Hide resolved
void testMergingDefault() throws CliException {
buildOptionsFromCLI(defaultArguments());
assertNotNull(options.mergingOptions());
assertEquals(options.mergingOptions().enabled(), MergingOptions.DEFAULT_ENABLED);
assertEquals(options.mergingOptions().minimumNeighborLength(), MergingOptions.DEFAULT_NEIGHBOR_LENGTH);
assertEquals(options.mergingOptions().maximumGapSize(), MergingOptions.DEFAULT_GAP_SIZE);
}
}
6 changes: 5 additions & 1 deletion core/src/main/java/de/jplag/merging/MergingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
public record MergingOptions(@JsonProperty("enabled") boolean enabled, @JsonProperty("min_neighbour_length") int minimumNeighborLength,
@JsonProperty("max_gap_size") int maximumGapSize) {

public static final boolean DEFAULT_ENABLED = false;
public static final int DEFAULT_NEIGHBOR_LENGTH = 2;
public static final int DEFAULT_GAP_SIZE = 6;

/**
* The default values of MergingOptions are false for the enable-switch, which deactivate MatchMerging, while
* minimumNeighborLength and maximumGapSize default to (2,6), which in testing yielded the best results.
*/
public MergingOptions() {
this(false, 2, 6);
this(DEFAULT_ENABLED, DEFAULT_NEIGHBOR_LENGTH, DEFAULT_GAP_SIZE);
}

/**
Expand Down
Loading