فهرست منبع

Fix obvious CLI bugs in arguments -s, -t, and -bc.

Sebastian Hahner 5 سال پیش
والد
کامیت
72c7651dba
1فایلهای تغییر یافته به همراه30 افزوده شده و 8 حذف شده
  1. 30 8
      jplag/src/main/java/jplag/CLI.java

+ 30 - 8
jplag/src/main/java/jplag/CLI.java

@@ -15,20 +15,22 @@ import net.sourceforge.argparse4j.inf.Namespace;
 
 /**
  * Command line interface class, allows using via command line.
+ *
  * @see CLI#main(String[])
  */
 public class CLI {
-    
+
     private static final String DESCRIPTION = "JPlag - Detecting Software Plagiarism";
     private static final String PROGRAM_NAME = "jplag";
     private static final String[] verbosityOptions = {"parser", "quiet", "long", "details"};
-    private static final String[] languageOptions = new String[] {"java_1_1", "java_1_2", "java_1_5", "java_1_5_dm", "java_1_7", "java_1_9",
+    private static final String[] languageOptions = new String[]{"java_1_1", "java_1_2", "java_1_5", "java_1_5_dm", "java_1_7", "java_1_9",
             "python_3", "c_cpp", "c_sharp", "char", "text", "scheme"};
-    
+
     private final ArgumentParser parser;
 
     /**
      * Main class for using JPlag via the CLI.
+     *
      * @param args are the CLI arguments that will be passed to JPlag.
      */
     public static void main(String[] args) {
@@ -62,12 +64,13 @@ public class CLI {
         parser.addArgument("-p").help("comma-separated list of all filename suffixes that are included");
         parser.addArgument("-x").help("All files named in <file> will be ignored");
         parser.addArgument("-t").help("Tune the sensitivity of the comparison. A smaller <n> increases the sensitivity");
-        parser.addArgument("-s").help("Similarity Threshold: all matches above this threshold will be saved");
+        parser.addArgument("-s").setDefault(0f).help("Similarity Threshold [0-100]: all matches above this threshold will be saved");
         parser.addArgument("-r").setDefault("result").help("Name of directory in which the web pages will be stored");
     }
 
     /**
      * Parses an array of argument strings.
+     *
      * @param args is the array to parse.
      * @return the parsed arguments in a {@link Namespace} format.
      */
@@ -83,12 +86,13 @@ public class CLI {
 
     /**
      * Builds a options instance from parsed arguments.
+     *
      * @param namespace encapsulates the parsed arguments in a {@link Namespace} format.
      * @return the newly built options.F
      */
     public JPlagOptions buildOptionsFromArguments(Namespace namespace) {
         String fileSuffixString = namespace.getString("p");
-        String[] fileSuffixes = new String[] {};
+        String[] fileSuffixes = new String[]{};
         if (fileSuffixString != null) {
             fileSuffixes = fileSuffixString.replaceAll("\\s+", "").split(",");
         }
@@ -96,14 +100,32 @@ public class CLI {
         Verbosity verbosity = Verbosity.fromOption(namespace.getString("v"));
 
         JPlagOptions options = new JPlagOptions(namespace.getString("rootDir"), language);
-        options.setBaseCodeSubmissionName("base-code");
+        options.setBaseCodeSubmissionName(namespace.getString("bc"));
         options.setVerbosity(verbosity);
         options.setDebugParser(namespace.getBoolean("d"));
         options.setSubdirectoryName(namespace.getString("S"));
         options.setFileSuffixes(fileSuffixes);
         options.setExclusionFileName(namespace.getString("x"));
-        options.setMinTokenMatch(namespace.getInt("t"));
-        options.setSimilarityThreshold(namespace.getFloat("s"));
+
+        String minTokenMatch = namespace.getString("t");
+        if (minTokenMatch != null) {
+            try {
+                options.setMinTokenMatch(Integer.parseInt(minTokenMatch));
+            } catch (NumberFormatException e) {
+                System.out.println("Illegal comparison sensitivity. Ignoring input and taking language default value.");
+            }
+        }
+
+        String similarityThreshold = namespace.getString("s");
+        if (similarityThreshold != null) {
+            try {
+                options.setSimilarityThreshold(Float.parseFloat(similarityThreshold));
+            } catch (NumberFormatException e) {
+                System.out.println("Illegal similarity threshold. Taking 0 as default value.");
+                options.setSimilarityThreshold(0);
+            }
+        }
+
         return options;
     }
 }