diff --git a/cli/src/main/java/de/jplag/cli/CLI.java b/cli/src/main/java/de/jplag/cli/CLI.java index a946f924c..e79fa4adb 100644 --- a/cli/src/main/java/de/jplag/cli/CLI.java +++ b/cli/src/main/java/de/jplag/cli/CLI.java @@ -1,41 +1,37 @@ package de.jplag.cli; -import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_DESCRIPTION_HEADING; -import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_OPTION_LIST; -import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_SYNOPSIS; - -import java.io.File; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.HashSet; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.stream.Collectors; - -import org.slf4j.ILoggerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import de.jplag.JPlag; import de.jplag.JPlagResult; import de.jplag.Language; import de.jplag.cli.logger.CollectedLoggerFactory; import de.jplag.clustering.ClusteringOptions; import de.jplag.clustering.Preprocessing; -import de.jplag.csv.comparisons.CsvComparisonOutput; import de.jplag.exceptions.ExitException; import de.jplag.merging.MergingOptions; import de.jplag.options.JPlagOptions; import de.jplag.options.LanguageOption; import de.jplag.options.LanguageOptions; import de.jplag.reporting.reportobject.ReportObjectFactory; - +import org.slf4j.ILoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.OptionSpec; import picocli.CommandLine.ParseResult; +import java.io.File; +import java.security.SecureRandom; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_DESCRIPTION_HEADING; +import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_OPTION_LIST; +import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_SYNOPSIS; + /** * Command line interface class, allows using via command line. * @see CLI#main(String[]) @@ -81,9 +77,7 @@ public static void main(String[] args) { ReportObjectFactory reportObjectFactory = new ReportObjectFactory(); reportObjectFactory.createAndSaveReport(result, cli.getResultFolder()); - if (cli.options.csv.print) { - cli.printCsv(result); - } + OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFolder()), cli.options); } } catch (ExitException exception) { logger.error(exception.getMessage()); // do not pass exception here to keep log clean @@ -92,14 +86,6 @@ public static void main(String[] args) { } } - private void printCsv(JPlagResult result) { - try { - CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), options.csv.anonymize, new File(getResultFolder()), options.csv.fileName); - } catch (IOException e) { - logger.error("Could not write csv", e); - } - } - /** * Creates a new instance */ diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index 804a9b4a4..395c45ec7 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -62,9 +62,6 @@ public class CliOptions implements Runnable { @ArgGroup(validate = false, heading = "Merging of neighboring matches to increase the similarity of concealed plagiarism:%n") public Merging merging = new Merging(); - @ArgGroup(validate = false, heading = "Csv%n") - public Csv csv = new Csv(); - /** * Empty run method, so picocli prints help automatically */ @@ -91,6 +88,9 @@ public static class Advanced { "--similarity-threshold"}, description = "Comparison similarity threshold [0.0-1.0]: All comparisons above this threshold will " + "be saved (default: 0.0)%n") public double similarityThreshold = JPlagOptions.DEFAULT_SIMILARITY_THRESHOLD; + + @Option(names = "--csv-export", description = "If present, a csv export will be generated in addition to the zip file.") + public boolean csvExport = false; } public static class Clustering { @@ -127,18 +127,6 @@ public static class Merging { } - public static class Csv { - @Option(names = {"--csv-print"}, description = "If true, the comparisons will pre printed in a csv%n") - public boolean print; - - @Option(names = { - "--csv-anonymize"}, description = "If true, the csv will contain anonymized data and a second csv will contain the actual names.%n") - public boolean anonymize; - - @Option(names = {"--csv-file-name"}, description = "Overrides the base name of the csv file. Do not include .csv in here.%n") - public String fileName = "resultCsv"; - } - @Option(names = {"--cluster-spectral-bandwidth"}, hidden = true) public double clusterSpectralBandwidth = new ClusteringOptions().spectralKernelBandwidth(); diff --git a/cli/src/main/java/de/jplag/cli/OutputFileGenerator.java b/cli/src/main/java/de/jplag/cli/OutputFileGenerator.java new file mode 100644 index 000000000..93cb9af7c --- /dev/null +++ b/cli/src/main/java/de/jplag/cli/OutputFileGenerator.java @@ -0,0 +1,32 @@ +package de.jplag.cli; + +import de.jplag.JPlagResult; +import de.jplag.csv.comparisons.CsvComparisonOutput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; + +public class OutputFileGenerator { + private static final Logger LOGGER = LoggerFactory.getLogger(OutputFileGenerator.class); + + /** + * Exports the given result as csvs, if the csvExport is activated in the options. + * Both a full and an anonymized version will be written. + * + * @param result The result to export + * @param outputRoot The root folder for the output + * @param options The cli options + */ + public static void generateCsvOutput(JPlagResult result, File outputRoot, CliOptions options) { + if (options.advanced.csvExport) { + try { + CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), false, outputRoot, "results"); + CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), true, outputRoot, "results-anonymous"); + } catch (IOException e) { + LOGGER.warn("Could not write csv results", e); + } + } + } +} diff --git a/core/pom.xml b/core/pom.xml index e504ecd2f..0d1f9480c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -37,12 +37,6 @@ ${revision} test - - org.scala-lang - scala-library - 2.13.11 - test - diff --git a/core/src/main/java/de/jplag/csv/comparisons/NameMapperIncrementalIds.java b/core/src/main/java/de/jplag/csv/comparisons/NameMapperIncrementalIds.java index ddd33181b..c3e0aaa29 100644 --- a/core/src/main/java/de/jplag/csv/comparisons/NameMapperIncrementalIds.java +++ b/core/src/main/java/de/jplag/csv/comparisons/NameMapperIncrementalIds.java @@ -5,7 +5,7 @@ import java.util.Map; /** - * Maps the real names of submissions to random ids to anonymize the data. + * Maps the real names of submissions to incremental ids. The ids will be in order of the queried new names. */ public class NameMapperIncrementalIds implements NameMapper { private final Map map;