Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Apr 26, 2024
1 parent e6de747 commit 77fda20
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 64 deletions.
5 changes: 4 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ var listCmd = &cobra.Command{
commonmeta list --number 10 --member 78 --type journal-article,
commonmeta list --number 10 --member cern.zenodo --type dataset`,
Run: func(cmd *cobra.Command, args []string) {
var input string
var str string // a string, content loaded from a file
var err error
var data []commonmeta.Data

input := args[0]
if len(args) > 0 {
input = args[0]
}
number, _ := cmd.Flags().GetInt("number")
from, _ := cmd.Flags().GetString("from")

Expand Down
25 changes: 13 additions & 12 deletions crossref/crossref.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,13 @@ func Load(filename string) (commonmeta.Data, error) {

// LoadList loads the metadata for a list of works from a JSON file and converts it to the Commonmeta format
func LoadList(filename string) ([]commonmeta.Data, error) {
var response []Content
var data []commonmeta.Data
// var err error
var content []Content
var err error

extension := path.Ext(filename)
if extension == ".jsonl" || extension == ".jsonlines" {
var response []Content
file, err := os.Open(filename)
if err != nil {
return nil, errors.New("error reading file")
Expand All @@ -408,14 +409,15 @@ func LoadList(filename string) ([]commonmeta.Data, error) {

decoder := json.NewDecoder(file)
for {
var content Content
if err := decoder.Decode(&content); err == io.EOF {
var c Content
if err := decoder.Decode(&c); err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
response = append(response, content)
response = append(response, c)
}
content = response
} else if extension == ".json" {
type Response struct {
Items []Content `json:"items"`
Expand All @@ -437,16 +439,15 @@ func LoadList(filename string) ([]commonmeta.Data, error) {
if err != nil {
return data, err
}
content = response.Items
} else {
return data, errors.New("unsupported file format")
}

log.Printf("Loaded %d items from %s", len(response), filename)

// data, err = ReadList(response.Items)
// if err != nil {
// return data, err
// }
data, err = ReadList(content)
if err != nil {
return data, err
}
return data, nil
}

Expand Down Expand Up @@ -553,7 +554,7 @@ func Read(content Content) (commonmeta.Data, error) {
Affiliations: affiliations,
}
containsName := slices.ContainsFunc(data.Contributors, func(e commonmeta.Contributor) bool {
return e.Name != "" && e.Name == contributor.Name || e.GivenName != "" && e.GivenName == contributor.GivenName && e.FamilyName != "" && e.FamilyName == contributor.FamilyName
return e.Name != "" && e.Name == contributor.Name || e.GivenName == contributor.GivenName && e.FamilyName != "" && e.FamilyName == contributor.FamilyName
})
if !containsName {
data.Contributors = append(data.Contributors, contributor)
Expand Down
47 changes: 15 additions & 32 deletions datacite/datacite.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ type Attributes struct {
DescriptionType string `json:"descriptionType"`
Lang string `json:"lang"`
} `json:"descriptions"`
GeoLocations []struct {
*GeoLocationPoint `json:"geoLocationPoint,omitempty"`
*GeoLocationBox `json:"geoLocationBox,omitempty"`
GeoLocationPlace string `json:"geoLocationPlace,omitempty"`
} `json:"geoLocations,omitempty"`
GeoLocations []GeoLocation `json:"geoLocations"`
FundingReferences []struct {
FunderName string `json:"funderName"`
FunderIdentifier string `json:"funderIdentifier"`
Expand All @@ -115,12 +111,14 @@ type Contributor struct {
NameIdentifier string `json:"nameIdentifier"`
NameIdentifierScheme string `json:"nameIdentifierScheme"`
} `json:"nameIdentifiers"`
Affiliation []struct {
AffiliationIdentifier string `json:"affiliationIdentifier"`
AffiliationIdentifierScheme string `json:"affiliationIdentifierScheme"`
Name string `json:"name"`
} `json:"affiliation"`
ContributorType string `json:"contributorType"`
Affiliation []string `json:"affiliation"`
ContributorType string `json:"contributorType"`
}

type GeoLocation struct {
GeoLocationPoint `json:"geoLocationPoint,omitempty"`
GeoLocationBox `json:"geoLocationBox,omitempty"`
GeoLocationPlace string `json:"geoLocationPlace,omitempty"`
}

type GeoLocationBox struct {
Expand Down Expand Up @@ -400,34 +398,21 @@ func Read(content Content) (commonmeta.Data, error) {
AwardURI: v.AwardURI,
})
}

for _, v := range content.Attributes.GeoLocations {
geoLocation := commonmeta.GeoLocation{
GeoLocationPlace: v.GeoLocationPlace,
}
if v.GeoLocationPoint.PointLongitude != 0 && v.GeoLocationPoint.PointLatitude != 0 {
geoLocation.GeoLocationPoint = commonmeta.GeoLocationPoint{
GeoLocationPoint: commonmeta.GeoLocationPoint{
PointLongitude: v.GeoLocationPoint.PointLongitude,
PointLatitude: v.GeoLocationPoint.PointLatitude,
}
}
if v.GeoLocationBox.WestBoundLongitude != 0 && v.GeoLocationBox.EastBoundLongitude != 0 && v.GeoLocationBox.SouthBoundLatitude != 0 && v.GeoLocationBox.NorthBoundLatitude != 0 {
geoLocation.GeoLocationBox = commonmeta.GeoLocationBox{
EastBoundLongitude: v.GeoLocationBox.EastBoundLongitude,
},
GeoLocationBox: commonmeta.GeoLocationBox{
WestBoundLongitude: v.GeoLocationBox.WestBoundLongitude,
EastBoundLongitude: v.GeoLocationBox.EastBoundLongitude,
SouthBoundLatitude: v.GeoLocationBox.SouthBoundLatitude,
NorthBoundLatitude: v.GeoLocationBox.NorthBoundLatitude,
}
} else {
geoLocation.GeoLocationBox = commonmeta.GeoLocationBox{
EastBoundLongitude: 0,
WestBoundLongitude: 0,
SouthBoundLatitude: 0,
NorthBoundLatitude: 0,
}
},
}
data.GeoLocations = append(data.GeoLocations, geoLocation)
//}
}

if len(content.Attributes.AlternateIdentifiers) > 0 {
Expand Down Expand Up @@ -603,10 +588,8 @@ func GetContributor(v Contributor) commonmeta.Contributor {
}
var affiliations []commonmeta.Affiliation
for _, a := range v.Affiliation {
id := utils.NormalizeROR(a.AffiliationIdentifier)
affiliations = append(affiliations, commonmeta.Affiliation{
ID: id,
Name: a.Name,
Name: a,
})
}
var roles []string
Expand Down
2 changes: 0 additions & 2 deletions datacite/testdata/10.4230_lipics.tqc.2013.93.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
"publisher": { "name": "Schloss Dagstuhl – Leibniz-Zentrum für Informatik" },
"relations": [
{ "id": "https://doi.org/10.4230/lipics.tqc.2013", "type": "IsPartOf" },
{ "id": "978-3-939897-55-2", "type": "IsPartOf" },
{ "id": "1868-8969", "type": "IsPartOf" }
],
"subjects": [
{
Expand Down
28 changes: 11 additions & 17 deletions schemautils/schemas/commonmeta_v0.13.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@
],
"type": "string"
},
"geoLocationBox": {
"type": "object",
"properties": {
"westBoundLongitude": { "$ref": "#/definitions/longitude" },
"eastBoundLongitude": { "$ref": "#/definitions/longitude" },
"southBoundLatitude": { "$ref": "#/definitions/latitude" },
"northBoundLatitude": { "$ref": "#/definitions/latitude" }
}
},
"geoLocationPoint": {
"type": "object",
"properties": {
"pointLongitude": { "$ref": "#/definitions/longitude" },
"pointLatitude": { "$ref": "#/definitions/latitude" }
},
"required": ["pointLongitude", "pointLatitude"]
}
},
"id": {
"description": "The unique identifier for the resource.",
Expand Down Expand Up @@ -369,21 +377,7 @@
"properties": {
"geoLocationPlace": { "type": "string" },
"geoLocationPoint": { "$ref": "#/definitions/geoLocationPoint" },
"geoLocationBox": {
"type": "object",
"properties": {
"westBoundLongitude": { "$ref": "#/definitions/longitude" },
"eastBoundLongitude": { "$ref": "#/definitions/longitude" },
"southBoundLatitude": { "$ref": "#/definitions/latitude" },
"northBoundLatitude": { "$ref": "#/definitions/latitude" }
},
"required": [
"westBoundLongitude",
"eastBoundLongitude",
"southBoundLatitude",
"northBoundLatitude"
]
},
"geoLocationBox": { "$ref": "#/definitions/geoLocationBox" },
"geoLocationPolygons": {
"type": "array",
"items": {
Expand Down

0 comments on commit 77fda20

Please sign in to comment.