Skip to content

Commit

Permalink
Improved code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Dec 5, 2023
1 parent 844a8f8 commit 0f4154b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
46 changes: 16 additions & 30 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
@@ -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[])
Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
18 changes: 3 additions & 15 deletions cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down
32 changes: 32 additions & 0 deletions cli/src/main/java/de/jplag/cli/OutputFileGenerator.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
6 changes: 0 additions & 6 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
<version>${revision}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> map;
Expand Down

0 comments on commit 0f4154b

Please sign in to comment.