commonmeta-py 0.37__py3-none-any.whl → 0.39__py3-none-any.whl

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.
commonmeta/__init__.py CHANGED
@@ -10,7 +10,7 @@ commonmeta-py is a Python library to convert scholarly metadata
10
10
  """
11
11
 
12
12
  __title__ = "commonmeta-py"
13
- __version__ = "0.37"
13
+ __version__ = "0.39"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
commonmeta/constants.py CHANGED
@@ -612,3 +612,14 @@ INVENIORDM_IDENTIFIER_TYPES = {
612
612
  "W3ID": "w3id",
613
613
  "Other": "other",
614
614
  }
615
+
616
+
617
+ CROSSREF_FUNDER_ID_TO_ROR_TRANSLATIONS = {
618
+ "https://doi.org/10.13039/100000001": "https://ror.org/021nxhr62",
619
+ "https://doi.org/10.13039/501100000780": "https://ror.org/00k4n6c32",
620
+ "https://doi.org/10.13039/501100007601": "https://ror.org/00k4n6c32",
621
+ "https://doi.org/10.13039/501100001659": "https://ror.org/018mejw64",
622
+ "https://doi.org/10.13039/501100006390": "https://ror.org/019whta54",
623
+ "https://doi.org/10.13039/501100001711": "https://ror.org/00yjd3n13",
624
+ "https://doi.org/10.13039/501100003043": "https://ror.org/04wfr2810",
625
+ }
@@ -36,7 +36,6 @@ def get_inveniordm(pid: str, **kwargs) -> dict:
36
36
 
37
37
  def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
38
38
  """read_inveniordm"""
39
- print(data)
40
39
  meta = data
41
40
  read_options = kwargs or {}
42
41
 
@@ -49,7 +48,6 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
49
48
  resource_type = py_.get(meta, "metadata.resource_type.type") or py_.get(
50
49
  meta, "metadata.resource_type.id"
51
50
  )
52
- print(resource_type)
53
51
  _type = INVENIORDM_TO_CM_TRANSLATIONS.get(resource_type, "Other")
54
52
 
55
53
  contributors = py_.get(meta, "metadata.creators")
@@ -46,7 +46,6 @@ def read_json_feed_item(data: Optional[dict], **kwargs) -> Commonmeta:
46
46
  if data is None:
47
47
  return {"state": "not_found"}
48
48
  meta = data
49
- print(meta)
50
49
  read_options = kwargs or {}
51
50
 
52
51
  url = normalize_url(meta.get("url", None))
@@ -168,39 +167,28 @@ def get_references(references: list) -> list:
168
167
  def get_reference(reference: dict) -> Optional[dict]:
169
168
  if reference is None or not isinstance(reference, dict):
170
169
  return None
171
- try:
172
- if reference.get("doi", None) and validate_doi(reference.get("doi")):
173
- id_ = normalize_doi(reference.get("doi"))
174
- return compact(
175
- {
176
- "id": id_,
177
- "title": reference.get("title", None),
178
- "publicationYear": reference.get("publicationYear", None),
179
- }
180
- )
181
170
 
182
- elif (
183
- reference.get("url", None)
184
- and validate_url(reference.get("url")) == "URL"
185
- ):
186
- response = httpx.head(reference.get("url", None), timeout=10)
187
- # check that URL resolves.
188
- # TODO: check for redirects
189
- if response.status_code in [404]:
190
- return None
191
- return {
192
- "id": reference.get("url"),
171
+ if reference.get("id", None) and validate_doi(reference.get("id")):
172
+ id_ = normalize_doi(reference.get("id"))
173
+ return compact(
174
+ {
175
+ "id": id_,
176
+ "title": reference.get("title", None),
177
+ "publicationYear": reference.get("publicationYear", None),
193
178
  }
194
- except Exception as error:
195
- print(error)
196
- return None
179
+ )
180
+
181
+ else:
182
+ return {
183
+ "id": reference.get("id", None),
184
+ }
197
185
 
198
186
  def number_reference(reference: dict, index: int) -> dict:
199
187
  """number reference"""
200
188
  reference["key"] = f"ref{index +1}"
201
189
  return reference
202
190
 
203
- references = [get_reference(i) for i in references]
191
+ references = [get_reference(i) for i in references if i.get("id", None)]
204
192
  return [
205
193
  number_reference(i, index)
206
194
  for index, i in enumerate(references)
@@ -230,7 +218,7 @@ def get_funding_references(meta: Optional[dict]) -> Optional[list]:
230
218
  "funderName": "European Commission",
231
219
  "funderIdentifier": "https://doi.org/10.13039/501100000780",
232
220
  "funderIdentifierType": "Crossref Funder ID",
233
- "award_uri": urls[0],
221
+ "awardUri": urls[0],
234
222
  "awardNumber": urls[0].split("/")[-1],
235
223
  }
236
224
  ]
@@ -251,7 +239,7 @@ def get_funding_references(meta: Optional[dict]) -> Optional[list]:
251
239
  "funderName": funder_name,
252
240
  "funderIdentifier": urls[0],
253
241
  "funderIdentifierType": "Crossref Funder ID",
254
- "award_uri": urls[1],
242
+ "awardUri": urls[1],
255
243
  "awardNumber": award_number,
256
244
  }
257
245
  ]
@@ -282,7 +270,7 @@ def get_funding_references(meta: Optional[dict]) -> Optional[list]:
282
270
  "funderName": funder_name,
283
271
  "funderIdentifier": funder_identifier,
284
272
  "funderIdentifierType": funder_identifier_type,
285
- "award_uri": urls[1],
273
+ "awardUri": urls[1],
286
274
  "awardNumber": award_number,
287
275
  }
288
276
  )
@@ -186,7 +186,7 @@ def get_funding_references(funding_references: list) -> list:
186
186
  funding_reference, "funder.organization_name", None
187
187
  ),
188
188
  "awardNumber": funding_reference.get("grant_id", None),
189
- "award_uri": funding_reference.get("grant_url", None),
189
+ "awardUri": funding_reference.get("grant_url", None),
190
190
  }
191
191
  )
192
192
 
@@ -0,0 +1,574 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://commonmeta.org/commonmeta_v0.15.json",
4
+ "title": "Commonmeta v0.15",
5
+ "description": "JSON representation of the Commonmeta schema.",
6
+ "commonmeta": {
7
+ "anyOf": [
8
+ { "$ref": "#/definitions/commonmeta"
9
+ },
10
+ {
11
+ "type": "array",
12
+ "description": "An array of commonmeta objects.",
13
+ "items": { "$ref": "#/definitions/commonmeta" }
14
+ }
15
+ ]
16
+ },
17
+ "definitions": {
18
+ "affiliations": {
19
+ "type": "array",
20
+ "items": {
21
+ "type": "object",
22
+ "properties": {
23
+ "organization": { "$ref": "#/definitions/organization" }
24
+ }
25
+ }
26
+ },
27
+ "commonmeta": {
28
+ "description": "A commonmeta object.",
29
+ "type": "object",
30
+ "additionalProperties": false,
31
+ "properties": {
32
+ "id": { "$ref": "#/definitions/id" },
33
+ "type": { "$ref": "#/definitions/type" },
34
+ "additionalType": {
35
+ "description": "The additional type of the resource.",
36
+ "type": "string"
37
+ },
38
+ "archiveLocations": {
39
+ "description": "The location where content is archived.",
40
+ "type": "array",
41
+ "items": {
42
+ "type": "string",
43
+ "enum": [
44
+ "CLOCKSS",
45
+ "LOCKSS",
46
+ "Portico",
47
+ "KB",
48
+ "Internet Archive",
49
+ "DWT"
50
+ ]
51
+ }
52
+ },
53
+ "container": {
54
+ "description": "The container of the resource.",
55
+ "type": "object",
56
+ "properties": {
57
+ "identifier": {
58
+ "description": "The identifier for the container.",
59
+ "type": "string"
60
+ },
61
+ "identifierType": {
62
+ "description": "The identifierType for the container.",
63
+ "type": "string"
64
+ },
65
+ "type": {
66
+ "description": "The type of the container.",
67
+ "type": "string",
68
+ "enum": [
69
+ "Book",
70
+ "BookSeries",
71
+ "Journal",
72
+ "Proceedings",
73
+ "ProceedingsSeries",
74
+ "Repository",
75
+ "DataRepository",
76
+ "Periodical",
77
+ "Series"
78
+ ]
79
+ },
80
+ "title": {
81
+ "description": "The title of the container.",
82
+ "type": "string"
83
+ },
84
+ "firstPage": {
85
+ "description": "The first page of the resource.",
86
+ "type": "string"
87
+ },
88
+ "lastPage": {
89
+ "description": "The last page of the resource.",
90
+ "type": "string"
91
+ },
92
+ "volume": {
93
+ "description": "The volume of the resource.",
94
+ "type": "string"
95
+ },
96
+ "issue": {
97
+ "description": "The issue of the resource.",
98
+ "type": "string"
99
+ }
100
+ }
101
+ },
102
+ "contributors": {
103
+ "description": "The contributors to the resource.",
104
+ "type": "array",
105
+ "items": {
106
+ "type": "object",
107
+ "properties": {
108
+ "organization": { "$ref": "#/definitions/organization" },
109
+ "person": { "$ref": "#/definitions/person" },
110
+ "contributorRoles": {
111
+ "description": "List of roles assumed by the contributor when working on the resource.",
112
+ "items": {
113
+ "$ref": "#/definitions/contributorRole"
114
+ },
115
+ "type": "array"
116
+ }
117
+ }
118
+ },
119
+ "minItems": 1
120
+ },
121
+ "date": {
122
+ "description": "The dates for the resource.",
123
+ "$comment": "The date fields are not required. Dates should be formatted as ISO 8601 dates.",
124
+ "type": "object",
125
+ "properties": {
126
+ "created": {
127
+ "description": "The date the resource was created.",
128
+ "type": "string"
129
+ },
130
+ "submitted": {
131
+ "description": "The date the resource was submitted.",
132
+ "type": "string"
133
+ },
134
+ "accepted": {
135
+ "description": "The date the resource was accepted.",
136
+ "type": "string"
137
+ },
138
+ "published": {
139
+ "description": "The date the resource was published.",
140
+ "type": "string"
141
+ },
142
+ "updated": {
143
+ "description": "The date the resource was updated.",
144
+ "type": "string"
145
+ },
146
+ "accessed": {
147
+ "description": "The date the resource was accessed.",
148
+ "type": "string"
149
+ },
150
+ "available": {
151
+ "description": "The date the resource was made available.",
152
+ "type": "string"
153
+ },
154
+ "withdrawn": {
155
+ "description": "The date the resource was withdrawn.",
156
+ "type": "string"
157
+ }
158
+ }
159
+ },
160
+ "descriptions": {
161
+ "description": "The descriptions of the resource.",
162
+ "type": "array",
163
+ "items": {
164
+ "type": "object",
165
+ "properties": {
166
+ "description": {
167
+ "description": "The description of the resource.",
168
+ "type": "string"
169
+ },
170
+ "type": {
171
+ "description": "The type of the description.",
172
+ "type": "string",
173
+ "enum": ["Abstract", "Summary", "Methods", "TechnicalInfo", "Other"]
174
+ },
175
+ "language": {
176
+ "description": "The language of the title. Use one of the language codes from the IETF BCP 47 standard.",
177
+ "type": "string"
178
+ }
179
+ },
180
+ "required": ["description"]
181
+ }
182
+ },
183
+ "files": {
184
+ "description": "The downloadable files for the resource.",
185
+ "type": "array",
186
+ "items": {
187
+ "type": "object",
188
+ "properties": {
189
+ "bucket": { "type": "string" },
190
+ "key": { "type": "string" },
191
+ "checksum": { "type": "string" },
192
+ "url": { "type": "string", "format": "uri" },
193
+ "size": { "type": "integer" },
194
+ "mimeType": { "type": "string" }
195
+ },
196
+ "required": ["url"]
197
+ },
198
+ "minItems": 1
199
+ },
200
+ "fundingReferences": {
201
+ "description": "The funding references for the resource.",
202
+ "type": "array",
203
+ "items": {
204
+ "type": "object",
205
+ "properties": {
206
+ "funderIdentifier": { "type": "string" },
207
+ "funderIdentifierType": {
208
+ "type": "string",
209
+ "enum": [
210
+ "Crossref Funder ID",
211
+ "ROR",
212
+ "GRID",
213
+ "ISNI",
214
+ "Ringgold",
215
+ "Other"
216
+ ]
217
+ },
218
+ "funderName": { "type": "string" },
219
+ "awardNumber": { "type": "string" },
220
+ "awardTitle": { "type": "string" },
221
+ "awardUri": { "type": "string", "format": "uri" }
222
+ },
223
+ "required": ["funderName"]
224
+ }
225
+ },
226
+ "geoLocations": {
227
+ "type": "array",
228
+ "items": {
229
+ "type": "object",
230
+ "properties": {
231
+ "geoLocationPlace": { "type": "string" },
232
+ "geoLocationPoint": { "$ref": "#/definitions/geoLocationPoint" },
233
+ "geoLocationBox": { "$ref": "#/definitions/geoLocationBox" },
234
+ "geoLocationPolygons": {
235
+ "type": "array",
236
+ "items": {
237
+ "type": "object",
238
+ "properties": {
239
+ "polygonPoints": {
240
+ "type": "array",
241
+ "items": { "$ref": "#/definitions/geoLocationPoint" },
242
+ "minItems": 4
243
+ },
244
+ "inPolygonPoint": { "$ref": "#/definitions/geoLocationPoint" }
245
+ },
246
+ "required": ["polygonPoints"]
247
+ },
248
+ "uniqueItems": true
249
+ }
250
+ }
251
+ },
252
+ "uniqueItems": true
253
+ },
254
+ "identifiers": {
255
+ "description": "Identifiers for the resource, including the id.",
256
+ "type": "array",
257
+ "items": {
258
+ "type": "object",
259
+ "properties": {
260
+ "identifier": { "type": "string" },
261
+ "identifierType": {
262
+ "type": "string",
263
+ "enum": [
264
+ "ARK",
265
+ "arXiv",
266
+ "Bibcode",
267
+ "DOI",
268
+ "Handle",
269
+ "ISBN",
270
+ "ISSN",
271
+ "PMID",
272
+ "PMCID",
273
+ "PURL",
274
+ "URL",
275
+ "URN",
276
+ "UUID",
277
+ "Other"
278
+ ]
279
+ }
280
+ },
281
+ "required": ["identifier", "identifierType"]
282
+ }
283
+ },
284
+ "language": {
285
+ "description": "The language of the resource. Use one of the language codes from the IETF BCP 47 standard.",
286
+ "type": "string"
287
+ },
288
+ "license": {
289
+ "description": "The license for the resource. Use one of the SPDX license identifiers.",
290
+ "type": "object",
291
+ "properties": {
292
+ "id": { "type": "string" },
293
+ "url": { "type": "string", "format": "uri" }
294
+ }
295
+ },
296
+ "provider": {
297
+ "description": "The provider of the resource. This can be a DOI registration agency or a repository.",
298
+ "type": "string",
299
+ "enum": ["Crossref", "DataCite", "GitHub", "JaLC", "KISTI", "mEDRA", "OP"]
300
+ },
301
+ "publisher": {
302
+ "description": "The publisher of the resource.",
303
+ "type": "object",
304
+ "properties": {
305
+ "organization": { "$ref": "#/definitions/organization" }
306
+ }
307
+ },
308
+ "relations": {
309
+ "description": "Other resolvable persistent unique IDs related to the resource.",
310
+ "type": "array",
311
+ "items": {
312
+ "type": "object",
313
+ "properties": {
314
+ "id": {
315
+ "type": "string",
316
+ "format": "uri"
317
+ },
318
+ "type": {
319
+ "type": "string",
320
+ "enum": [
321
+ "IsNewVersionOf",
322
+ "IsPreviousVersionOf",
323
+ "IsVersionOf",
324
+ "HasVersion",
325
+ "IsPartOf",
326
+ "HasPart",
327
+ "IsVariantFormOf",
328
+ "IsOriginalFormOf",
329
+ "IsIdenticalTo",
330
+ "IsTranslationOf",
331
+ "HasTranslation",
332
+ "IsReviewedBy",
333
+ "Reviews",
334
+ "HasReview",
335
+ "IsPreprintOf",
336
+ "HasPreprint",
337
+ "IsSupplementTo",
338
+ "IsSupplementedBy"
339
+ ]
340
+ }
341
+ },
342
+ "required": ["id", "type"]
343
+ },
344
+ "minItems": 1
345
+ },
346
+ "references": {
347
+ "type": "array",
348
+ "items": {
349
+ "type": "object",
350
+ "properties": {
351
+ "id": { "$ref": "#/definitions/id" },
352
+ "type": { "$ref": "#/definitions/type" },
353
+ "key": { "type": "string" },
354
+ "contributor": { "type": "string" },
355
+ "title": { "type": "string" },
356
+ "publisher": { "type": "string" },
357
+ "publicationYear": { "type": "string" },
358
+ "volume": { "type": "string" },
359
+ "issue": { "type": "string" },
360
+ "firstPage": { "type": "string" },
361
+ "lastPage": { "type": "string" },
362
+ "containerTitle": { "type": "string" },
363
+ "edition": { "type": "string" },
364
+ "unstructured": { "type": "string" }
365
+ },
366
+ "required": ["key"]
367
+ }
368
+ },
369
+ "subjects": {
370
+ "type": "array",
371
+ "items": {
372
+ "type": "object",
373
+ "properties": {
374
+ "subject": { "type": "string" },
375
+ "language": {
376
+ "description": "The language of the subject. Use one of the language codes from the IETF BCP 47 standard.",
377
+ "type": "string"
378
+ }
379
+ },
380
+ "required": ["subject"]
381
+ }
382
+ },
383
+ "titles": {
384
+ "description": "The titles of the resource.",
385
+ "type": "array",
386
+ "items": {
387
+ "type": "object",
388
+ "properties": {
389
+ "title": {
390
+ "description": "The title of the resource.",
391
+ "type": "string"
392
+ },
393
+ "type": {
394
+ "description": "The type of the title.",
395
+ "type": "string",
396
+ "enum": ["AlternativeTitle", "Subtitle", "TranslatedTitle"]
397
+ },
398
+ "language": {
399
+ "description": "The language of the title. Use one of the language codes from the IETF BCP 47 standard.",
400
+ "type": "string"
401
+ }
402
+ },
403
+ "required": ["title"]
404
+ }
405
+ },
406
+ "url": {
407
+ "description": "The URL of the resource.",
408
+ "type": "string",
409
+ "format": "uri"
410
+ },
411
+ "version": {
412
+ "description": "The version of the resource.",
413
+ "type": "string"
414
+ }
415
+ },
416
+ "required": ["id", "type"]
417
+ },
418
+ "contributorRole": {
419
+ "description": "The type of contribution made by a contributor",
420
+ "enum": [
421
+ "Author",
422
+ "Editor",
423
+ "Chair",
424
+ "Reviewer",
425
+ "ReviewAssistant",
426
+ "StatsReviewer",
427
+ "ReviewerExternal",
428
+ "Reader",
429
+ "Translator",
430
+ "ContactPerson",
431
+ "DataCollector",
432
+ "DataManager",
433
+ "Distributor",
434
+ "HostingInstitution",
435
+ "Producer",
436
+ "ProjectLeader",
437
+ "ProjectManager",
438
+ "ProjectMember",
439
+ "RegistrationAgency",
440
+ "RegistrationAuthority",
441
+ "RelatedPerson",
442
+ "ResearchGroup",
443
+ "RightsHolder",
444
+ "Researcher",
445
+ "Sponsor",
446
+ "WorkPackageLeader",
447
+ "Conceptualization",
448
+ "DataCuration",
449
+ "FormalAnalysis",
450
+ "FundingAcquisition",
451
+ "Investigation",
452
+ "Methodology",
453
+ "ProjectAdministration",
454
+ "Resources",
455
+ "Software",
456
+ "Supervision",
457
+ "Validation",
458
+ "Visualization",
459
+ "WritingOriginalDraft",
460
+ "WritingReviewEditing",
461
+ "Maintainer",
462
+ "Other"
463
+ ],
464
+ "type": "string"
465
+ },
466
+ "geoLocationBox": {
467
+ "type": "object",
468
+ "properties": {
469
+ "westBoundLongitude": { "$ref": "#/definitions/longitude" },
470
+ "eastBoundLongitude": { "$ref": "#/definitions/longitude" },
471
+ "southBoundLatitude": { "$ref": "#/definitions/latitude" },
472
+ "northBoundLatitude": { "$ref": "#/definitions/latitude" }
473
+ }
474
+ },
475
+ "geoLocationPoint": {
476
+ "type": "object",
477
+ "properties": {
478
+ "pointLongitude": { "$ref": "#/definitions/longitude" },
479
+ "pointLatitude": { "$ref": "#/definitions/latitude" }
480
+ }
481
+ },
482
+ "id": {
483
+ "description": "The unique identifier for the resource.",
484
+ "type": "string",
485
+ "format": "uri"
486
+ },
487
+ "latitude": {
488
+ "type": "number",
489
+ "minimum": -90,
490
+ "maximum": 90
491
+ },
492
+ "longitude": {
493
+ "type": "number",
494
+ "minimum": -180,
495
+ "maximum": 180
496
+ },
497
+ "organization": {
498
+ "type": "object",
499
+ "properties": {
500
+ "id": {
501
+ "description": "The unique identifier for the organization.",
502
+ "type": "string",
503
+ "format": "uri"
504
+ },
505
+ "type": { "type": "string", "const": "Organization" },
506
+ "name": {
507
+ "description": "The name of the organization.",
508
+ "type": "string"
509
+ }
510
+ },
511
+ "required": ["name", "type"]
512
+ },
513
+ "person": {
514
+ "type": "object",
515
+ "properties": {
516
+ "id": { "type": "string", "format": "uri" },
517
+ "type": { "type": "string", "const": "Person" },
518
+ "givenName": {
519
+ "description": "The given name of the person.",
520
+ "type": "string"
521
+ },
522
+ "familyName": {
523
+ "description": "The family name of the person.",
524
+ "type": "string"
525
+ },
526
+ "affiliation": { "$ref": "#/definitions/affiliations" }
527
+ },
528
+ "required": ["familyName", "type"]
529
+ },
530
+ "type": {
531
+ "type": "string",
532
+ "enum": [
533
+ "Article",
534
+ "Audiovisual",
535
+ "BookChapter",
536
+ "BookPart",
537
+ "BookSection",
538
+ "BookSeries",
539
+ "BookSet",
540
+ "Book",
541
+ "Collection",
542
+ "Component",
543
+ "Database",
544
+ "Dataset",
545
+ "Dissertation",
546
+ "Document",
547
+ "Entry",
548
+ "Event",
549
+ "Grant",
550
+ "Image",
551
+ "Instrument",
552
+ "InteractiveResource",
553
+ "JournalArticle",
554
+ "JournalIssue",
555
+ "JournalVolume",
556
+ "Journal",
557
+ "PeerReview",
558
+ "PhysicalObject",
559
+ "Presentation",
560
+ "ProceedingsArticle",
561
+ "ProceedingsSeries",
562
+ "Proceedings",
563
+ "ReportComponent",
564
+ "ReportSeries",
565
+ "Report",
566
+ "Software",
567
+ "Standard",
568
+ "StudyRegistration",
569
+ "WebPage",
570
+ "Other"
571
+ ]
572
+ }
573
+ }
574
+ }
@@ -7,7 +7,7 @@ from jsonschema import Draft202012Validator, ValidationError
7
7
  def json_schema_errors(instance, schema: str = "commonmeta"):
8
8
  """validate against JSON schema"""
9
9
  schema_map = {
10
- "commonmeta": "commonmeta_v0.14",
10
+ "commonmeta": "commonmeta_v0.15",
11
11
  "datacite": "datacite-v4.5",
12
12
  "crossref": "crossref-v0.2",
13
13
  "csl": "csl-data",
commonmeta/utils.py CHANGED
@@ -1076,11 +1076,21 @@ def from_curie(id: Optional[str]) -> Optional[str]:
1076
1076
 
1077
1077
  def issn_as_url(issn: str) -> Optional[str]:
1078
1078
  """ISSN as URL"""
1079
- if issn is None:
1079
+ if normalize_issn(issn) is None:
1080
1080
  return None
1081
1081
  return f"https://portal.issn.org/resource/ISSN/{issn}"
1082
1082
 
1083
1083
 
1084
+ def issn_from_url(url: str) -> Optional[str]:
1085
+ """ISSN from URL"""
1086
+ if url is None:
1087
+ return None
1088
+ match = re.match(r"\Ahttps://portal.issn.org/resource/ISSN/(.+)\Z", url)
1089
+ if match is None:
1090
+ return None
1091
+ return match.group(1)
1092
+
1093
+
1084
1094
  def get_language(lang: str, format: str = "alpha_2") -> Optional[str]:
1085
1095
  """Provide a language string based on ISO 639, with either a name in English,
