Skip to content

Commit

Permalink
Merge 6709be2 into ea86b81
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekspeer committed Aug 13, 2019
2 parents ea86b81 + 6709be2 commit 43938cc
Show file tree
Hide file tree
Showing 17 changed files with 2,787 additions and 0 deletions.
1,225 changes: 1,225 additions & 0 deletions v0/rdf/examplerdf2v1.rdf

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions v0/rdf/rdf2v1/Annotation.go
@@ -0,0 +1,31 @@
package rdf2v1

import (
"github.com/deltamobile/goraptor"
)

type Annotation struct {
Annotator ValueStr
AnnotationType ValueStr
AnnotationDate ValueStr
AnnotationComment ValueStr
}

func (p *Parser) requestAnnotation(node goraptor.Term) (*Annotation, error) {
obj, err := p.requestElementType(node, typeAnnotation)
if err != nil {
return nil, err
}
return obj.(*Annotation), err
}

func (p *Parser) MapAnnotation(an *Annotation) *builder {
builder := &builder{t: typeAnnotation, ptr: an}
builder.updaters = map[string]updater{
"annotationDate": update(&an.AnnotationDate),
"rdfs:comment": update(&an.AnnotationComment),
"annotator": update(&an.Annotator),
"annotationType": updateTrimPrefix(baseUri, &an.AnnotationType),
}
return builder
}
54 changes: 54 additions & 0 deletions v0/rdf/rdf2v1/Checksum.go
@@ -0,0 +1,54 @@
package rdf2v1

import (
"fmt"
"strings"

"github.com/deltamobile/goraptor"
)

type Checksum struct {
Algorithm ValueStr
ChecksumValue ValueStr
}

func (p *Parser) requestChecksum(node goraptor.Term) (*Checksum, error) {
obj, err := p.requestElementType(node, typeChecksum)
if err != nil {
return nil, err
}
return obj.(*Checksum), err
}

func (p *Parser) MapChecksum(cksum *Checksum) *builder {
builder := &builder{t: typeChecksum, ptr: cksum}
key := false
builder.updaters = map[string]updater{
"algorithm": func(obj goraptor.Term) error {
if key {
return fmt.Errorf("Algorithm defined already.")
}
algostr := termStr(obj)
cksum.Algorithm.Val = ExtractChecksumAlgo(algostr)
key = true
return nil
},
"checksumValue": update(&cksum.ChecksumValue),
}
return builder
}

func ExtractChecksumAlgo(str string) string {
str = strings.Replace(str, "http://spdx.org/rdf/terms#checksumAlgorithm_", "", 1)
str = strings.ToUpper(str)
return str
}

// Takes in the checksum, compares it's algo with a string, if matches returns the algo
func AlgoIdentifier(cksum *Checksum, t string) string {
algo := ExtractChecksumAlgo(cksum.Algorithm.Val)
if strings.Contains(algo, t) {
return t
}
return ""
}
68 changes: 68 additions & 0 deletions v0/rdf/rdf2v1/CreationInfo.go
@@ -0,0 +1,68 @@
package rdf2v1

import (
"spdx/tools-golang/v0/spdx"

"github.com/deltamobile/goraptor"
)

type CreationInfo struct {
SPDXIdentifier ValueStr
LicenseListVersion ValueStr
Creator []ValueStr
Create ValueStr
Comment ValueStr
}

func (p *Parser) requestCreationInfo(node goraptor.Term) (*CreationInfo, error) {

obj, err := p.requestElementType(node, typeCreationInfo)
if err != nil {
return nil, err
}
return obj.(*CreationInfo), err
}

func (p *Parser) MapCreationInfo(ci *CreationInfo) *builder {
builder := &builder{t: typeCreationInfo, ptr: ci}
builder.updaters = map[string]updater{
"licenseListVersion": update(&ci.LicenseListVersion),
"creator": updateList(&ci.Creator),
"created": update(&ci.Create),
"rdfs:comment": update(&ci.Comment),
}
return builder
}

func ExtractCreator(ci *CreationInfo, creator string) []string {

var val []string
for _, c := range ValueList(ci.Creator) {
subkey, subvalue, _ := extractSubs(c)
if subkey == creator {
val = append(val, subvalue)
}
}
return val
}
func InsertCreator(ci *spdx.CreationInfo2_1) []ValueStr {

var val []string
if len(ci.CreatorPersons) != 0 {
for _, person := range ci.CreatorPersons {
val = append(val, person)
}
}
if len(ci.CreatorOrganizations) != 0 {
for _, org := range ci.CreatorOrganizations {
val = append(val, org)
}
}
if len(ci.CreatorOrganizations) != 0 {
for _, org := range ci.CreatorOrganizations {
val = append(val, org)
}
}
valstr := ValueStrList(val)
return valstr
}
118 changes: 118 additions & 0 deletions v0/rdf/rdf2v1/Document.go
@@ -0,0 +1,118 @@
package rdf2v1

