Skip to content

Commit 0f2a6c9

Browse files
authored
Merge pull request #1563 from jplag/bug-fix/default-values-mm
Match merging: Use default values for CLI
2 parents a5705bb + 38e4c20 commit 0f2a6c9

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

cli/src/main/java/de/jplag/cli/CliOptions.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.jplag.clustering.ClusteringOptions;
88
import de.jplag.clustering.algorithm.InterClusterSimilarity;
99
import de.jplag.java.JavaLanguage;
10+
import de.jplag.merging.MergingOptions;
1011
import de.jplag.options.JPlagOptions;
1112
import de.jplag.options.SimilarityMetric;
1213

@@ -116,14 +117,15 @@ public static class ClusteringEnabled {
116117
}
117118

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

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

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

128130
}
129131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.jplag.cli;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
import de.jplag.merging.MergingOptions;
10+
11+
/**
12+
* Test cases for the options of the match merging mechanism.
13+
*/
14+
class MergingOptionsTest extends CommandLineInterfaceTest {
15+
16+
@Test
17+
@DisplayName("Test if default values are used when creating merging options from CLI")
18+
void testMergingDefault() throws CliException {
19+
buildOptionsFromCLI(defaultArguments());
20+
assertNotNull(options.mergingOptions());
21+
assertEquals(MergingOptions.DEFAULT_ENABLED, options.mergingOptions().enabled());
22+
assertEquals(MergingOptions.DEFAULT_NEIGHBOR_LENGTH, options.mergingOptions().minimumNeighborLength());
23+
assertEquals(MergingOptions.DEFAULT_GAP_SIZE, options.mergingOptions().maximumGapSize());
24+
}
25+
}

core/src/main/java/de/jplag/merging/MergingOptions.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
public record MergingOptions(@JsonProperty("enabled") boolean enabled, @JsonProperty("min_neighbour_length") int minimumNeighborLength,
1111
@JsonProperty("max_gap_size") int maximumGapSize) {
1212

13+
public static final boolean DEFAULT_ENABLED = false;
14+
public static final int DEFAULT_NEIGHBOR_LENGTH = 2;
15+
public static final int DEFAULT_GAP_SIZE = 6;
16+
1317
/**
1418
* The default values of MergingOptions are false for the enable-switch, which deactivate MatchMerging, while
1519
* minimumNeighborLength and maximumGapSize default to (2,6), which in testing yielded the best results.
1620
*/
1721
public MergingOptions() {
18-
this(false, 2, 6);
22+
this(DEFAULT_ENABLED, DEFAULT_NEIGHBOR_LENGTH, DEFAULT_GAP_SIZE);
1923
}
2024

2125
/**

0 commit comments

Comments
 (0)