commonmeta-py 0.17.1__tar.gz → 0.17.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/PKG-INFO +1 -1
  2. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/author_utils.py +4 -1
  3. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/crossref_utils.py +14 -11
  4. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/crossref_reader.py +25 -16
  5. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/datacite_reader.py +32 -19
  6. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/datacite_xml_reader.py +41 -7
  7. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/commonmeta_v0.13.json +0 -2
  8. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/commonmeta_writer.py +1 -0
  9. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/datacite_writer.py +14 -5
  10. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/pyproject.toml +1 -1
  11. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/LICENSE +0 -0
  12. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/README.md +0 -0
  13. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/__init__.py +0 -0
  14. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/api_utils.py +0 -0
  15. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/base_utils.py +0 -0
  16. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/cli.py +0 -0
  17. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/constants.py +0 -0
  18. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/date_utils.py +0 -0
  19. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/doi_utils.py +0 -0
  20. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/metadata.py +15 -15
  21. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/__init__.py +0 -0
  22. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/bibtex_reader.py +0 -0
  23. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/cff_reader.py +0 -0
  24. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/codemeta_reader.py +0 -0
  25. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/commonmeta_reader.py +0 -0
  26. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/crossref_xml_reader.py +0 -0
  27. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/csl_reader.py +0 -0
  28. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/inveniordm_reader.py +0 -0
  29. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/json_feed_reader.py +0 -0
  30. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/kbase_reader.py +0 -0
  31. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/ris_reader.py +0 -0
  32. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/readers/schema_org_reader.py +0 -0
  33. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/cff_v1.2.0.json +0 -0
  34. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/commonmeta_v0.12.json +0 -0
  35. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/AccessIndicators.xsd +0 -0
  36. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3-elements.xsd +0 -0
  37. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3.xsd +0 -0
  38. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1-elements.xsd +0 -0
  39. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1-mathml3-elements.xsd +0 -0
  40. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1-mathml3.xsd +0 -0
  41. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/JATS-journalpublishing1.xsd +0 -0
  42. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/clinicaltrials.xsd +0 -0
  43. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/common5.3.1.xsd +0 -0
  44. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/crossref5.3.1.xsd +0 -0
  45. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/crossref_query_output3.0.xsd +0 -0
  46. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/fundref.xsd +0 -0
  47. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/module-ali.xsd +0 -0
  48. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref/relations.xsd +0 -0
  49. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/crossref-v0.2.json +0 -0
  50. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/csl-data.json +0 -0
  51. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/datacite-v4.5.json +0 -0
  52. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/ietf-bcp-47.json +0 -0
  53. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/iso-8601.json +0 -0
  54. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/spdx/licenses.json +0 -0
  55. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/spdx-schema..json +0 -0
  56. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/apa.csl +0 -0
  57. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/chicago-author-date.csl +0 -0
  58. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/harvard-cite-them-right.csl +0 -0
  59. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/ieee.csl +0 -0
  60. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/modern-language-association.csl +0 -0
  61. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/resources/styles/vancouver.csl +0 -0
  62. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/schema_utils.py +0 -0
  63. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/translators.py +0 -0
  64. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/utils.py +0 -0
  65. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/__init__.py +0 -0
  66. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/bibtex_writer.py +0 -0
  67. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/citation_writer.py +0 -0
  68. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/crossref_xml_writer.py +0 -0
  69. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/csl_writer.py +0 -0
  70. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/ris_writer.py +0 -0
  71. {commonmeta_py-0.17.1 → commonmeta_py-0.17.3}/commonmeta/writers/schema_org_writer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commonmeta-py
3
- Version: 0.17.1
3
+ Version: 0.17.3
4
4
  Summary: Library for conversions to/from the Commonmeta scholarly metadata format
5
5
  Home-page: https://python.commonmeta.org
6
6
  License: MIT
@@ -108,6 +108,9 @@ def get_one_author(author, **kwargs):
108
108
  else:
