-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License detection now shows 3 most probable licenses with match perct…
…ng (#37)
- Loading branch information
1 parent
425feaa
commit 7fca241
Showing
10 changed files
with
155 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ jshell.history | |
nbactions.xml | ||
nb-configuration.xml | ||
/plugin.cargo/nbproject/ | ||
/plugin.npm/nbproject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
common-utils/src/main/java/com/phsyberdome/common/utils/models/LicenseDetectionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
package com.phsyberdome.common.utils.models; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Pratham Gahlout | ||
*/ | ||
public class LicenseDetectionResult { | ||
|
||
private static final double DIFFERENTIATING_TOLERANCE = 0.05; // 5% | ||
|
||
private List<Pair<String,Double>> licenses; | ||
private String content; | ||
|
||
public LicenseDetectionResult(List<Pair<String,Double>> licenses, String content) { | ||
this.licenses = licenses; | ||
this.content = content; | ||
} | ||
|
||
public LicenseDetectionResult(String content) { | ||
this.content = content; | ||
this.licenses = new ArrayList<>(); | ||
} | ||
|
||
public LicenseDetectionResult() { | ||
this.licenses = new ArrayList<>(); | ||
this.content = ""; | ||
} | ||
|
||
public void addProbableLicense(Pair<String,Double> license) { | ||
if(licenses==null) { | ||
this.licenses = new ArrayList<>(); | ||
} | ||
this.licenses.add(license); | ||
} | ||
|
||
private void sortLicensesByProbability() { | ||
List<Pair<String,Double>> modifiable = new ArrayList<>(this.licenses); | ||
modifiable.sort((Pair<String, Double> o1, Pair<String, Double> o2) -> { | ||
if(o1.second > o2.second){ | ||
return -1; | ||
}else if(o1.second < o2.second) { | ||
return 1; | ||
}else{ | ||
return 0; | ||
} | ||
}); | ||
this.setLicenses(modifiable); | ||
} | ||
|
||
public List<Pair<String,Double>> getLicenses(){ | ||
return this.licenses; | ||
} | ||
|
||
public String getAnalyzedContent() { | ||
return this.content; | ||
} | ||
|
||
public void setAnalyzedContent(String content){ | ||
this.content = content; | ||
} | ||
|
||
public void setLicenses(List<Pair<String,Double>> licenses) { | ||
this.licenses = licenses; | ||
} | ||
|
||
public LicenseDetectionResult getResultWithMostProbableLicenses() { | ||
var newResult = new LicenseDetectionResult(); | ||
newResult.setAnalyzedContent(this.content); | ||
var highest = this.licenses.getFirst().second; | ||
newResult.setLicenses(this.licenses.stream().filter(item -> (highest - item.second) < DIFFERENTIATING_TOLERANCE) | ||
.map(item -> { | ||
return new Pair<>(item.first,Math.floor(item.second * 1000)/1000); | ||
}).limit(3).toList()); | ||
newResult.sortLicensesByProbability(); | ||
return newResult; | ||
} | ||
|
||
public String getLicensesAsString() { | ||
return String.join(" | ", licenses.stream().map(item -> item.first + " " + item.second).toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters