Skip to content

Commit

Permalink
support crossrefxml organization contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Jun 11, 2024
1 parent e7c9b56 commit 09f3ea7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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) {
cmd.Println("Commonmeta v0.3.19 -- HEAD")
cmd.Println("Commonmeta v0.3.20 -- HEAD")
},
}

Expand Down
14 changes: 12 additions & 2 deletions crossrefxml/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ type CreationDate struct {
}

type Contributors struct {
XMLName xml.Name `xml:"contributors"`
PersonName []PersonName `xml:"person_name"`
XMLName xml.Name `xml:"contributors"`
Organization []Organization `xml:"organization,omitempty"`
PersonName []PersonName `xml:"person_name,omitempty"`
}

type Crossmark struct {
Expand Down Expand Up @@ -449,6 +450,15 @@ type LicenseRef struct {
AppliesTo string `xml:"applies_to,attr"`
}

// OrganizationName represents an organization in Crossref XML metadata.
type Organization struct {
XMLName xml.Name `xml:"organization"`
ContributorRole string `xml:"contributor_role,attr"`
Sequence string `xml:"sequence,attr"`
Text string `xml:",chardata"`
Name string `xml:"name"`
}

type OriginalLanguageTitle struct {
Text string `xml:",chardata"`
Language string `xml:"language,attr"`
Expand Down
87 changes: 50 additions & 37 deletions crossrefxml/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,53 +96,63 @@ func Convert(data commonmeta.Data) (Body, error) {
}
}
personName := []PersonName{}
organization := []Organization{}
if len(data.Contributors) > 0 {
for i, contributor := range data.Contributors {
contributorRole := "author"
sequence := "first"
if i > 0 {
sequence = "additional"
}
if len(contributor.Affiliations) > 0 {
institution := []Institution{}
for _, a := range contributor.Affiliations {
if a.Name != "" {
if a.ID != "" {
institutionID := InstitutionID{
Type: "ror",
Text: a.ID,
}
institution = append(institution, Institution{
InstitutionID: &institutionID,
InstitutionName: a.Name,
})
} else {
institution = append(institution, Institution{
InstitutionName: a.Name,
})
}
}
}
affiliations := Affiliations{
Institution: institution,
}
personName = append(personName, PersonName{
if contributor.Type == "Organization" {
organization = append(organization, Organization{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
Affiliations: &affiliations,
Name: contributor.Name,
})
} else {
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
})
if len(contributor.Affiliations) > 0 {
institution := []Institution{}
for _, a := range contributor.Affiliations {
if a.Name != "" {
if a.ID != "" {
institutionID := InstitutionID{
Type: "ror",
Text: a.ID,
}
institution = append(institution, Institution{
InstitutionID: &institutionID,
InstitutionName: a.Name,
})
} else {
institution = append(institution, Institution{
InstitutionName: a.Name,
})
}
}
}
affiliations := Affiliations{
Institution: institution,
}
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
Affiliations: &affiliations,
})
} else {
personName = append(personName, PersonName{
ContributorRole: contributorRole,
Sequence: sequence,
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
})
}
}

}
}

Expand Down Expand Up @@ -353,7 +363,9 @@ func Convert(data commonmeta.Data) (Body, error) {
Language: data.Language,
GroupTitle: groupTitle,
Contributors: Contributors{
PersonName: personName},
Organization: organization,
PersonName: personName,
},
Titles: titles,
PostedDate: postedDate,
Institution: institution,
Expand Down Expand Up @@ -393,7 +405,8 @@ func Convert(data commonmeta.Data) (Body, error) {
// ArchiveLocations: ArchiveLocations{}
CitationList: citationList,
Contributors: Contributors{
PersonName: personName},
Organization: organization,
PersonName: personName},
// Crossmark: Crossmark{
// CustomMetadata: customMetadata,
// },
Expand Down
41 changes: 41 additions & 0 deletions crossrefxml/writer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package crossrefxml_test

// func TestConvert(t *testing.T) {
// t.Parallel()

// type testCase struct {
// id string
// want string
// err error
// }

// journalArticle := crossrefxml.DOIData{
// DOI: "10.7554/elife.01567",
// Resource: "https://elifesciences.org/articles/01567",
// }
// postedContent := crossrefxml.DOIData{
// DOI: "10.1101/097196",
// Resource: "http://biorxiv.org/lookup/doi/10.1101/097196",
// }

// testCases := []testCase{
// {id: journalArticle.DOI, want: journalArticle.Resource, err: nil},
// {id: postedContent.DOI, want: postedContent.Resource, err: nil},
// }
// for _, tc := range testCases {
// got, err := crossrefxml.Convert(tc.id)
// if err != nil {
// t.Errorf("Get (%v): error %v", tc.id, err)
// }
// var resource string
// if got.DOI.Type == "journal-article" {
// resource = got.DOIRecord.Crossref.Journal.JournalArticle.DOIData.Resource
// } else if got.DOI.Type == "posted-content" {
// resource = got.DOIRecord.Crossref.PostedContent.DOIData.Resource
// }
// if tc.want != resource {
// t.Errorf("Get (%v): want %v, got %v, error %v",
// tc.id, tc.want, got, err)
// }
// }
// }

0 comments on commit 09f3ea7

Please sign in to comment.