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
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 @@
Name string
Confidence float64
MatchType string
+ Variant string
StartLine int
EndLine int
StartTokenIndex int
@@ -100,6 +101,7 @@
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 @@
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 {