1086
1096
  ISO 639-1, or ISO 639-3 code as input. Optionally format as alpha_2 (defaul),
@@ -2,12 +2,23 @@
2
2
 
3
3
  import orjson as json
4
4
  from typing import Optional
5
+ from furl import furl
5
6
 
6
7
  from ..base_utils import compact, wrap, parse_attributes, presence
7
8
  from ..date_utils import get_iso8601_date
8
- from ..doi_utils import doi_from_url
9
- from ..constants import CM_TO_INVENIORDM_TRANSLATIONS, INVENIORDM_IDENTIFIER_TYPES
10
- from ..utils import get_language, validate_orcid, id_from_url, FOS_MAPPINGS
9
+ from ..doi_utils import doi_from_url, normalize_doi
10
+ from ..constants import (
11
+ CM_TO_INVENIORDM_TRANSLATIONS,
12
+ INVENIORDM_IDENTIFIER_TYPES,
13
+ CROSSREF_FUNDER_ID_TO_ROR_TRANSLATIONS,
14
+ )
15
+ from ..utils import (
16
+ get_language,
17
+ validate_orcid,
18
+ id_from_url,
19
+ issn_from_url,
20
+ FOS_MAPPINGS,
21
+ )
11
22
 
12
23
 
13
24
  def write_inveniordm(metadata):
