Documentation
¶
Overview ¶
Package licenses matches byte slices against the ScanCode license rule corpus. Matching is exact after token normalization, so edits within a license can prevent a match.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTooManyMatches = errors.New("licenses: too many exact-match candidates")
ErrTooManyMatches is returned when an input produces more exact-match candidates than the matcher can safely filter.
Functions ¶
This section is empty.
Types ¶
type CorpusInfo ¶
type CorpusInfo struct {
Version string // ScanCode version recorded in CORPUS_VERSION.
RuleCount int // Number of license texts and rules in the index.
SourceCommit string // Full ScanCode Toolkit source commit.
}
CorpusInfo identifies the ScanCode corpus used for a result.
type Detection ¶
type Detection struct {
// Expression is copied exactly from the ScanCode rule.
Expression string
// Identification is derived from the identifiers in Expression.
Identification Identification
// Matches contains the rule matches that state Expression.
Matches []Match
}
Detection groups matches that state the same license expression.
type Identification ¶
type Identification string
Identification states whether a detected expression names concrete licenses.
const ( // Identified means the expression contains no ScanCode placeholder // identifiers. Identified Identification = "identified" // Partial means the expression contains both non-placeholder and ScanCode // placeholder identifiers. Partial Identification = "partial" // NoAssertion uses SPDX's NOASSERTION term when the expression contains // only ScanCode placeholder identifiers. NoAssertion Identification = "NOASSERTION" )
type Kind ¶
type Kind string
Kind identifies the ScanCode category of a matched rule.
const ( // KindUnknown identifies a rule without an is_license_* category. KindUnknown Kind = "unknown" // KindText identifies a full license text rule. KindText Kind = "text" // KindNotice identifies a license notice rule. KindNotice Kind = "notice" // KindTag identifies a license tag rule. KindTag Kind = "tag" // KindReference identifies a license reference rule. KindReference Kind = "reference" // KindIntro identifies a license introduction rule. KindIntro Kind = "intro" // KindClue identifies a weak license clue rule. KindClue Kind = "clue" )
type Match ¶
type Match struct {
// RuleID is the ScanCode rule identifier.
RuleID string
// LicenseIDs contains identifiers copied from the rule expression.
LicenseIDs []string
// Kind identifies the ScanCode category of the matched rule.
Kind Kind
// Method identifies the exact matching stage that produced the match.
Method Method
// Score is the rule's 0-100 relevance, not a similarity score.
Score float64
// Coverage is 100 for every exact match.
Coverage float64
// Start is the inclusive byte offset into the input.
Start int
// End is the exclusive byte offset into the input.
End int
// Matched is a copy of input[Start:End] when WithMatchedText is set.
// It is nil otherwise.
Matched []byte
}
Match describes one rule match in the input.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher matches byte slices against an immutable embedded corpus.
func New ¶
New loads the embedded corpus. The decoded corpus is shared by every Matcher in the process.
func (*Matcher) Corpus ¶
func (m *Matcher) Corpus() CorpusInfo
Corpus returns information about the embedded corpus used by m. It returns the zero value for a nil or uninitialized Matcher.
type Option ¶
type Option func(*matcherOptions)
Option configures a Matcher.
func WithMatchedText ¶
func WithMatchedText() Option
WithMatchedText includes a copy of each matched input range in Match.Matched.
type Result ¶
type Result struct {
Detections []Detection
Clues []Match
Corpus CorpusInfo
}
Result contains conclusive detections and weaker clue matches.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
corpusgen
command
Command corpusgen builds the embedded license corpus from a ScanCode checkout.
|
Command corpusgen builds the embedded license corpus from a ScanCode checkout. |
|
licenses
command
Command licenses scans files and repositories for exact ScanCode license rule matches.
|
Command licenses scans files and repositories for exact ScanCode license rule matches. |
|
internal
|
|
|
aho
Package aho implements a compact Aho-Corasick automaton over integer tokens.
|
Package aho implements a compact Aho-Corasick automaton over integer tokens. |
|
tokenize
Package tokenize converts license text into normalized integer tokens.
|
Package tokenize converts license text into normalized integer tokens. |