109
109
  given_name = None
110
110
  family_name = None
111
+
112
+ # support various keys for affiliations
113
+ affiliations = author.get("affiliation", None) or author.get("affiliations", None)
111
114
 
112
115
  # return author in commonmeta format, using name vs. given/family name
113
116
  # depending on type
@@ -119,7 +122,7 @@ def get_one_author(author, **kwargs):
119
122
  "name": name if _type == "Organization" else None,
120
123
  "givenName": given_name if _type == "Person" else None,
121
124
  "familyName": family_name if _type == "Person" else None,
122
- "affiliation": presence(get_affiliations(wrap(author.get("affiliation", None)))
125
+ "affiliations": presence(get_affiliations(wrap(affiliations))
123
126
  ),
124
127
  }
125
128
  )
@@ -131,8 +131,12 @@ def insert_crossref_contributors(metadata, xml):
131
131
  ]
132
132
  for num, contributor in enumerate(con):
133
133
  contributor_role = (
134
- "author" if contributor.get("contributorRoles") == ["Author"] else "editor"
134
+ "author" if "Author" in contributor.get("contributorRoles") else None
135
135
  )
136
+ if contributor_role is None:
137
+ contributor_role = (
138
+ "editor" if "Editor" in contributor.get("contributorRoles") else None
139
+ )
136
140
  sequence = "first" if num == 0 else "additional"
137
141
  if (
138
142
  contributor.get("type", None) == "Organization"
@@ -153,7 +157,7 @@ def insert_crossref_contributors(metadata, xml):
153
157
  {"contributor_role": contributor_role, "sequence": sequence},
154
158
  )
155
159
  person_name = insert_crossref_person(contributor, person_name)
156
- elif contributor.get("affiliation", None) is not None:
160
+ elif contributor.get("affiliations", None) is not None:
157
161
  anonymous = etree.SubElement(
158
162
  contributors,
159
163
  "anonymous",
@@ -176,18 +180,17 @@ def insert_crossref_person(contributor, xml):
176
180
  if contributor.get("familyName", None) is not None:
177
181
  etree.SubElement(xml, "surname").text = contributor.get("familyName")
178
182
 
179
- if contributor.get("affiliation", None) is not None:
183
+ if contributor.get("affiliations", None) is not None:
180
184
  affiliations = etree.SubElement(xml, "affiliations")
181
185
  institution = etree.SubElement(affiliations, "institution")
182
- if py_.get(contributor, "affiliation.0.name") is not None:
186
+ if py_.get(contributor, "affiliations.0.name") is not None:
183
187
  etree.SubElement(institution, "institution_name").text = py_.get(
184
- contributor, "affiliation.0.name"
188
+ contributor, "affiliations.0.name"
185
189
  )
186
- if py_.get(contributor, "affiliation.0.id") is not None:
190
+ if py_.get(contributor, "affiliations.0.id") is not None:
187
191
  etree.SubElement(
188
192
  institution, "institution_id", {"type": "ror"}
189
- ).text = py_.get(contributor, "affiliation.0.id")
190
-
193
+ ).text = py_.get(contributor, "affiliations.0.id")
191
194
  orcid = normalize_orcid(contributor.get("id", None))
192
195
  if orcid is not None:
193
196
  etree.SubElement(xml, "ORCID").text = orcid
@@ -196,13 +199,13 @@ def insert_crossref_person(contributor, xml):
196
199
 
197
200
  def insert_crossref_anonymous(contributor, xml):
198
201
  """Insert crossref anonymous"""
199
- if contributor.get("affiliation", None) is None:
202
+ if contributor.get("affiliations", None) is None:
200
203
  return xml
201
204
  affiliations = etree.SubElement(xml, "affiliations")
202
205
  institution = etree.SubElement(affiliations, "institution")
203
- if py_.get(contributor, "affiliation.0.name") is not None:
206
+ if py_.get(contributor, "affiliations.0.name") is not None:
204
207
  etree.SubElement(institution, "institution_name").text = py_.get(
205
- contributor, "affiliation.0.name"
208
+ contributor, "affiliations.0.name"
206
209
  )