@@ -30,6 +41,24 @@ def write_inveniordm(metadata):
30
41
  for i in wrap(metadata.identifiers)
31
42
  if i.get("id", None) != metadata.id
32
43
  ]
44
+ references = [
45
+ to_inveniordm_related_identifier(i)
46
+ for i in wrap(metadata.references)
47
+ if i.get("id", None)
48
+ ]
49
+ relations = [
50
+ to_inveniordm_related_identifier(i)
51
+ for i in wrap(metadata.relations)
52
+ if i.get("id", None) and i.get("type", None)
53
+ ]
54
+ related_identifiers = references + relations
55
+ funding = compact(
56
+ [
57
+ to_inveniordm_funding(i)
58
+ for i in wrap(metadata.funding_references)
59
+ if i.get("funderName", None)
60
+ ]
61
+ )
33
62
  container = metadata.container if metadata.container else {}
34
63
  journal = (
35
64
  container.get("title", None)
@@ -42,6 +71,14 @@ def write_inveniordm(metadata):
42
71
  if container.get("identifierType", None) == "ISSN"
43
72
  else None
44
73
  )
74
+ dates = []
75
+ if metadata.date.get("updated", None):
76
+ dates.append(
77
+ {
78
+ "date": metadata.date.get("updated"),
79
+ "type": {"id": "updated"},
80
+ }
81
+ )
45
82
 
