Skip to content

Commit

Permalink
Update license text detection and correct threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
lumaxis authored Apr 17, 2024
1 parent 7a78662 commit 659a823
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions providers/summary/scancode-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class ScanCodeSummarizerNew {

_getDeclaredLicenseFromFiles(harvestedData, coordinates) {
const rootFiles = this._getRootFiles(coordinates, harvestedData.content.files, harvestedData.content.packages)
return this._getLicenseFromLicenseDetections(rootFiles)
return this._getLicensesFromLicenseDetections(rootFiles)
}

_getLicenseFromLicenseDetections(files) {
_getLicensesFromLicenseDetections(files) {
const fullLicenses = files
.filter(file => file.percentage_of_license_text >= 80 && file.license_detections)
.filter(file => file.percentage_of_license_text >= 90 && file.license_detections)
.reduce((licenses, file) => {
file.license_detections.forEach(licenseDetection => {
licenses.add(normalizeLicenseExpression(licenseDetection.license_expression, this.logger))
Expand All @@ -130,7 +130,7 @@ class ScanCodeSummarizerNew {
return joinExpressions(fullLicenses)
}

_getLicenseByFileName(files, coordinates) {
_getLicenseByFileName(files, coordinates, licenseClarityScoreThreshold = 90) {
const fullLicenses = files
.filter(file => isLicenseFile(file.path, coordinates) && file.license_detections)
.reduce((licenses, file) => {
Expand All @@ -140,7 +140,7 @@ class ScanCodeSummarizerNew {
return
}
licenseDetection.matches.forEach(match => {
if (match.score >= 90) {
if (match.score >= licenseClarityScoreThreshold) {
licenses.add(normalizeLicenseExpression(match.license_expression, this.logger))
}
})
Expand All @@ -157,14 +157,13 @@ class ScanCodeSummarizerNew {

const result = { path: file.path }

const licenseExpressionFromFromLicenseDetections = this._getLicenseFromLicenseDetections([file])
const licenseExpression =
file.detected_license_expression_spdx ||
normalizeLicenseExpression(file.detected_license_expression, this.logger) ||
licenseExpressionFromFromLicenseDetections
this._getLicenseByFileName([file], coordinates, 80)
setIfValue(result, 'license', licenseExpression)

if (licenseExpressionFromFromLicenseDetections || this._getLicenseByFileName([file], coordinates)) {
if (this._getLicensesFromLicenseDetections([file]) || this._getLicenseByFileName([file], coordinates)) {
result.natures = result.natures || []
if (!result.natures.includes('license')) result.natures.push('license')
}
Expand Down
4 changes: 2 additions & 2 deletions test/providers/summary/scancode-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ describe('ScancodeSummarizerNew basic compatability', () => {
)
assert.equal(result.described.releaseDate, '2021-01-13', `releaseDate mismatch for version ${version}`)
assert.deepEqual(uniq(compact(flatten(result.files.map(x => x.attributions)))).length, 6)
assert.deepEqual(result.files.find(x => x.path === 'COPYRIGHT').natures, ['license'])
assert.equal(result.files.find(x => x.path === 'COPYRIGHT').natures, null)
assert.deepEqual(result.files.find(x => x.path === 'LICENSE-APACHE').natures, ['license'])
assert.deepEqual(result.files.find(x => x.path === 'LICENSE-MIT').natures, ['license'])
assert.equal(compact(flatten(result.files.map(x => x.natures))).length, 3)
assert.equal(compact(flatten(result.files.map(x => x.natures))).length, 2)
}
})
})
Expand Down

0 comments on commit 659a823

Please sign in to comment.