207
210
  return xml
208
211
 
@@ -65,6 +65,8 @@ def read_crossref(data: Optional[dict], **kwargs) -> Commonmeta:
65
65
  _id = doi_as_url(doi)
66
66
  _type = CR_TO_CM_TRANSLATIONS.get(meta.get("type", None)) or "Other"
67
67
 
68
+ archive_locations = wrap(meta.get("archive", None))
69
+
68
70
  if meta.get("author", None):
69
71
  contributors = get_authors(wrap(meta.get("author")), via="crossref")
70
72
  else:
@@ -89,7 +91,15 @@ def read_crossref(data: Optional[dict], **kwargs) -> Commonmeta:
89
91
  or py_.get(meta, "created.date-time")
90
92
  }
91
93
  )
92
-
94
+ identifiers = []
95
+ identifiers.append(
96
+ compact(
97
+ {
98
+ "identifier": _id,
99
+ "identifierType": "DOI",
100
+ }
101
+ )
102
+ )
93
103
  license_ = meta.get("license", None)
94
104
  if license_ is not None:
95
105
  license_ = normalize_cc_url(license_[0].get("URL", None))
@@ -133,27 +143,26 @@ def read_crossref(data: Optional[dict], **kwargs) -> Commonmeta:
133
143
  "id": _id,
134
144
  "type": _type,
135
145
  # recommended and optional properties
136
- "url": url,
146
+ "additionalType": None,
147
+ "archiveLocations": presence(archive_locations),
148
+ "container": presence(container),
137
149
  "contributors": presence(contributors),
138
- "titles": presence(titles),
139
- "publisher": presence(publisher),
140
150
  "date": presence(date),
141
- "additionalType": None,
142
- "subjects": presence(subjects),
151
+ "descriptions": presence(descriptions),
152
+ "files": presence(files),
153
+ "fundingReferences": presence(funding_references),
154
+ "geoLocations": None,
155
+ "identifiers": identifiers,
143
156
  "language": meta.get("language", None),
144
- "identifiers": None,
145
- "sizes": None,
146
- "formats": None,
147
- "version": meta.get("version", None),
148
157
  "license": license_,
149
- "descriptions": descriptions,
150
- "geoLocations": None,
151
- "fundingReferences": presence(funding_references),
158
+ "provider": "Crossref",
159
+ "publisher": presence(publisher),
152
160
  "references": presence(references),
153
161
  "relations": presence(relations),
154
- "files": presence(files),
155
- "container": presence(container),
156
- "provider": "Crossref",
162
+ "subjects": presence(subjects),
163
+ "titles": presence(titles),
164
+ "url": url,
165
+ "version": meta.get("version", None),
157
166
  } | read_options
158
167
 
159
168
 
@@ -84,6 +84,15 @@ def read_datacite(data: dict, **kwargs) -> Commonmeta:
84
84
  files = [get_file(i) for i in wrap(meta.get("content_url"))]
85
85
 
86
86
  identifiers = get_identifiers(wrap(meta.get("alternateIdentifiers", None)))
87
+ identifiers.append(
88
+ compact(
89
+ {
90
+ "identifier": normalize_doi(_id),
91
+ "identifierType": "DOI",
92
+ }
93
+ )
94
+ )
95
+
87
96
  references = get_references(
88
97
  wrap(meta.get("relatedItems", None) or meta.get("relatedIdentifiers", None))
89
98
  )
@@ -104,28 +113,26 @@ def read_datacite(data: dict, **kwargs) -> Commonmeta:
104
113
  # required properties
105
114
  "id": _id,
106
115
  "type": _type,
107
- "doi": doi_from_url(_id),
108
- "url": normalize_url(meta.get("url", None)),
109
- "contributors": presence(contributors),
110
- "titles": titles,
111
- "publisher": publisher,
112
- "date": compact(date),
113
116
  # recommended and optional properties
