Browse Source

Use consistent naming for the minimum token match throughout the projects.

Timur Sağlam 5 years ago
parent
commit
c9a1755e0c

+ 2 - 2
jplag/src/main/java/de/jplag/CLI.java

@@ -108,9 +108,9 @@ public class CLI {
         options.setSubdirectoryName(SUBDIRECTORY.getFrom(namespace));
         options.setFileSuffixes(fileSuffixes);
         options.setExclusionFileName(EXCLUDE_FILE.getFrom(namespace));
-        options.setMinTokenMatch(MIN_TOKEN_MATCH.getFrom(namespace));
+        options.setMinimumTokenMatch(MIN_TOKEN_MATCH.getFrom(namespace));
         options.setSimilarityThreshold(SIMILARITY_THRESHOLD.getFrom(namespace));
-        options.setMaxNumberOfMatches(STORED_MATCHES.getFrom(namespace));
+        options.setMaximumNumberOfMatches(STORED_MATCHES.getFrom(namespace));
         ComparisonMode.fromName(COMPARISON_MODE.getFrom(namespace)).ifPresentOrElse(it -> options.setComparisonMode(it),
                 () -> System.out.println("Unknown comparison mode, using default mode!"));
         return options;

+ 15 - 15
jplag/src/main/java/de/jplag/GreedyStringTiling.java

@@ -124,9 +124,9 @@ public class GreedyStringTiling implements TokenConstants {
 
         // Initialize:
         JPlagComparison comparison = new JPlagComparison(firstSubmission, secondSubmission);
-        int minimalTokenMatch = program.getOptions().getMinTokenMatch(); // minimal required token match
+        int minimumTokenMatch = program.getOptions().getMinimumTokenMatch(); // minimal required token match
 
-        if (first.size() <= minimalTokenMatch || second.size() <= minimalTokenMatch) { // <= because of pivots!
+        if (first.size() <= minimumTokenMatch || second.size() <= minimumTokenMatch) { // <= because of pivots!
             return comparison;
         }
 
@@ -134,32 +134,32 @@ public class GreedyStringTiling implements TokenConstants {
         markTokens(second, withBaseCode);
 
         // create hashes:
-        if (first.hash_length != minimalTokenMatch) {
-            createHashes(first, minimalTokenMatch, withBaseCode); // don't make table if it is not a base code comparison
+        if (first.hash_length != minimumTokenMatch) {
+            createHashes(first, minimumTokenMatch, withBaseCode); // don't make table if it is not a base code comparison
         }
-        if (second.hash_length != minimalTokenMatch || second.tokenHashes == null) {
-            createHashes(second, minimalTokenMatch, true);
+        if (second.hash_length != minimumTokenMatch || second.tokenHashes == null) {
+            createHashes(second, minimumTokenMatch, true);
         }
 
         List<Match> matches = new ArrayList<>();
 
         // start the black magic:
-        int maxmatch;
+        int maxMatch;
         do {
-            maxmatch = minimalTokenMatch;
+            maxMatch = minimumTokenMatch;
             matches.clear();
-            for (int x = 0; x < first.size() - maxmatch; x++) {
+            for (int x = 0; x < first.size() - maxMatch; x++) {
                 List<Integer> hashedTokens = second.tokenHashes.get(first.getToken(x).hash);
                 if (first.getToken(x).marked || first.getToken(x).hash == -1) {
                     continue;
                 }
                 inner: for (Integer y : hashedTokens) {
-                    if (second.getToken(y).marked || maxmatch >= second.size() - y) { // >= because of pivots!
+                    if (second.getToken(y).marked || maxMatch >= second.size() - y) { // >= because of pivots!
                         continue;
                     }
 
                     int j, hx, hy;
-                    for (j = maxmatch - 1; j >= 0; j--) { // begins comparison from behind
+                    for (j = maxMatch - 1; j >= 0; j--) { // begins comparison from behind
                         if (first.getToken(hx = x + j).type != second.getToken(hy = y + j).type || first.getToken(hx).marked
                                 || second.getToken(hy).marked) {
                             continue inner;
@@ -167,15 +167,15 @@ public class GreedyStringTiling implements TokenConstants {
                     }
 
                     // expand match
-                    j = maxmatch;
+                    j = maxMatch;
                     while (first.getToken(hx = x + j).type == second.getToken(hy = y + j).type && !first.getToken(hx).marked
                             && !second.getToken(hy).marked) {
                         j++;
                     }
 
-                    if (j > maxmatch && !withBaseCode || j != maxmatch && withBaseCode) {  // new biggest match? -> delete current smaller
+                    if (j > maxMatch && !withBaseCode || j != maxMatch && withBaseCode) {  // new biggest match? -> delete current smaller
                         matches.clear();
-                        maxmatch = j;
+                        maxMatch = j;
                     }
                     addMatchIfNotOverlapping(matches, x, y, j);
                 }
@@ -195,7 +195,7 @@ public class GreedyStringTiling implements TokenConstants {
                 }
             }
 
-        } while (maxmatch != minimalTokenMatch);
+        } while (maxMatch != minimumTokenMatch);
 
         return comparison;
     }

+ 9 - 9
jplag/src/main/java/de/jplag/JPlag.java

@@ -61,12 +61,12 @@ public class JPlag implements Program {
      */
     public JPlagResult run() throws ExitException {
         // 1. Preparation:
-        File rootDir = new File(options.getRootDirName());
+        File rootDir = new File(options.getRootDirectoryName());
         if (!rootDir.exists()) {
-            throw new ExitException("Root directory " + options.getRootDirName() + " does not exist!");
+            throw new ExitException("Root directory " + options.getRootDirectoryName() + " does not exist!");
         }
         if (!rootDir.isDirectory()) {
-            throw new ExitException(options.getRootDirName() + " is not a directory!");
+            throw new ExitException(options.getRootDirectoryName() + " is not a directory!");
         }
         readExclusionFile(); // This file contains all files names which are excluded
 
@@ -153,10 +153,10 @@ public class JPlag implements Program {
             return;
         }
 
-        String baseCodePath = this.options.getRootDirName() + File.separator + this.options.getBaseCodeSubmissionName();
+        String baseCodePath = this.options.getRootDirectoryName() + File.separator + this.options.getBaseCodeSubmissionName();
 
-        if (!(new File(this.options.getRootDirName())).exists()) {
-            throw new ExitException("Root directory \"" + this.options.getRootDirName() + "\" doesn't exist!", ExitException.BAD_PARAMETER);
+        if (!(new File(this.options.getRootDirectoryName())).exists()) {
+            throw new ExitException("Root directory \"" + this.options.getRootDirectoryName() + "\" doesn't exist!", ExitException.BAD_PARAMETER);
         }
 
         File f = new File(baseCodePath);
@@ -316,12 +316,12 @@ public class JPlag implements Program {
             throw new ExitException("Bad basecode submission");
         }
 
-        if (subm.getTokenList() != null && subm.getNumberOfTokens() < options.getMinTokenMatch()) {
+        if (subm.getTokenList() != null && subm.getNumberOfTokens() < options.getMinimumTokenMatch()) {
             throw new ExitException("Basecode submission contains fewer tokens " + "than minimum match length allows!\n");
         }
 
         if (options.hasBaseCode()) {
-            gSTiling.createHashes(subm.getTokenList(), options.getMinTokenMatch(), true);
+            gSTiling.createHashes(subm.getTokenList(), options.getMinimumTokenMatch(), true);
         }
 
         print("\nBasecode submission parsed!\n", null);
@@ -361,7 +361,7 @@ public class JPlag implements Program {
 
             count++;
 
-            if (subm.getTokenList() != null && subm.getNumberOfTokens() < options.getMinTokenMatch()) {
+            if (subm.getTokenList() != null && subm.getNumberOfTokens() < options.getMinimumTokenMatch()) {
                 print(null, "Submission contains fewer tokens than minimum match " + "length allows!\n");
                 subm.setTokenList(null);
                 invalid++;

+ 2 - 2
jplag/src/main/java/de/jplag/JPlagResult.java

@@ -77,10 +77,10 @@ public class JPlagResult {
      * settings set in JPlagOptions
      */
     public List<JPlagComparison> getComparisons() {
-        if (this.options.getMaxNumberOfMatches() == -1) {
+        if (this.options.getMaximumNumberOfMatches() == -1) {
             return this.getAllComparisons();
         } else {
-            return this.getComparisons(this.options.getMaxNumberOfMatches());
+            return this.getComparisons(this.options.getMaximumNumberOfMatches());
         }
     }
 

+ 25 - 25
jplag/src/main/java/de/jplag/options/JPlagOptions.java

@@ -46,7 +46,7 @@ public class JPlagOptions {
      * The maximum number of matches that will be saved. This does affect the generated report as well as the internally
      * saved comparisons. If set to -1 all matches will be saved.
      */
-    private int maxNumberOfMatches = DEFAULT_STORED_MATCHES;
+    private int maximumNumberOfMatches = DEFAULT_STORED_MATCHES;
 
     /**
      * TODO PB: Not happy with the name yet.
@@ -56,7 +56,7 @@ public class JPlagOptions {
     /**
      * Tune the sensitivity of the comparison. A smaller <n> increases the sensitivity
      */
-    private Integer minTokenMatch;
+    private Integer minimumTokenMatch;
 
     /**
      * Name of the file that contains the names of files to exclude from comparison.
@@ -66,7 +66,7 @@ public class JPlagOptions {
     /**
      * Directory that contains all submissions.
      */
-    private String rootDirName;
+    private String rootDirectoryName;
 
     /**
      * Name of the directory which contains the base code.
@@ -92,8 +92,8 @@ public class JPlagOptions {
     /**
      * Constructor with required attributes.
      */
-    public JPlagOptions(String rootDirName, LanguageOption languageOption) {
-        this.rootDirName = rootDirName;
+    public JPlagOptions(String rootDirectoryName, LanguageOption languageOption) {
+        this.rootDirectoryName = rootDirectoryName;
         this.languageOption = languageOption;
     }
 
@@ -103,8 +103,8 @@ public class JPlagOptions {
      * @param language - initialized language instance
      */
     public void setLanguageDefaults(Language language) {
-        if (!hasMinTokenMatch()) {
-            setMinTokenMatch(language.minimumTokenMatch());
+        if (!hasMinimumTokenMatch()) {
+            setMinimumTokenMatch(language.minimumTokenMatch());
         }
 
         if (!hasFileSuffixes()) {
@@ -128,8 +128,8 @@ public class JPlagOptions {
         return fileSuffixes != null && fileSuffixes.length > 0;
     }
 
-    private boolean hasMinTokenMatch() {
-        return minTokenMatch != null;
+    private boolean hasMinimumTokenMatch() {
+        return minimumTokenMatch != null;
     }
 
     public ComparisonMode getComparisonMode() {
@@ -144,16 +144,16 @@ public class JPlagOptions {
         return language;
     }
 
-    public Integer getMinTokenMatch() {
-        return minTokenMatch;
+    public Integer getMinimumTokenMatch() {
+        return minimumTokenMatch;
     }
 
     public String getExclusionFileName() {
         return exclusionFileName;
     }
 
-    public String getRootDirName() {
-        return rootDirName;
+    public String getRootDirectoryName() {
+        return rootDirectoryName;
     }
 
     public String getBaseCodeSubmissionName() {
@@ -172,8 +172,8 @@ public class JPlagOptions {
         return similarityThreshold;
     }
 
-    public int getMaxNumberOfMatches() {
-        return this.maxNumberOfMatches;
+    public int getMaximumNumberOfMatches() {
+        return this.maximumNumberOfMatches;
     }
 
     public SimilarityMetric getSimilarityMetric() {
@@ -196,11 +196,11 @@ public class JPlagOptions {
         this.fileSuffixes = fileSuffixes;
     }
 
-    public void setMinTokenMatch(Integer minTokenMatch) {
-        if (minTokenMatch != null && minTokenMatch < 1) {
-            this.minTokenMatch = 1;
+    public void setMinimumTokenMatch(Integer minimumTokenMatch) {
+        if (minimumTokenMatch != null && minimumTokenMatch < 1) {
+            this.minimumTokenMatch = 1;
         } else {
-            this.minTokenMatch = minTokenMatch;
+            this.minimumTokenMatch = minimumTokenMatch;
         }
     }
 
@@ -208,8 +208,8 @@ public class JPlagOptions {
         this.exclusionFileName = exclusionFileName;
     }
 
-    public void setRootDirName(String rootDirName) {
-        this.rootDirName = rootDirName;
+    public void setRootDirectoryName(String rootDirectoryName) {
+        this.rootDirectoryName = rootDirectoryName;
     }
 
     public void setBaseCodeSubmissionName(String baseCodeSubmissionName) {
@@ -240,11 +240,11 @@ public class JPlagOptions {
         }
     }
 
-    public void setMaxNumberOfMatches(int maxNumberOfMatches) {
-        if (maxNumberOfMatches < -1) {
-            this.maxNumberOfMatches = -1;
+    public void setMaximumNumberOfMatches(int maximumNumberOfMatches) {
+        if (maximumNumberOfMatches < -1) {
+            this.maximumNumberOfMatches = -1;
         } else {
-            this.maxNumberOfMatches = maxNumberOfMatches;
+            this.maximumNumberOfMatches = maximumNumberOfMatches;
         }
     }
 

+ 1 - 1
jplag/src/main/java/de/jplag/reporting/Report.java

@@ -458,7 +458,7 @@ public class Report { // Mostly legacy code with some minor improvements.
         htmlFile.println(
                 "<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Date") + ":</TD><TD>" + dateFormat.format(new Date()) + "</TD></TR>");
         htmlFile.println("<TR BGCOLOR=#aaaaff>" + "<TD><EM>" + msg.getString("Report.Minimum_Match_Length") + "</EM> ("
-                + msg.getString("Report.sensitivity") + "):</TD><TD>" + result.getOptions().getMinTokenMatch() + "</TD></TR>");
+                + msg.getString("Report.sensitivity") + "):</TD><TD>" + result.getOptions().getMinimumTokenMatch() + "</TD></TR>");
         htmlFile.println("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Suffixes") + ":</TD><TD>");
 
         String[] fileSuffixes = result.getOptions().getFileSuffixes();

+ 1 - 1
jplag/src/test/java/de/jplag/VolumeTest.java

@@ -44,7 +44,7 @@ public class VolumeTest extends TestBase {
         }
 
         var results = runJPlag("data",
-                jPlagOptions -> jPlagOptions.setMaxNumberOfMatches(-1));
+                jPlagOptions -> jPlagOptions.setMaximumNumberOfMatches(-1));
 
         var csv = readCSVResults(String.format("%s/%s", this.getBasePath(), "matches_avg.csv"));
 

+ 4 - 4
jplag/src/test/java/de/jplag/cli/MinTokenMatchTest.java

@@ -22,7 +22,7 @@ public class MinTokenMatchTest extends CommandLineInterfaceTest {
     public void testLanguageDefault() {
         // Language defaults not set yet:
         buildOptionsFromCLI(CURRENT_DIRECTORY);
-        assertNull(options.getMinTokenMatch());
+        assertNull(options.getMinimumTokenMatch());
         assertNull(options.getLanguage());
 
         // Init JPlag:
@@ -35,7 +35,7 @@ public class MinTokenMatchTest extends CommandLineInterfaceTest {
 
         // Now the language is set:
         assertNotNull(options.getLanguage());
-        assertEquals(options.getLanguage().minimumTokenMatch(), options.getMinTokenMatch().intValue());
+        assertEquals(options.getLanguage().minimumTokenMatch(), options.getMinimumTokenMatch().intValue());
     }
 
     @Test
@@ -56,7 +56,7 @@ public class MinTokenMatchTest extends CommandLineInterfaceTest {
     public void testLowerBound() {
         String argument = buildArgument(CommandLineArgument.MIN_TOKEN_MATCH, Integer.toString(-1));
         buildOptionsFromCLI(argument, CURRENT_DIRECTORY);
-        assertEquals(1, options.getMinTokenMatch().intValue());
+        assertEquals(1, options.getMinimumTokenMatch().intValue());
     }
 
     @Test
@@ -64,6 +64,6 @@ public class MinTokenMatchTest extends CommandLineInterfaceTest {
         int expectedValue = 50;
         String argument = buildArgument(CommandLineArgument.MIN_TOKEN_MATCH, Integer.toString(expectedValue));
         buildOptionsFromCLI(argument, CURRENT_DIRECTORY);
-        assertEquals(expectedValue, options.getMinTokenMatch().intValue());
+        assertEquals(expectedValue, options.getMinimumTokenMatch().intValue());
     }
 }

+ 4 - 4
jplag/src/test/java/de/jplag/cli/StoredMatchesTest.java

@@ -17,7 +17,7 @@ public class StoredMatchesTest extends CommandLineInterfaceTest {
     @Test
     public void testDefault() {
         buildOptionsFromCLI(CURRENT_DIRECTORY);
-        assertEquals(JPlagOptions.DEFAULT_STORED_MATCHES, options.getMaxNumberOfMatches());
+        assertEquals(JPlagOptions.DEFAULT_STORED_MATCHES, options.getMaximumNumberOfMatches());
     }
 
     @Test
@@ -25,7 +25,7 @@ public class StoredMatchesTest extends CommandLineInterfaceTest {
         int expectedValue = 999;
         String argument = buildArgument(CommandLineArgument.STORED_MATCHES, Integer.toString(expectedValue));
         buildOptionsFromCLI(argument, CURRENT_DIRECTORY);
-        assertEquals(expectedValue, options.getMaxNumberOfMatches());
+        assertEquals(expectedValue, options.getMaximumNumberOfMatches());
     }
 
     @Test
@@ -33,14 +33,14 @@ public class StoredMatchesTest extends CommandLineInterfaceTest {
         int expectedValue = -1;
         String argument = buildArgument(CommandLineArgument.STORED_MATCHES, Integer.toString(expectedValue));
         buildOptionsFromCLI(argument, CURRENT_DIRECTORY);
-        assertEquals(expectedValue, options.getMaxNumberOfMatches());
+        assertEquals(expectedValue, options.getMaximumNumberOfMatches());
     }
 
     @Test
     public void testLowerBound() {
         String argument = buildArgument(CommandLineArgument.STORED_MATCHES, Integer.toString(-2));
         buildOptionsFromCLI(argument, CURRENT_DIRECTORY);
-        assertEquals(-1, options.getMaxNumberOfMatches());
+        assertEquals(-1, options.getMaximumNumberOfMatches());
     }
 
     @Test