From 006e5cbc150d70483f4b4911fc7703d8e522f0b0 Mon Sep 17 00:00:00 2001 From: Bill Neubauer Date: Wed, 2 Mar 2022 11:11:37 -0800 Subject: 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 --- v2/classifier.go | 7 +++++++ 1 file changed, 7 insertions(+) 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 { -- cgit v1.2.3