diff options
Diffstat (limited to 'rdfloader/parser2v2/parse_other_license_info.go')
-rw-r--r-- | rdfloader/parser2v2/parse_other_license_info.go | 65 |
1 files changed, 18 insertions, 47 deletions
diff --git a/rdfloader/parser2v2/parse_other_license_info.go b/rdfloader/parser2v2/parse_other_license_info.go index dd1c193..887ae55 100644 --- a/rdfloader/parser2v2/parse_other_license_info.go +++ b/rdfloader/parser2v2/parse_other_license_info.go @@ -5,62 +5,33 @@ package parser2v2 import ( "fmt" gordfParser "github.com/RishabhBhatnagar/gordf/rdfloader/parser" + "github.com/RishabhBhatnagar/gordf/rdfwriter" "github.com/spdx/tools-golang/spdx" - "strings" ) -func (parser *rdfParser2_2) getExternalLicensingInfoFromNode(node *gordfParser.Node) (*spdx.OtherLicense2_2, error) { - lic := &spdx.OtherLicense2_2{} - licensePrefix := "LicenseRef-" - for _, triple := range parser.nodeToTriples[node.String()] { +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 RDF_TYPE: - continue - case SPDX_LICENSE_ID: - fragment := strings.TrimSpace(getLastPartOfURI(triple.Subject.ID)) - if !strings.HasPrefix(fragment, licensePrefix) { - return nil, fmt.Errorf("license ID must be of type \"LicenseRef-[idstring]\"; found %s", fragment) - } - lic.LicenseIdentifier = strings.TrimSuffix(fragment, licensePrefix) case SPDX_EXTRACTED_TEXT: - lic.ExtractedText = triple.Object.ID - case SPDX_NAME: - lic.LicenseName = triple.Object.ID - case RDFS_SEE_ALSO: - lic.LicenseCrossReferences = append(lic.LicenseCrossReferences, triple.Object.ID) - case RDFS_COMMENT: - lic.LicenseComment = triple.Object.ID + lic.extractedText = triple.Object.ID default: - return nil, fmt.Errorf("unknown predicate %v while parsing extractedLicensingInfo", triple.Predicate) + 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 } -// parses the other license and appends it to the doc if no error is encountered. -func (parser *rdfParser2_2) parseOtherLicenseFromNode(node *gordfParser.Node) error { - ol := &spdx.OtherLicense2_2{} - ol.LicenseIdentifier = getLicenseStringFromURI(node.ID) // 6.1 - for _, triple := range parser.nodeToTriples[node.String()] { - switch triple.Predicate.ID { - case RDF_TYPE: - continue - case SPDX_EXTRACTED_TEXT: // 6.2 - ol.ExtractedText = triple.Object.ID - case SPDX_NAME: // 6.3 - ol.LicenseName = triple.Object.ID - case RDFS_SEE_ALSO: // 6.4 - ol.LicenseCrossReferences = append(ol.LicenseCrossReferences, triple.Object.ID) - case RDFS_COMMENT: // 6.5 - ol.LicenseComment = triple.Object.ID - case SPDX_LICENSE_ID: - // override licenseId from the rdf:about tag. - ol.LicenseIdentifier = getLicenseStringFromURI(triple.Object.ID) - default: - return fmt.Errorf("unknown predicate (%s) while parsing other license", triple.Predicate.ID) - } - } - - parser.doc.OtherLicenses = append(parser.doc.OtherLicenses, ol) - return 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 } |