Skip to content

Commit

Permalink
move json to actual options
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Jan 4, 2024
1 parent d6622da commit 1ff2c91
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 75 deletions.
15 changes: 11 additions & 4 deletions core/src/main/java/de/jplag/clustering/ClusteringOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import de.jplag.clustering.algorithm.InterClusterSimilarity;
import de.jplag.options.SimilarityMetric;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Collection of all possible parameters that describe how a clustering should be performed.
* @param similarityMetric The similarity metric is used for clustering
Expand Down Expand Up @@ -34,10 +36,15 @@
* @param preprocessorPercentile up to which percentile of similarities the percentile-preprocessor zeroes out the
* similarities
*/
public record ClusteringOptions(SimilarityMetric similarityMetric, double spectralKernelBandwidth, double spectralGaussianProcessVariance,
int spectralMinRuns, int spectralMaxRuns, int spectralMaxKMeansIterationPerRun, double agglomerativeThreshold, Preprocessing preprocessor,
boolean enabled, ClusteringAlgorithm algorithm, InterClusterSimilarity agglomerativeInterClusterSimilarity, double preprocessorThreshold,
double preprocessorPercentile) {
public record ClusteringOptions(@JsonProperty("metric") SimilarityMetric similarityMetric,
@JsonProperty("spectral_bandwidth") double spectralKernelBandwidth,
@JsonProperty("spectral_gaussian_variance") double spectralGaussianProcessVariance, @JsonProperty("spectral_min_runs") int spectralMinRuns,
@JsonProperty("spectral_max_runs") int spectralMaxRuns, @JsonProperty("spectral_max_kmeans_iterations") int spectralMaxKMeansIterationPerRun,
@JsonProperty("agglomerative_threshold") double agglomerativeThreshold, @JsonProperty("preprocessor") Preprocessing preprocessor,
@JsonProperty("enabled") boolean enabled, @JsonProperty("algorithm") ClusteringAlgorithm algorithm,
@JsonProperty("inter_similarity") InterClusterSimilarity agglomerativeInterClusterSimilarity,
@JsonProperty("preprocessor_threshold") double preprocessorThreshold,
@JsonProperty("preprocessor_percentile") double preprocessorPercentile) {

public ClusteringOptions(SimilarityMetric similarityMetric, double spectralKernelBandwidth, double spectralGaussianProcessVariance,
int spectralMinRuns, int spectralMaxRuns, int spectralMaxKMeansIterationPerRun, double agglomerativeThreshold, Preprocessing preprocessor,
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/de/jplag/merging/MergingOptions.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.jplag.merging;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Collection of parameters that describe how a match merging should be performed.
* @param minimumNeighborLength describes how short a match can be, to be considered (Defaults to 2).
* @param maximumGapSize describes how many tokens can be between to neighboring matches (Defaults to 6).
*/
public record MergingOptions(boolean enabled, int minimumNeighborLength, int maximumGapSize) {
public record MergingOptions(@JsonProperty("enabled") boolean enabled, @JsonProperty("min_neighbour_length") int minimumNeighborLength,
@JsonProperty("max_gap_size") int maximumGapSize) {

/**
* The default values of MergingOptions are false for the enable-switch, which deactivate MatchMerging, while
Expand Down
15 changes: 11 additions & 4 deletions core/src/main/java/de/jplag/options/JPlagOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
import de.jplag.clustering.ClusteringOptions;
import de.jplag.exceptions.BasecodeException;
import de.jplag.merging.MergingOptions;
import de.jplag.reporting.jsonfactory.serializer.LanguageSerializer;
import de.jplag.util.FileUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
* This record defines the options to configure {@link JPlag}.
* @param language Language to use when parsing the submissions.
Expand All @@ -45,10 +49,13 @@
* @param clusteringOptions Clustering options
* @param debugParser If true, submissions that cannot be parsed will be stored in a separate directory.
*/
public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<File> submissionDirectories, Set<File> oldSubmissionDirectories,
File baseCodeSubmissionDirectory, String subdirectoryName, List<String> fileSuffixes, String exclusionFileName,
SimilarityMetric similarityMetric, double similarityThreshold, int maximumNumberOfComparisons, ClusteringOptions clusteringOptions,
boolean debugParser, MergingOptions mergingOptions) {
public record JPlagOptions(@JsonSerialize(using = LanguageSerializer.class) Language language,
@JsonProperty("min_token_match") Integer minimumTokenMatch, @JsonProperty("submission_directories") Set<File> submissionDirectories,
@JsonProperty("old_directories") Set<File> oldSubmissionDirectories, @JsonProperty("base_directory") File baseCodeSubmissionDirectory,
@JsonProperty("subdirectory_name") String subdirectoryName, @JsonProperty("file_suffixes") List<String> fileSuffixes,
@JsonProperty("exclusion_file_name") String exclusionFileName, @JsonProperty("similarity_metric") SimilarityMetric similarityMetric,
@JsonProperty("similarity_threshold") double similarityThreshold, @JsonProperty("max_comparisons") int maximumNumberOfComparisons,
@JsonProperty("cluster") ClusteringOptions clusteringOptions, boolean debugParser, @JsonProperty("merging") MergingOptions mergingOptions) {

public static final double DEFAULT_SIMILARITY_THRESHOLD = 0;
public static final int DEFAULT_SHOWN_COMPARISONS = 500;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.jplag.reporting.jsonfactory.serializer;

import java.io.IOException;

import de.jplag.Language;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

public class LanguageSerializer extends StdSerializer<Language> {

/**
* Constructor used by the fasterxml.jackson
*/
public LanguageSerializer() {
this(null);
}

public LanguageSerializer(Class<Language> t) {
super(t);
}

@Override
public void serialize(Language value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
import de.jplag.reporting.jsonfactory.ComparisonReportWriter;
import de.jplag.reporting.reportobject.mapper.ClusteringResultMapper;
import de.jplag.reporting.reportobject.mapper.MetricMapper;
import de.jplag.reporting.reportobject.model.ClusterOptionsReport;
import de.jplag.reporting.reportobject.model.MergingOptionsReport;
import de.jplag.reporting.reportobject.model.OptionsReport;
import de.jplag.reporting.reportobject.model.OverviewReport;
import de.jplag.reporting.reportobject.model.SubmissionFileIndex;
import de.jplag.reporting.reportobject.model.Version;
Expand Down Expand Up @@ -230,21 +227,7 @@ private void writeSubmissionIndexFile(JPlagResult result, String path) {
}

private void writeOptionsFiles(JPlagOptions options, String path) {
OptionsReport report = new OptionsReport(options.language().getName(), options.minimumTokenMatch(),
options.submissionDirectories().stream().map(File::getPath).toList(),
options.oldSubmissionDirectories().stream().map(File::getPath).toList(),
options.hasBaseCode() ? options.baseCodeSubmissionDirectory().getPath() : "", options.subdirectoryName(), options.fileSuffixes(),
options.exclusionFileName(), options.similarityMetric().name(), options.similarityThreshold(), options.maximumNumberOfComparisons(),
new ClusterOptionsReport(options.clusteringOptions().enabled(), options.clusteringOptions().similarityMetric().name(),
options.clusteringOptions().spectralKernelBandwidth(), options.clusteringOptions().spectralGaussianProcessVariance(),
options.clusteringOptions().spectralMinRuns(), options.clusteringOptions().spectralMaxRuns(),
options.clusteringOptions().spectralMaxKMeansIterationPerRun(), options.clusteringOptions().agglomerativeThreshold(),
options.clusteringOptions().preprocessor().name(), options.clusteringOptions().algorithm().name(),
options.clusteringOptions().agglomerativeInterClusterSimilarity().name(), options.clusteringOptions().preprocessorThreshold(),
options.clusteringOptions().preprocessorPercentile()),
new MergingOptionsReport(options.mergingOptions().enabled(), options.mergingOptions().minimumNeighborLength(),
options.mergingOptions().maximumGapSize()));
jsonFileWriter.writeFile(report, path, OPTIONS_FILE_NAME);
jsonFileWriter.writeFile(options, path, OPTIONS_FILE_NAME);
}

private Set<Submission> getSubmissions(List<JPlagComparison> comparisons) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions report-viewer/src/model/CliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface CliOptions {
fileSuffixes: string[]
exclusionFileName: string
similarityMetric: MetricType
similarityTreshold: number
similarityThreshold: number
maxNumberComparisons: number
clusterOptions: CliClusterOptions
mergingOptions: CliMergingOptions
Expand All @@ -29,12 +29,12 @@ export interface CliClusterOptions {
preprocessor: string
algorithm: string
interClusterSimilarity: string
preprocessorTreshold: number
preprocessorThreshold: number
preprocessorPercentile: number
}

export interface CliMergingOptions {
enabled: boolean
minNeighbourLength: number
minNeighborLength: number
maxGapSize: number
}
8 changes: 4 additions & 4 deletions report-viewer/src/model/factories/OptionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class OptionsFactory extends BaseFactory {
fileSuffixes: json['file_suffixes'] as string[],
exclusionFileName: (json['exclusion_file_name'] as string) ?? '',
similarityMetric: json['similarity_metric'] as MetricType,
similarityTreshold: json['similarity_threshold'] as number,
similarityThreshold: json['similarity_threshold'] as number,
maxNumberComparisons: json['max_comparisons'] as number,
clusterOptions: this.extractClusterOptions(json['cluster'] as Record<string, unknown>),
mergingOptions: this.extractMergingOptions(json['merging'] as Record<string, unknown>)
Expand All @@ -39,15 +39,15 @@ export class OptionsFactory extends BaseFactory {
preprocessor: this.transformWord(json['preprocessor'] as string),
algorithm: this.transformWord(json['algorithm'] as string),
interClusterSimilarity: this.transformWord(json['inter_similarity'] as string),
preprocessorTreshold: json['preprocessor_threshold'] as number,
preprocessorPercentile: json['preprocessor_precentile'] as number
preprocessorThreshold: json['preprocessor_threshold'] as number,
preprocessorPercentile: json['preprocessor_percentile'] as number
}
}

private static extractMergingOptions(json: Record<string, unknown>): CliMergingOptions {
return {
enabled: json['enabled'] as boolean,
minNeighbourLength: json['min_neighbour_length'] as number,
minNeighborLength: json['min_neighbour_length'] as number,
maxGapSize: json['max_gap_size'] as number
}
}
Expand Down
14 changes: 7 additions & 7 deletions report-viewer/src/views/InformationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
overview.baseCodeFolderPath
}}</TextInformation>
<TextInformation label="Language" class="pb-1">{{ overview.language }}</TextInformation>
<TextInformation label="File Extentions" class="pb-1">{{
<TextInformation label="File Extensions" class="pb-1">{{
overview.fileExtensions.join(', ')
}}</TextInformation>
<TextInformation label="Min Token Match" class="pb-1">{{
Expand Down Expand Up @@ -42,8 +42,8 @@
<TextInformation label="Similarity Metric">{{
metricToolTips[options.similarityMetric].longName
}}</TextInformation>
<TextInformation label="Similarity Treshold">{{
options.similarityTreshold
<TextInformation label="Similarity Threshold">{{
options.similarityThreshold
}}</TextInformation>
<TextInformation label="Max Comparison Count">{{
options.maxNumberComparisons
Expand Down Expand Up @@ -86,8 +86,8 @@
<TextInformation label="Preprocessor">{{
options.clusterOptions.preprocessor
}}</TextInformation>
<TextInformation label="Preprocessor Treshold">{{
options.clusterOptions.preprocessorTreshold
<TextInformation label="Preprocessor Threshold">{{
options.clusterOptions.preprocessorThreshold
}}</TextInformation>
<TextInformation label="Preprocessor Percentile">{{
options.clusterOptions.preprocessorPercentile
Expand All @@ -99,8 +99,8 @@

<div class="mt-5 space-y-2" v-if="options.mergingOptions.enabled">
<h3 class="font-bold">Match Merging:</h3>
<TextInformation label="Min Neighbour Length">{{
options.mergingOptions.minNeighbourLength
<TextInformation label="Min Neighbor Length">{{
options.mergingOptions.minNeighborLength
}}</TextInformation>
<TextInformation label="Max Gap Size"
>{{ options.mergingOptions.maxGapSize }} }}</TextInformation
Expand Down

0 comments on commit 1ff2c91

Please sign in to comment.