import (
"github.com/deltamobile/goraptor"
)

type Document struct {
SPDXVersion ValueStr
DataLicense ValueStr
CreationInfo *CreationInfo
Review []*Review
DocumentName ValueStr
DocumentNamespace ValueStr
SPDXID ValueStr
DocumentComment ValueStr
ExtractedLicensingInfo []*ExtractedLicensingInfo
Relationship []*Relationship
License *License
Annotation []*Annotation
ExternalDocumentRef *ExternalDocumentRef
}

type ExternalDocumentRef struct {
ExternalDocumentId ValueStr
Checksum *Checksum
SPDXDocument ValueStr
}

func (p *Parser) requestDocument(node goraptor.Term) (*Document, error) {
obj, err := p.requestElementType(node, typeDocument)
if err != nil {
return nil, err
}
return obj.(*Document), err
}

func (p *Parser) requestExternalDocumentRef(node goraptor.Term) (*ExternalDocumentRef, error) {
obj, err := p.requestElementType(node, typeExternalDocumentRef)
if err != nil {
return nil, err
}
return obj.(*ExternalDocumentRef), err
}

func (p *Parser) MapDocument(doc *Document) *builder {
builder := &builder{t: typeDocument, ptr: doc}
doc.DocumentNamespace = DocumentNamespace
builder.updaters = map[string]updater{
"specVersion": update(&doc.SPDXVersion),
// Example: gets CC0-1.0 from "http://spdx.org/licenses/CC0-1.0"
"dataLicense": func(obj goraptor.Term) error {
lic, err := p.requestLicense(obj)
doc.License = lic
return err
},
"creationInfo": func(obj goraptor.Term) error {
ci, err := p.requestCreationInfo(obj)
doc.CreationInfo = ci
return err
},
"reviewed": func(obj goraptor.Term) error {
rev, err := p.requestReview(obj)
if err != nil {
return err
}
doc.Review = append(doc.Review, rev)
return err
},
"name": update(&doc.DocumentName),
"rdfs:comment": update(&doc.DocumentComment),
"hasExtractedLicensingInfo": func(obj goraptor.Term) error {
eli, err := p.requestExtractedLicensingInfo(obj)
if err != nil {
return err
}
doc.ExtractedLicensingInfo = append(doc.ExtractedLicensingInfo, eli)
return nil
},
"relationship": func(obj goraptor.Term) error {
rel, err := p.requestRelationship(obj)
if err != nil {
return err
}
doc.Relationship = append(doc.Relationship, rel)
return nil
},
"annotation": func(obj goraptor.Term) error {
an, err := p.requestAnnotation(obj)
if err != nil {
return err
}
doc.Annotation = append(doc.Annotation, an)
return err
},
"externalDocumentRef": func(obj goraptor.Term) error {
edr, err := p.requestExternalDocumentRef(obj)
doc.ExternalDocumentRef = edr
return err
},
}
return builder
}

func (p *Parser) MapExternalDocumentRef(edr *ExternalDocumentRef) *builder {
builder := &builder{t: typeExternalDocumentRef, ptr: edr}
builder.updaters = map[string]updater{
"externalDocumentId": update(&edr.ExternalDocumentId),
"checksum": func(obj goraptor.Term) error {
cksum, err := p.requestChecksum(obj)

edr.Checksum = cksum
return err
},
"spdxDocument": update(&edr.SPDXDocument),
}
return builder

}
33 changes: 33 additions & 0 deletions v0/rdf/rdf2v1/ExtractedLicensingInfo.go
@@ -0,0 +1,33 @@
package rdf2v1

import (
"github.com/deltamobile/goraptor"
)

type ExtractedLicensingInfo struct {
LicenseIdentifier ValueStr
LicenseName []ValueStr
ExtractedText ValueStr
LicenseComment ValueStr
LicenseSeeAlso []ValueStr
}

func (p *Parser) requestExtractedLicensingInfo(node goraptor.Term) (*ExtractedLicensingInfo, error) {
obj, err := p.requestElementType(node, typeExtractedLicensingInfo)
if err != nil {
return nil, err
}
return obj.(*ExtractedLicensingInfo), err
}

func (p *Parser) MapExtractedLicensingInfo(lic *ExtractedLicensingInfo) *builder {
builder := &builder{t: typeExtractedLicensingInfo, ptr: lic}
builder.updaters = map[string]updater{
"licenseId": update(&lic.LicenseIdentifier),
"name": updateList(&lic.LicenseName),
"extractedText": update(&lic.ExtractedText),
"rdfs:comment": update(&lic.LicenseComment),
"rdfs:seeAlso": updateList(&lic.LicenseSeeAlso),
}
return builder
}

0 comments on commit 43938cc

Please sign in to comment.