114
117
  "additionalType": additional_type,
115
- "subjects": presence(subjects),
116
- "language": meta.get("language", None),
118
+ "container": presence(container),
119
+ "contributors": presence(contributors),
120
+ "date": compact(date),
121
+ "descriptions": presence(descriptions),
122
+ "files": presence(files),
123
+ "fundingReferences": presence(meta.get("fundingReferences", None)),
124
+ "geoLocations": presence(geo_locations),
117
125
  "identifiers": presence(identifiers),
118
- "version": meta.get("version", None),
126
+ "language": meta.get("language", None),
119
127
  "license": presence(license_),
120
- "descriptions": descriptions,
121
- "geoLocations": presence(geo_locations),
122
- "fundingReferences": presence(meta.get("fundingReferences", None)),
128
+ "provider": "DataCite",
129
+ "publisher": publisher,
123
130
  "references": presence(references),
124
131
  "relations": presence(relations),
125
- # other properties
126
- "files": presence(files),
127
- "container": presence(container),
128
- "provider": "DataCite",
132
+ "subjects": presence(subjects),
133
+ "titles": presence(titles),
134
+ "url": normalize_url(meta.get("url", None)),
135
+ "version": meta.get("version", None),
129
136
  } | read_options
130
137
 
131
138
 
@@ -176,11 +183,16 @@ def get_references(references: list) -> list:
176
183
  """map_reference"""
177
184
  identifier = reference.get("relatedIdentifier", None)
178
185
  identifier_type = reference.get("relatedIdentifierType", None)
186
+ if identifier_type == "DOI":
187
+ id_ = normalize_doi(identifier)
188
+ elif identifier_type == "URL":
189
+ id_ = normalize_url(identifier)
190
+ else:
191
+ id_ = identifier
179
192
  return compact(
180
193
  {
181
194
  "key": f"ref{index + 1}",
182
- "doi": normalize_doi(identifier) if identifier_type == "DOI" else None,
183
- "url": normalize_url(identifier) if identifier_type == "URL" else None,
195
+ "id": id_,
184
196
  }
185
197
  )
186
198
 
@@ -214,7 +226,8 @@ def get_relations(relations: list) -> list:
214
226
 
215
227
  def map_relation(relation):
216
228
  """map_relation"""
217
- identifier = relation.get("relatedIdentifier", None)
229
+
230
+ identifier = normalize_doi(relation.get("relatedIdentifier", None)) or relation.get("relatedIdentifier", None)
218
231
  relation_type = relation.get("relationType", None)
