Skip to content

Commit

Permalink
handle missing affiliations
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 15, 2024
1 parent 1e29ed5 commit ff814e6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 57 deletions.
14 changes: 7 additions & 7 deletions commonmeta/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ type Container struct {

// Contributor represents a contributor of a publication, defined in the commonmeta JSON Schema.
type Contributor struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
GivenName string `json:"givenName,omitempty"`
FamilyName string `json:"familyName,omitempty"`
Affiliations []Affiliation `json:"affiliations,omitempty"`
ContributorRoles []string `json:"contributorRoles,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
GivenName string `json:"givenName,omitempty"`
FamilyName string `json:"familyName,omitempty"`
Affiliations []*Affiliation `json:"affiliations,omitempty"`
ContributorRoles []string `json:"contributorRoles,omitempty"`
}

// Date represents the date of a publication, defined in the commonmeta JSON Schema.
Expand Down
4 changes: 2 additions & 2 deletions crossref/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ func Read(content Content) (commonmeta.Data, error) {
} else {
Type = "Person"
}
var affiliations []commonmeta.Affiliation
var affiliations []*commonmeta.Affiliation
if len(v.Affiliation) > 0 {
for _, a := range v.Affiliation {
var ID string
if len(a.ID) > 0 && a.ID[0].IDType == "ROR" {
ID = utils.NormalizeROR(a.ID[0].ID)
}
if a.Name != "" {
affiliations = append(affiliations, commonmeta.Affiliation{
affiliations = append(affiliations, &commonmeta.Affiliation{
ID: ID,
Name: a.Name,
})
Expand Down
91 changes: 49 additions & 42 deletions crossrefxml/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,15 @@ type PeerReview struct {

// PersonName represents a person in Crossref XML metadata.
type PersonName struct {
XMLName xml.Name `xml:"person_name"`
ContributorRole string `xml:"contributor_role,attr"`
Sequence string `xml:"sequence,attr"`
Text string `xml:",chardata"`
GivenName string `xml:"given_name"`
Surname string `xml:"surname"`
Affiliations Affiliations `xml:"affiliations,omitempty"`
Affiliation string `xml:"affiliation,omitempty"`
ORCID string `xml:"ORCID,omitempty"`
XMLName xml.Name `xml:"person_name"`
ContributorRole string `xml:"contributor_role,attr"`
Sequence string `xml:"sequence,attr"`
Text string `xml:",chardata"`
GivenName string `xml:"given_name"`
Surname string `xml:"surname"`
Affiliations *Affiliations `xml:"affiliations,omitempty"`
Affiliation string `xml:"affiliation,omitempty"`
ORCID string `xml:"ORCID,omitempty"`
}

// PostedContent represents posted content in Crossref XML metadata.
Expand Down Expand Up @@ -1309,49 +1309,56 @@ 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 != "" {
ID, _ = utils.NormalizeURL(v.ORCID, true, false) // enforce HTTPS
}
}
Type := "Person"
var affiliations []commonmeta.Affiliation
if len(v.Affiliations.Institution) > 0 {
for _, i := range v.Affiliations.Institution {
if i.InstitutionName != "" {
if i.InstitutionID != nil && i.InstitutionID.Text != "" {
ID = utils.NormalizeROR(i.InstitutionID.Text)
affiliations = append(affiliations, commonmeta.Affiliation{
ID: ID,
Name: i.InstitutionName,
})
} else {
affiliations = append(affiliations, commonmeta.Affiliation{
Name: i.InstitutionName,
})
if len(v.Affiliations.Institution) > 0 || v.Affiliation != "" {
var affiliations []*commonmeta.Affiliation
if len(v.Affiliations.Institution) > 0 {
for _, i := range v.Affiliations.Institution {
if i.InstitutionName != "" {
if i.InstitutionID != nil && i.InstitutionID.Text != "" {
ID = utils.NormalizeROR(i.InstitutionID.Text)
affiliations = append(affiliations, &commonmeta.Affiliation{
ID: ID,
Name: i.InstitutionName,
})
} else {
affiliations = append(affiliations, &commonmeta.Affiliation{
Name: i.InstitutionName,
})
}
}
}
} else if v.Affiliation != "" {
affiliations = append(affiliations, &commonmeta.Affiliation{
Name: v.Affiliation,
})
}
contributor := commonmeta.Contributor{
ID: ID,
Type: Type,
GivenName: v.GivenName,
FamilyName: v.Surname,
Name: "",
ContributorRoles: []string{"Author"},
Affiliations: affiliations,
}
contributors = append(contributors, contributor)
} else {
contributor := commonmeta.Contributor{
ID: ID,
Type: Type,
GivenName: v.GivenName,
FamilyName: v.Surname,
Name: "",
ContributorRoles: []string{"Author"},
}
} else if v.Affiliation != "" {
affiliations = append(affiliations, commonmeta.Affiliation{
Name: v.Affiliation,
})
}

contributor := commonmeta.Contributor{
ID: ID,
Type: Type,
GivenName: v.GivenName,
FamilyName: v.Surname,
Name: "",
ContributorRoles: []string{"Author"},
Affiliations: affiliations,
}
containsName := slices.ContainsFunc(contributors, func(e commonmeta.Contributor) bool {
return e.GivenName == contributor.GivenName && e.FamilyName != "" && e.FamilyName == contributor.FamilyName
})
if !containsName {
contributors = append(contributors, contributor)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crossrefxml/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Convert(data commonmeta.Data) (Body, error) {
ORCID: contributor.ID,
GivenName: contributor.GivenName,
Surname: contributor.FamilyName,
Affiliations: affiliations,
Affiliations: &affiliations,
})
} else {
personName = append(personName, PersonName{
Expand Down
6 changes: 3 additions & 3 deletions datacite/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ func GetContributor(v ContentContributor) commonmeta.Contributor {
//parse Affiliation as either slice of string or slice of struct
var affiliationStructs []Affiliation
var affiliationNames []string
var affiliations []commonmeta.Affiliation
var affiliations []*commonmeta.Affiliation
var err error
err = json.Unmarshal(v.Affiliation, &affiliationNames)
if err != nil {
Expand All @@ -691,13 +691,13 @@ func GetContributor(v ContentContributor) commonmeta.Contributor {
ID: id,
Name: v.Name,
}
affiliations = append(affiliations, af)
affiliations = append(affiliations, &af)
}
} else if len(affiliationNames) > 0 {
af := commonmeta.Affiliation{
Name: affiliationNames[0],
}
affiliations = append(affiliations, af)
affiliations = append(affiliations, &af)
}

var roles []string
Expand Down
4 changes: 2 additions & 2 deletions jsonfeed/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ func GetContributors(contrib Authors) ([]commonmeta.Contributor, error) {
Type = "Organization"
}

var affiliations []commonmeta.Affiliation
var affiliations []*commonmeta.Affiliation
if len(v.Affiliation) > 0 {
for _, a := range v.Affiliation {
if a.Name != "" {
affiliations = append(affiliations, commonmeta.Affiliation{
affiliations = append(affiliations, &commonmeta.Affiliation{
ID: a.ID,
Name: a.Name,
})
Expand Down

0 comments on commit ff814e6

Please sign in to comment.