Skip to content

Commit

Permalink
include basecode in symmetric similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Nov 28, 2024
1 parent dad1a4a commit bcbd7db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/de/jplag/JPlagComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public final double similarity() {
return 2 * similarity(divisorA + divisorB);
}

/**
* @return A symmetric similarity in interval [0, 1]. O means no similarity, 1 means maximum similarity.
*/
public final double symmetricSimilarity() {
boolean subtractBaseCode = firstSubmission.hasBaseCodeMatches() && secondSubmission.hasBaseCodeMatches();
int divisorA = firstSubmission.getSimilarityDivisor(subtractBaseCode);
int divisorB = secondSubmission.getSimilarityDivisor(subtractBaseCode);
if (divisorA + divisorB == 0) {
return 0.0;
}
return 2.0 * getNumberOfMatchedTokens() / (divisorA + divisorB);
}

/**
* @return Similarity of the first submission in interval [0, 1]. O means no similarity, 1 means maximum similarity.
*/
Expand Down
9 changes: 1 addition & 8 deletions core/src/main/java/de/jplag/options/SimilarityMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ public enum SimilarityMetric implements ToDoubleFunction<JPlagComparison> {
MIN("minimum similarity", JPlagComparison::minimalSimilarity),
MAX("maximal similarity", JPlagComparison::maximalSimilarity),
INTERSECTION("matched tokens", it -> (double) it.getNumberOfMatchedTokens()),
SYMMETRIC("symmetric similarity", it -> {
int divisor = it.firstSubmission().getNumberOfTokens() + it.secondSubmission().getNumberOfTokens();
if (divisor != 0) {
return 2.0 * it.getNumberOfMatchedTokens() / divisor;
} else {
return .0;
}
}),
SYMMETRIC("symmetric similarity", JPlagComparison::symmetricSimilarity),
LONGEST_MATCH("number of tokens in the longest match", it -> it.matches().stream().mapToInt(Match::length).max().orElse(0)),
OVERALL("Sum of both submission lengths", it -> it.firstSubmission().getNumberOfTokens() + it.secondSubmission().getNumberOfTokens());

Expand Down

0 comments on commit bcbd7db

Please sign in to comment.