219
232
  return compact(
220
233
  {
@@ -35,16 +35,13 @@ def read_datacite_xml(data: dict, **kwargs) -> Commonmeta:
35
35
 
36
36
  doi = parse_attributes(meta.get("identifier", None))
37
37
  _id = doi_as_url(doi) if doi else None
38
- # identifiers = Array.wrap(meta.dig('alternateIdentifiers', 'alternateIdentifier')).map do |r|
39
- # if r['__content__'].present?
40
- # { 'identifierType' => get_identifier_type(r['alternateIdentifierType']),
41
- # 'identifier' => r['__content__'] }
42
- # end
43
- # end.compact
44
38
 
45
39
  resource__typegeneral = py_.get(meta, "resourceType.resourceTypeGeneral")
46
40
  _type = DC_TO_CM_TRANSLATIONS.get(resource__typegeneral, "Other")
47
41
  additional_type = py_.get(meta, "resourceType.#text")
42
+
43
+ identifiers = wrap(py_.get(meta, "alternateIdentifiers.alternateIdentifier"))
44
+ identifiers = get_xml_identifiers(identifiers)
48
45
 
49
46
  def format_title(title):
50
47
  """format_title"""
@@ -218,7 +215,7 @@ def read_datacite_xml(data: dict, **kwargs) -> Commonmeta:
218
215
  "additionalType": presence(additional_type),
219
216
  "subjects": presence(subjects),
220
217
  "language": meta.get("language", None),
221
- "identifiers": presence(meta.get("alternateIdentifiers", None)),
218
+ "identifiers": identifiers,
222
219
  "version": meta.get("version", None),
223
220
  "license": presence(license_),
224
221
  "descriptions": presence(descriptions),
@@ -239,6 +236,43 @@ def read_datacite_xml(data: dict, **kwargs) -> Commonmeta:
239
236
  } | read_options
240
237
 
241
238
 
239
+ def get_xml_identifiers(identifiers: list) -> list:
240
+ """get_identifiers"""
241
+
242
+ def is_identifier(identifier):
243
+ """supported identifier types"""
244
+ return identifier.get("alternateIdentifierType", None) in [
245
+ "ARK",
246
+ "arXiv",
247
+ "Bibcode",
248
+ "DOI",
249
+ "Handle",
250
+ "ISBN",
251
+ "ISSN",
252
+ "PMID",
253
+ "PMCID",
254
+ "PURL",
255
+ "URL",
256
+ "URN",
257
+ "Other"
258
+ ]
259
+
260
+ def format_identifier(identifier):
261
+ """format_identifier"""
262
+
263
+ if is_identifier(identifier):
264
+ type_ = identifier.get("alternateIdentifierType")
265
+ else:
266
+ type_ = "Other"
267
+
268
+ return compact(
269
+ {
270
+ "identifier": identifier.get("#text", None),
271
+ "identifierType": type_,
272
+ }
273
+ )
274
+ return [format_identifier(i) for i in identifiers]
275
+
242
276
  def get_xml_references(references: list) -> list:
243
277
  """get_xml_references"""
244
278
 
@@ -248,7 +248,6 @@
248
248
  "$ref": "#/definitions/contributorRole"
249
249
  },
250
250
  "type": "array",
251
- "minItems": 1,
252
251
  "uniqueItems": true
253
252
  }
254
253
  }
@@ -333,7 +332,6 @@
333
332
  },
334
333
  "required": ["url"]
335
334
  },
336
- "minItems": 1,
337
335
  "uniqueItems": true
338
336
  },