46
83
  subjects = [to_inveniordm_subject(i) for i in wrap(metadata.subjects)]
47
84
  data = compact(
@@ -67,14 +104,7 @@ def write_inveniordm(metadata):
67
104
  "publication_date": get_iso8601_date(metadata.date.get("published"))
68
105
  if metadata.date.get("published", None)
69
106
  else None,
70
- "dates": [
71
- {
72
- "date": metadata.date.get("updated"),
73
- "type": {"id": "updated"},
74
- }
75
- ]
76
- if metadata.date.get("updated", None)
77
- else None,
107
+ "dates": presence(dates),
78
108
  "subjects": presence(subjects),
79
109
  "description": parse_attributes(
80
110
  metadata.descriptions, content="description", first=True
@@ -88,6 +118,8 @@ def write_inveniordm(metadata):
88
118
  if metadata.language
89
119
  else None,
90
120
  "identifiers": identifiers,
121
+ "related_identifiers": presence(related_identifiers),
122
+ "funding": presence(funding),
91
123
  "version": metadata.version,
92
124
  }
93
125
  ),
@@ -173,3 +205,98 @@ def to_inveniordm_affiliations(creator: dict) -> Optional[list]:
173
205
  return compact(
174
206
  [format_affiliation(i) for i in wrap(creator.get("affiliations", None))]
175
207
  )
