aboutsummaryrefslogtreecommitdiff
path: root/rdfloader/parser2v2/parse_other_license_info.go
blob: 887ae55e5b5321d45c6d5db8a2ff8dbb0b1a63c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

package parser2v2

import (
	"fmt"
	gordfParser "github.com/RishabhBhatnagar/gordf/rdfloader/parser"
	"github.com/RishabhBhatnagar/gordf/rdfwriter"
	"github.com/spdx/tools-golang/spdx"
)

func (parser *rdfParser2_2) getExtractedLicensingInfoFromNode(node *gordfParser.Node) (lic ExtractedLicensingInfo, err error) {
	associatedTriples := rdfwriter.FilterTriples(parser.gordfParserObj.Triples, &node.ID, nil, nil)
	restTriples := []*gordfParser.Triple{}
	for _, triple := range associatedTriples {
		switch triple.Predicate.ID {
		case SPDX_EXTRACTED_TEXT:
			lic.extractedText = triple.Object.ID
		default:
			restTriples = append(restTriples, triple)
		}
	}
	lic.SimpleLicensingInfo, err = parser.getSimpleLicensingInfoFromTriples(restTriples)
	if err != nil {
		return lic, fmt.Errorf("error setting simple licensing information of extracted licensing info: %s", err)
	}
	return lic, nil
}

func (parser *rdfParser2_2) extractedLicenseToOtherLicense(extLicense ExtractedLicensingInfo) (othLic spdx.OtherLicense2_2) {
	othLic.LicenseIdentifier = extLicense.licenseID
	othLic.ExtractedText = extLicense.extractedText
	othLic.LicenseComment = extLicense.comment
	othLic.LicenseCrossReferences = extLicense.seeAlso
	othLic.LicenseName = extLicense.name
	return othLic
}