From 087289fd27fe2f88d04c2907a02ed597b488d9a9 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 15 May 2024 19:00:18 +0200 Subject: [PATCH] fix crossrefxml reference parsing --- cmd/version.go | 2 +- crossrefxml/reader.go | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 7e36afc..3145a8f 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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.13 -- HEAD") + cmd.Println("Commonmeta v0.3.14 -- HEAD") }, } diff --git a/crossrefxml/reader.go b/crossrefxml/reader.go index 4226ebc..88ec196 100644 --- a/crossrefxml/reader.go +++ b/crossrefxml/reader.go @@ -1116,18 +1116,24 @@ func Read(query Query) (commonmeta.Data, error) { if len(citationList.Citation) > 0 { for _, v := range citationList.Citation { - reference := commonmeta.Reference{ - Key: v.Key, - ID: doiutils.NormalizeDOI(v.DOI.Text), - Title: v.ArticleTitle, - PublicationYear: v.CYear, - Unstructured: v.UnstructedCitation, + var id string + if v.DOI != nil { + id = doiutils.NormalizeDOI(v.DOI.Text) } - containsKey := slices.ContainsFunc(data.References, func(e commonmeta.Reference) bool { - return e.Key != "" && e.Key == reference.Key - }) - if !containsKey { - data.References = append(data.References, reference) + if id != "" { + reference := commonmeta.Reference{ + Key: v.Key, + ID: id, + Title: v.ArticleTitle, + PublicationYear: v.CYear, + Unstructured: v.UnstructedCitation, + } + containsKey := slices.ContainsFunc(data.References, func(e commonmeta.Reference) bool { + return e.Key != "" && e.Key == reference.Key + }) + if !containsKey { + data.References = append(data.References, reference) + } } } } @@ -1309,7 +1315,6 @@ func GetContributors(contrib Contributors) ([]commonmeta.Contributor, error) { if len(contrib.PersonName) > 0 { for _, v := range contrib.PersonName { - fmt.Print(v.Affiliations) var ID string if v.GivenName != "" || v.Surname != "" { if v.ORCID != "" { @@ -1317,9 +1322,9 @@ func GetContributors(contrib Contributors) ([]commonmeta.Contributor, error) { } } Type := "Person" - if len(v.Affiliations.Institution) > 0 || v.Affiliation != "" { + if v.Affiliations != nil || v.Affiliation != "" { var affiliations []*commonmeta.Affiliation - if len(v.Affiliations.Institution) > 0 { + if v.Affiliations != nil { for _, i := range v.Affiliations.Institution { if i.InstitutionName != "" { if i.InstitutionID != nil && i.InstitutionID.Text != "" {