208
+
209
+
210
+ def to_inveniordm_related_identifier(relation: dict) -> dict:
211
+ """Convert reference or relation to inveniordm related_identifier"""
212
+ if normalize_doi(relation.get("id", None)):
213
+ identifier = doi_from_url(relation.get("id", None))
214
+ scheme = "doi"
215
+ elif (
216
+ relation.get("type", None) == "IsPartOf"
217
+ and furl(relation.get("id", None)).host == "portal.issn.org"
218
+ ):
219
+ identifier = issn_from_url(relation.get("id", None))
220
+ scheme = "issn"
221
+ else:
222
+ identifier = relation.get("id", None)
223
+ scheme = "url"
224
+
225
+ # normalize relation types
226
+ relation_type = relation.get("type")
227
+ if relation.get("type", None) is None:
228
+ relation_type = "References"
229
+ if relation.get("type") == "HasReview":
230
+ relation_type = "IsReviewedBy"
231
+
232
+ return compact(
233
+ {
234
+ "identifier": identifier,
235
+ "scheme": scheme,
236
+ "relation_type": {
237
+ "id": relation_type.lower(),
238
+ },
239
+ }
240
+ )
241
+
242
+
243
+ def to_inveniordm_funding(funding: dict) -> Optional[dict]:
244
+ """Convert funding to inveniordm funding"""
245
+ if funding.get("funderIdentifierType", None) == "ROR":
246
+ funder_identifier = id_from_url(funder_identifier)
247
+ elif funding.get("funderIdentifierType", None) == "Crossref Funder ID":
248
+ # convert to ROR
249
+ funder_identifier = id_from_url(
250
+ CROSSREF_FUNDER_ID_TO_ROR_TRANSLATIONS.get(
251
+ funding.get("funderIdentifier", None), None
252
+ )
253
+ )
254
+ else:
255
+ funder_identifier = None
256
+ award_number = funding.get("awardNumber", None)
257
+ award_title = funding.get("awardTitle", None)
258
+ if award_title:
259
+ award_title = {"title": {"en": award_title}}
260
+ if funding.get("awardUri", None):
261
+ award_identifier = funding.get("awardUri", None)
262
+ scheme = "doi" if normalize_doi(award_identifier) else "url"
263
+ if scheme == "doi":
264
+ award_identifier = doi_from_url(award_identifier)
265
+ award_identifiers = [
266
+ {
267
+ "scheme": scheme,
268
+ "identifier": award_identifier,
269
+ },
270
+ ]
271
+ else:
272
+ award_identifiers = None
273
+
274
+ if award_number or award_title or award_identifiers:
275
+ return compact(
276
+ {
277
+ "funder": compact(
278
+ {
279
+ "name": funding.get("funderName"),
280
+ "id": funder_identifier,
281
+ }
282
+ ),
283
+ "award": compact(
284
+ {
285
+ "number": award_number,
286
+ "title": award_title,
287
+ "identifiers": award_identifiers,
288
+ }
289
+ ),
290
+ }
291
+ )
292
+
293
+ return compact(
294
+ {
295
+ "funder": compact(
296
+ {
297
+ "name": funding.get("funderName"),
298
+ "id": funder_identifier,
299
+ }
300
+ ),
301
+ }
302
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commonmeta-py
3
- Version: 0.37
3
+ Version: 0.39
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
@@ -1,9 +1,9 @@
1
- commonmeta/__init__.py,sha256=I3h_-vkXPlcA7lMWCN6MwOovl6EEoCs796ho6ISnYfM,1779
1
+ commonmeta/__init__.py,sha256=Yb35HxY9mUSmG9MYb6v3qVEfQF7Zt6PWJr8hehffPNU,1779
2
2
  commonmeta/api_utils.py,sha256=-ZHGVZZhJqnjnsLtp4-PoeHYbDqL0cQme7W70BEjo4U,2677
3
3
  commonmeta/author_utils.py,sha256=zBIPTgP5n7Zx57xomJ2h7x0dvC0AV8gJ2gPoYeDy5Lo,8348
4
4
  commonmeta/base_utils.py,sha256=0t6fr9XGeeTBoMlKSAMI7p_EmKsA6wYRW0roEBXVcc8,3722
5
5
  commonmeta/cli.py,sha256=0IJF1SQ1sKPg7M0Gb8fpX2nBps-G0L13o01__M6c5Z0,6104
6
- commonmeta/constants.py,sha256=fB2oMjnPYCJG3Zx6080u0R0ujmXkPRLGSgYOulWyOFw,16411
6
+ commonmeta/constants.py,sha256=aMD7vG_kJD5ja5YOqDjsfuokWcRMnWOF7jv0YV3-OXw,16973
7
7
  commonmeta/crossref_utils.py,sha256=xyS8jFXO8unzumCC6YXK45kzz16PQAAOkWUHgjqawAo,22063
8
8
  commonmeta/date_utils.py,sha256=amF3E0ZJlh8yY5eY3aVXQyAO1x2WuZHJXw-ajOEcdUQ,5808
9
9
  commonmeta/doi_utils.py,sha256=Dt6K9ADD2ga2WNsOzfX9f29gnubhn7xqeKL7U5pEpBs,8209
@@ -18,15 +18,16 @@ commonmeta/readers/crossref_xml_reader.py,sha256=QF1A-r3OJbykBTH9YMSxusT3-KSKmmz
18
18
  commonmeta/readers/csl_reader.py,sha256=5V_sHSJwcAWJmhB8SYk199nB96BWYX1Sq9vkQ3iEmAY,3164
19
19
  commonmeta/readers/datacite_reader.py,sha256=CdOtxhthrakBoQMsLTdPx6sUCmqtEWo5ICYE6ZsWDdo,12026
20
20
  commonmeta/readers/datacite_xml_reader.py,sha256=nhnO92fZihr1HZlbXjyem-HJXc9_DWLgJ2zeltuPMIg,13041
21
- commonmeta/readers/inveniordm_reader.py,sha256=ejhpj4KX6bJU79lKrkTQeG3AATw0h2DdNdieNlx5j0w,7521
22
- commonmeta/readers/json_feed_reader.py,sha256=YUJlZ7P44HEb-VKZHGr84ePGmHTVnfco_K36koooKnQ,13917
23
- commonmeta/readers/kbase_reader.py,sha256=NpIK-_fh5QFN4Q_ArqcrnH4tS5zR1gqbPew6VEjrUbs,6764
21
+ commonmeta/readers/inveniordm_reader.py,sha256=jzv0rXzT8OCdPD_MShBXTnlwD-F9tpTX7OKZGn8smzs,7480
22
+ commonmeta/readers/json_feed_reader.py,sha256=x7TjLq5nJsYw-MpDfYeiAWn2RbvqrIVkdOjQFW_Y7EE,13403
23
+ commonmeta/readers/kbase_reader.py,sha256=ehKXQsJyPCtaq2FmBxNb2Jb5Nktpx8pNscpmEM6N0A4,6763
24
24
  commonmeta/readers/ris_reader.py,sha256=v6qOd-i2OcMTEFy5RGd3MlYthJcYSU6yzmZ5yHDzmII,3677
25
25
  commonmeta/readers/schema_org_reader.py,sha256=xyWzO2XAWlI2pYVl2EbVRsUmfiWXEwP64CHRBQNRN-M,16835
26
26
  commonmeta/resources/cff_v1.2.0.json,sha256=MpfjDYgX7fN9PLiG54ISZ2uu9WItNqfh-yaRuTf6Ptg,46691
27
27
  commonmeta/resources/commonmeta_v0.12.json,sha256=HUSNReXh2JN3Q6YWSt7CE69js8dh50OlpMYGTyU98oU,16762
28
28
  commonmeta/resources/commonmeta_v0.13.json,sha256=2-WSZGijR13zVu97S_YHXr-cyeLW7hzHXYMlr6nIjdw,15787
29
29
  commonmeta/resources/commonmeta_v0.14.json,sha256=nACmkTe4IrZkygd5AeJnAv9P4EWfzCwW9oL5AhubvnE,17657
30
+ commonmeta/resources/commonmeta_v0.15.json,sha256=tOc1QL2n9HYngEgxIZDwBFWEXxX1bd2wtOqCqI0usnw,17707
30
31
  commonmeta/resources/crossref/AccessIndicators.xsd,sha256=en-G2FFt4ewIFRw5C6g4YA8Nc0M66fCM2CygiO_ZqqY,2825
31
32
  commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3-elements.xsd,sha256=l5jJMFm4xx09bavH2Gc3EqIdr-0PTf6M9YBTNpUaZhY,415409
32
33
  commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3.xsd,sha256=goO2ckm12fF2-kGFZC_FaTBdi4BK3YCRwb_ESur8dfY,2210
@@ -55,9 +56,9 @@ commonmeta/resources/styles/harvard-cite-them-right.csl,sha256=XmLVFDrfsgkECYaAb
55
56
  commonmeta/resources/styles/ieee.csl,sha256=DfuN__z8FZ5Rcdaj_Myc5y_FmB-fHwfRVTeS9-hOgmQ,15854
56
57
  commonmeta/resources/styles/modern-language-association.csl,sha256=HI2iU4krze1aHYc9VSQCUyw_2I6fEQYnA9xIWo-xNus,11594
57
58
  commonmeta/resources/styles/vancouver.csl,sha256=lun3_i2oTilgsANk4LjFao2UDPQlGj_hgFgKAWC_DF8,12878
58
- commonmeta/schema_utils.py,sha256=Ep8suJgqtgDAvbjVkQxwzAY1MqwwqPwNRKDTMAxMQTg,915
59
+ commonmeta/schema_utils.py,sha256=gg3l1jd_lFtRkQlO1DYGMVbC10nEmVTN4AWacxC4AAE,915
59
60
  commonmeta/translators.py,sha256=RpGJtKNLjmz41VREZDY7KyyE2eXOi8j7m-da4jHmknI,1362
60
- commonmeta/utils.py,sha256=TjspdiI9g6WEcbvEiUOc6ARV7j_PHAdY2nRrEHrNXQs,42310
61
+ commonmeta/utils.py,sha256=dblEYOmR0q6qZgsqnQOunm_Zj7YP4bugzwK1ps5SYq8,42583
61
62
  commonmeta/writers/__init__.py,sha256=47-snms6xBHkoEXKYV1DBtH1npAtlVtvY29Z4Zr45qI,45
62
63
  commonmeta/writers/bibtex_writer.py,sha256=s3hIJIgWvSG7TAriZMRQEAyuitw6ebwWSI1YcYFQ-do,4971
63
64
  commonmeta/writers/citation_writer.py,sha256=RjaNh9EALxq6gfODLRWVJxGxPArGd6ZiHUlkYnCT6MA,2355
@@ -65,11 +66,11 @@ commonmeta/writers/commonmeta_writer.py,sha256=2qlttCfYpGhfVjrYkjzbIra7AywssRLT3
65
66
  commonmeta/writers/crossref_xml_writer.py,sha256=0Ds494RnXfdfjWw5CLX1kwV2zP7gqffdVqO-X74Uc6c,492
66
67
  commonmeta/writers/csl_writer.py,sha256=rlCeShkvC6ui9By0yVfNCMay_JfaZ4AooUPOPg-g-2M,2819
67
68
  commonmeta/writers/datacite_writer.py,sha256=G7Lr0aZ4sAEdbfXe3dG4Y6AyGUKA9UWr_iiaQRDnV24,6233
68
- commonmeta/writers/inveniordm_writer.py,sha256=nMQpjp_XKUxQvLroqGY4V2hyq2G4rgCrLQR5koAhOSE,5893
69
+ commonmeta/writers/inveniordm_writer.py,sha256=zPGji-ccaGwTmXM0uYUQYi0SWCkJxijz3g974d8QkAk,9622
69
70
  commonmeta/writers/ris_writer.py,sha256=AcnCszS3WY9lF594NbFBtLylsA8ownnYp_XLQJ84Ios,2093
70
71
  commonmeta/writers/schema_org_writer.py,sha256=5j002uCNLdlScZMNQmPjodcVWqaBh2z38zL1H4lo2hY,5741
71
- commonmeta_py-0.37.dist-info/LICENSE,sha256=746hEF2wZCKkcckk5-_DcBLtHewfaEMS4iXTlA1PVwk,1074
72
- commonmeta_py-0.37.dist-info/METADATA,sha256=HBztndo5nCk4uGfS1QnxpL9YS8WXRO9mZAdBnNUoVQo,8331
73
- commonmeta_py-0.37.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
74
- commonmeta_py-0.37.dist-info/entry_points.txt,sha256=vbcDw3_2lMTKdcAL2VUF4DRYRpKuzXVYLMCdgKVf88U,49
75
- commonmeta_py-0.37.dist-info/RECORD,,
72
+ commonmeta_py-0.39.dist-info/LICENSE,sha256=746hEF2wZCKkcckk5-_DcBLtHewfaEMS4iXTlA1PVwk,1074
73
+ commonmeta_py-0.39.dist-info/METADATA,sha256=00-S7EqflCWSm8Db0wNxmoXkVRC5AR7CMBEXt1MZI-Q,8331
74
+ commonmeta_py-0.39.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
75
+ commonmeta_py-0.39.dist-info/entry_points.txt,sha256=vbcDw3_2lMTKdcAL2VUF4DRYRpKuzXVYLMCdgKVf88U,49
76
+ commonmeta_py-0.39.dist-info/RECORD,,