Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#944] Change to originality score and new threshold value #2072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
075d34d
[#2027] Fix date range bug (#2034)
jq1836 Sep 24, 2023
0c80ee6
[#2039] Update cypress minimum requirement to 12.15.0 (#2041)
chan-j-d Sep 30, 2023
46409aa
[#1936] Migrate c-segment.vue to typescript (#2035)
jq1836 Sep 30, 2023
43828fd
[#1936] Migrate load-font-awesome-icons.js to typescript (#2040)
jq1836 Sep 30, 2023
d4e2272
[#2045] Fix cypress zoom feature test (#2047)
jq1836 Oct 4, 2023
a8c3f00
[#1936] Migrate random-color-gen.js to typescript (#2043)
jq1836 Oct 4, 2023
93e850f
[#1936] Migrate c-segment-collection.vue to typescript (#2036)
jq1836 Oct 4, 2023
0d1cd99
[#1936] Migrate c-resizer.vue to typescript (#2038)
jq1836 Oct 4, 2023
6292688
Bump zod from 3.20.6 to 3.22.3 in /frontend (#2048)
dependabot[bot] Oct 4, 2023
7bc056a
Bump @cypress/request and cypress in /frontend/cypress (#2042)
dependabot[bot] Oct 4, 2023
0c4045d
[#1936] Migrate c-ramp.vue to typescript (#2037)
jq1836 Oct 11, 2023
174ecc5
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Oct 20, 2023
e200e5e
Give partial credit if annotated author is not the same as the blame
SkyBlaise99 Oct 20, 2023
00cf40d
[#2054] Fix zoom view bug (#2055)
jq1836 Oct 28, 2023
4dae85d
[#1936] Migrate repo-sorter.js to typescript (#2052)
jq1836 Oct 28, 2023
7450425
[#1936] Migrate safari_date.js to typescript (#2053)
jq1836 Oct 28, 2023
056fa5f
Remove frontend JS lint (#2063)
jq1836 Oct 28, 2023
bdeb15a
use full and partial credit color
SkyBlaise99 Oct 29, 2023
54596ed
[#1929] Add dynamic positioning support for tooltips (#2056)
pratham31012002 Nov 7, 2023
a187d9c
Add test cases for annotated author overriding last author's credit
SkyBlaise99 Nov 7, 2023
58b7002
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Nov 7, 2023
b296b83
revert merge from master
SkyBlaise99 Nov 7, 2023
4ce6545
revert merge from master 58b70025
SkyBlaise99 Nov 7, 2023
f29dc16
[#1928] Fix tooltip zIndex such that it doesn't occlude next file tit…
pratham31012002 Nov 8, 2023
e42c14e
[#1726] Update GitHub-specific references in codebase and docs (#2050)
chan-j-d Nov 8, 2023
4bd05a7
Trigger workflow
SkyBlaise99 Nov 8, 2023
950c912
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Nov 8, 2023
a46d423
Revert "Merge branch 'master' into 944-analyze-authorship"
SkyBlaise99 Nov 8, 2023
bba556d
fix frontend test failing
SkyBlaise99 Nov 8, 2023
4d7d3aa
Merge branch '944-analyze-authorship' into 944-analyze-authorship
SkyBlaise99 Nov 12, 2023
1b25572
Merge branch '944-swap-color' into 944-analyze-authorship
SkyBlaise99 Nov 12, 2023
9e93961
Merge branch 'reposense:944-analyze-authorship' into 944-analyze-auth…
SkyBlaise99 Nov 12, 2023
7908253
switch to originality score and threshold
SkyBlaise99 Nov 13, 2023
d086da2
update originality threshold
SkyBlaise99 Nov 13, 2023
6c8a051
revert frontend code changes
SkyBlaise99 Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/main/java/reposense/authorship/analyzer/AuthorshipAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class AuthorshipAnalyzer {
private static final Logger logger = LogsManager.getLogger(AuthorshipAnalyzer.class);

private static final double SIMILARITY_THRESHOLD = 0.8;
private static final double ORIGINALITY_THRESHOLD = 0.51;

private static final String DIFF_FILE_CHUNK_SEPARATOR = "\ndiff --git a/.*\n";
private static final Pattern FILE_CHANGED_PATTERN =
Expand Down Expand Up @@ -55,10 +55,10 @@ public static boolean analyzeAuthorship(RepoConfiguration config, String filePat
return true;
}

CandidateLine deletedLine = getDeletedLineWithHighestSimilarity(config, filePath, lineContent, commitHash);
CandidateLine deletedLine = getDeletedLineWithLowestOriginality(config, filePath, lineContent, commitHash);

// Give full credit if there are no deleted lines found or deleted line is less than similarity threshold
if (deletedLine == null || deletedLine.getSimilarityScore() < SIMILARITY_THRESHOLD) {
// Give full credit if there are no deleted lines found or deleted line is more than originality threshold
if (deletedLine == null || deletedLine.getOriginalityScore() > ORIGINALITY_THRESHOLD) {
return true;
}

Expand All @@ -84,14 +84,14 @@ public static boolean analyzeAuthorship(RepoConfiguration config, String filePat
}

/**
* Returns the deleted line in {@code commitHash} that has the highest similarity with {@code lineContent}.
* Returns the deleted line in {@code commitHash} that has the lowest originality with {@code lineContent}.
*/
private static CandidateLine getDeletedLineWithHighestSimilarity(RepoConfiguration config, String filePath,
private static CandidateLine getDeletedLineWithLowestOriginality(RepoConfiguration config, String filePath,
String lineContent, String commitHash) {
String gitLogResults = GitLog.getParentCommits(config.getRepoRoot(), commitHash);
String[] parentCommits = gitLogResults.split(" ");

CandidateLine highestSimilarityLine = null;
CandidateLine lowestOriginalityLine = null;

for (String parentCommit : parentCommits) {
// Generate diff between commit and parent commit
Expand All @@ -112,28 +112,28 @@ private static CandidateLine getDeletedLineWithHighestSimilarity(RepoConfigurati
continue;
}

CandidateLine candidateLine = getDeletedLineWithHighestSimilarityInDiff(
CandidateLine candidateLine = getDeletedLineWithLowestOriginalityInDiff(
fileDiffResult, lineContent, parentCommit, preImageFilePath);
if (candidateLine == null) {
continue;
}

if (highestSimilarityLine == null
|| candidateLine.getSimilarityScore() > highestSimilarityLine.getSimilarityScore()) {
highestSimilarityLine = candidateLine;
if (lowestOriginalityLine == null
|| candidateLine.getOriginalityScore() < lowestOriginalityLine.getOriginalityScore()) {
lowestOriginalityLine = candidateLine;
}
}
}

return highestSimilarityLine;
return lowestOriginalityLine;
}

/**
* Returns the deleted line in {@code fileDiffResult} that has the highest similarity with {@code lineContent}.
* Returns the deleted line in {@code fileDiffResult} that has the lowest originality with {@code lineContent}.
*/
private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fileDiffResult, String lineContent,
private static CandidateLine getDeletedLineWithLowestOriginalityInDiff(String fileDiffResult, String lineContent,
String commitHash, String filePath) {
CandidateLine highestSimilarityLine = null;
CandidateLine lowestOriginalityLine = null;

String[] hunks = fileDiffResult.split(HUNK_SEPARATOR);

Expand All @@ -155,11 +155,13 @@ private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fi

if (lineChanged.startsWith(DELETED_LINE_SYMBOL)) {
String deletedLineContent = lineChanged.substring(DELETED_LINE_SYMBOL.length());
double similarityScore = similarityScore(lineContent, deletedLineContent);
double originalityScore = computeOriginalityScore(lineContent, deletedLineContent);

if (highestSimilarityLine == null || similarityScore > highestSimilarityLine.getSimilarityScore()) {
highestSimilarityLine = new CandidateLine(
currentPreImageLineNumber, deletedLineContent, filePath, commitHash, similarityScore);
if (lowestOriginalityLine == null
|| originalityScore < lowestOriginalityLine.getOriginalityScore()) {
lowestOriginalityLine = new CandidateLine(
currentPreImageLineNumber, deletedLineContent, filePath, commitHash,
originalityScore);
}
}

Expand All @@ -169,7 +171,7 @@ private static CandidateLine getDeletedLineWithHighestSimilarityInDiff(String fi
}
}

return highestSimilarityLine;
return lowestOriginalityLine;
}

/**
Expand All @@ -191,11 +193,11 @@ private static int getPreImageStartingLineNumber(String linesChangedHeader) {
}

/**
* Calculates the similarity score of {@code s} with {@code baseString}.
* Calculates the originality score of {@code s} with {@code baseString}.
*/
private static double similarityScore(String s, String baseString) {
private static double computeOriginalityScore(String s, String baseString) {
double levenshteinDistance = StringsUtil.getLevenshteinDistance(s, baseString);
return 1 - (levenshteinDistance / baseString.length());
return levenshteinDistance / baseString.length();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/reposense/authorship/model/CandidateLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class CandidateLine {
private final String lineContent;
private final String filePath;
private final String gitBlameCommitHash;
private final double similarityScore;
private final double originalityScore;

public CandidateLine(int lineNumber, String lineContent, String filePath, String gitBlameCommitHash,
double similarityScore) {
double originalityScore) {
this.lineNumber = lineNumber;
this.lineContent = lineContent;
this.filePath = filePath;
this.gitBlameCommitHash = gitBlameCommitHash;
this.similarityScore = similarityScore;
this.originalityScore = originalityScore;
}

public int getLineNumber() {
Expand All @@ -35,7 +35,7 @@ public String getGitBlameCommitHash() {
return gitBlameCommitHash;
}

public double getSimilarityScore() {
return similarityScore;
public double getOriginalityScore() {
return originalityScore;
}
}
Loading