339
337
  "fundingReferences": {
@@ -27,6 +27,7 @@ def write_commonmeta(metadata):
27
27
  data,
28
28
  {
29
29
  "additional_type": "additionalType",
30
+ "archive_locations": "archiveLocations",
30
31
  "geo_locations": "geoLocations",
31
32
  "funding_references": "fundingReferences",
32
33
  },
@@ -3,7 +3,7 @@ import orjson as json
3
3
  from typing import Optional, Union
4
4
 
5
5
  from ..base_utils import wrap, compact
6
- from ..doi_utils import doi_from_url
6
+ from ..doi_utils import doi_from_url, normalize_doi
7
7
  from ..constants import (
8
8
  CM_TO_BIB_TRANSLATIONS,
9
9
  CM_TO_CSL_TRANSLATIONS,
@@ -19,6 +19,14 @@ def write_datacite(metadata: Commonmeta) -> Optional[Union[str, dict]]:
19
19
  """Write datacite. Make sure JSON Schema validates before writing"""
20
20
  if metadata.write_errors is not None:
21
21
  return "{}"
22
+
23
+ alternate_identifiers = [
24
+ {
25
+ "alternateIdentifier": i.get("identifier", None),
26
+ "alternateIdentifierType": i.get("identifierType", None),
27
+ }
28
+ for i in wrap(metadata.identifiers) if i.get("id", None) != metadata.id
29
+ ]
22
30
 
23
31
  creators = [
24
32
  to_datacite_creator(i)
@@ -33,7 +41,7 @@ def write_datacite(metadata: Commonmeta) -> Optional[Union[str, dict]]:
33
41
  related_identifiers = [
34
42
  to_datacite_related_identifier(i)
35
43
  for i in wrap(metadata.references)
36
- if i.get("doi", None) or i.get("url", None)
44
+ if i.get("id", None)
37
45
  ]
38
46
 
39
47
  resource__typegeneral = CM_TO_DC_TRANSLATIONS.get(metadata.type, "Other")
@@ -114,6 +122,7 @@ def write_datacite(metadata: Commonmeta) -> Optional[Union[str, dict]]:
114
122
  "dates": dates,
115
123
  "language": metadata.language,
116
124
  "types": types,
125
+ "alternateIdentifiers": alternate_identifiers,
117
126
  "relatedIdentifiers": related_identifiers,
118
127
  "version": metadata.version,
119
128
  "rightsList": license_,
@@ -151,7 +160,7 @@ def to_datacite_creator(creator: dict) -> dict:
151
160
  "familyName": creator.get("familyName", None),
152
161
  "nameType": _type + "al" if _type else None,
153
162
  "nameIdentifiers": name_identifiers,
154
- "affiliation": creator.get("affiliation", None),
163
+ "affiliation": creator.get("affiliations", None),
155
164
  }
156
165
  )
157
166
 
@@ -170,8 +179,8 @@ def to_datacite_titles(titles: list) -> list:
170
179
 
171
180
  def to_datacite_related_identifier(reference: dict) -> dict:
172
181
  """Convert reference to datacite related_identifier"""
173
- _id = reference.get("id", None)
174
- url = reference.get("url", None)
182
+ _id = normalize_doi(reference.get("id", None))
183
+ url = reference.get("id", None)
175
184
  return compact(
176
185
  {
177
186
  "relatedIdentifier": _id if _id else url,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name="commonmeta-py"
3
- version="0.17.1"
3
+ version="0.17.3"
4
4
  repository = "https://github.com/front-matter/commonmeta-py"
5
5
  homepage = "https://python.commonmeta.org"
6
6
  documentation = "https://python.commonmeta.org"
File without changes
File without changes
@@ -80,26 +80,26 @@ class Metadata:
80
80
  self.id = meta.get("id") # pylint: disable=C0103
81
81
  self.type = meta.get("type")
82
82
  # recommended and optional properties
83
- self.url = meta.get("url")
83
+ self.additional_type = meta.get("additionalType")
84
+ self.archive_locations = meta.get("archiveLocations")
85
+ self.container = meta.get("container")
84
86
  self.contributors = meta.get("contributors")
85
- self.titles = meta.get("titles")
86
- self.publisher = meta.get("publisher")
87
87
  self.date = meta.get("date")
88
- self.additional_type = meta.get("additionalType")
89
- self.subjects = meta.get("subjects")
90
- self.language = meta.get("language")
91
- self.identifiers = meta.get("identifiers")
92
- self.relations = meta.get("relations")
93
- self.version = meta.get("version")
94
- self.license = meta.get("license")
95
88
  self.descriptions = meta.get("descriptions")
96
- self.geo_locations = meta.get("geoLocations")
97
- self.funding_references = meta.get("fundingReferences")
98
- self.references = meta.get("references")
99
89
  self.files = meta.get("files")
100
- self.container = meta.get("container")
90
+ self.funding_references = meta.get("fundingReferences")
91
+ self.geo_locations = meta.get("geoLocations")
92
+ self.identifiers = meta.get("identifiers")
93
+ self.language = meta.get("language")
94
+ self.license = meta.get("license")
101
95
  self.provider = meta.get("provider")
102
- self.archive_locations = meta.get("archiveLocations")
96
+ self.publisher = meta.get("publisher")
97
+ self.references = meta.get("references")
98
+ self.relations = meta.get("relations")
99
+ self.subjects = meta.get("subjects")
100
+ self.titles = meta.get("titles")
101
+ self.url = meta.get("url")
102
+ self.version = meta.get("version")
103
103
  # other properties
104
104
  self.date_created = meta.get("date_created")
105
105
  self.date_registered = meta.get("date_registered")