Skip to content

Commit

Permalink
include references in schemaorg writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 1, 2024
1 parent d9eb38e commit b35e1e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Commonmeta reads and/or writes these metadata formats:
| [CrossRef XML](https://www.crossref.org/schema/documentation/unixref1.1/unixref1.1.html) | crossrefxml | application/vnd.crossref.unixref+xml | later | later |
| [Crossref](https://api.crossref.org) | crossref | application/vnd.crossref+json | yes | n/a |
| [DataCite](https://api.datacite.org/) | datacite | application/vnd.datacite.datacite+json | yes | yes |
| [Schema.org (in JSON-LD)](http://schema.org/) | schemaorg | application/vnd.schemaorg.ld+json | later | later |
| [Schema.org (in JSON-LD)](http://schema.org/) | schemaorg | application/vnd.schemaorg.ld+json | later | yes |
| [RDF XML](http://www.w3.org/TR/rdf-syntax-grammar/) | rdf | application/rdf+xml | no | later |
| [RDF Turtle](http://www.w3.org/TeamSubmission/turtle/) | turtle | text/turtle | no | later |
| [CSL-JSON](https://citationstyles.org/) | csl | application/vnd.citationstyles.csl+json | later | yes |
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of commonmeta",
Long: `All software has versions. This is commonmeta's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Commonmeta v0.2.5 -- HEAD")
fmt.Println("Commonmeta v0.2.7 -- HEAD")
},
}

Expand Down
30 changes: 27 additions & 3 deletions schemaorg/schemaorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SchemaOrg struct {
Type string `json:"@type"`
AdditionalType string `json:"additionalType,omitempty"`
Author []Author `json:"author,omitempty"`
Citation []Citation `json:"citation,omitempty"`
CodeRepository string `json:"codeRepository,omitempty"`
DateCreated string `json:"dateCreated,omitempty"`
DatePublished string `json:"datePublished,omitempty"`
Expand Down Expand Up @@ -60,6 +61,13 @@ type Author struct {
Affiliations []Organization `json:"affiliations,omitempty"`
}

// Citation represents a citation or reference to another creative work, such as another publication, web page, scholarly article, etc.
type Citation struct {
ID string `json:"@id,omitempty"`
Type string `json:"@type,omitempty"`
Name string `json:"name,omitempty"`
}

// Coderepository
type CodeRepository struct {
}
Expand Down Expand Up @@ -211,6 +219,20 @@ func Convert(data commonmeta.Data) (SchemaOrg, error) {
}
}

if len(data.References) > 0 {
for _, reference := range data.References {
t := "CreativeWork"
if reference.Type == "JournalArticle" {
t = "ScholarlyArticle"
}
schemaorg.Citation = append(schemaorg.Citation, Citation{
ID: reference.ID,
Type: t,
Name: reference.Title,
})
}
}

if data.Type == "Dataset" {
schemaorg.IncludedInDataCatalog = DataCatalog{
ID: data.Container.Identifier,
Expand Down Expand Up @@ -261,9 +283,11 @@ func Convert(data commonmeta.Data) (SchemaOrg, error) {
schemaorg.Encoding = mediaObjects
}

schemaorg.Identifier = []string{}
for _, identifier := range data.Identifiers {
schemaorg.Identifier = append(schemaorg.Identifier, identifier.Identifier)
if len(data.Identifiers) > 0 {
schemaorg.Identifier = []string{}
for _, identifier := range data.Identifiers {
schemaorg.Identifier = append(schemaorg.Identifier, identifier.Identifier)
}
}
schemaorg.InLanguage = data.Language
if len(data.Subjects) > 0 {
Expand Down

0 comments on commit b35e1e8

Please sign in to comment.