aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Neubauer <wcn@google.com>2022-03-02 11:11:37 -0800
committerBill Neubauer <wcn@google.com>2022-03-16 15:40:12 -0700
commit006e5cbc150d70483f4b4911fc7703d8e522f0b0 (patch)
treedb415900291a3b68308d7cd65c750833daafd40d
parent0ae8c6436993ad2e16c43e0ad11789005a170d14 (diff)
downloadlicenseclassifier-006e5cbc150d70483f4b4911fc7703d8e522f0b0.tar.gz
Updates the classifier's report structure to include information about the
detected variant of a match. This information is plumbed through into the text report of the identify_license tool. Note that this currently isn't plumbed into the JSON report because I can't determine what might break as a result of that. Will follow up on this, but wanted to get this initial version done to support basic diagnostics. PiperOrigin-RevId: 431983634
-rw-r--r--v2/classifier.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/v2/classifier.go b/v2/classifier.go
index 6dafd51..5e5f8cc 100644
--- a/v2/classifier.go
+++ b/v2/classifier.go
@@ -30,6 +30,7 @@ type Match struct {
Name string
Confidence float64
MatchType string
+ Variant string
StartLine int
EndLine int
StartTokenIndex int
@@ -100,6 +101,7 @@ func (c *Classifier) match(in []byte) Results {
if conf >= c.threshold && (endIndex-startIndex-startOffset-endOffset) > 0 {
candidates = append(candidates, &Match{
Name: LicenseName(l),
+ Variant: variantName(l),
MatchType: detectionType(l),
Confidence: conf,
StartLine: id.Tokens[startIndex+startOffset].Line,
@@ -322,6 +324,11 @@ func detectionType(in string) string {
return splits[0]
}
+func variantName(in string) string {
+ splits := strings.Split(in, fmt.Sprintf("%c", os.PathSeparator))
+ return splits[2]
+}
+
// LicenseName produces the output name for a license, removing the internal structure
// of the filename in use.
func LicenseName(in string) string {