commonmeta-py 0.137__py3-none-any.whl → 0.139__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.137"
13
+ __version__ = "0.139"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
commonmeta/doi_utils.py CHANGED
@@ -315,6 +315,7 @@ def is_rogue_scholar_doi(doi: str, ra: str = "crossref") -> bool:
315
315
  "10.59350",
316
316
  "10.63485",
317
317
  "10.64000",
318
+ "10.64395",
318
319
  ]
319
320
  rogue_scholar_datacite_prefixes = [
320
321
  "10.5438",
commonmeta/metadata.py CHANGED
@@ -355,13 +355,14 @@ class MetadataList:
355
355
  raise ValueError("No input found")
356
356
  if isinstance(dct, dict):
357
357
  meta = dct
358
+ elif isinstance(dct, list):
359
+ meta = {"items": dct}
358
360
  elif isinstance(dct, (str, bytes)):
359
361
  if path.exists(dct):
360
362
  with open(dct, encoding="utf-8") as file:
361
363
  dct = file.read()
362
364
  self.via = kwargs.get("via", None) or find_from_format(string=dct)
363
365
  meta = self.get_metadata_list(dct)
364
-
365
366
  self.id = meta.get("id", None)
366
367
  self.type = meta.get("type", None)
367
368
  self.title = meta.get("title", None)
@@ -392,12 +393,15 @@ class MetadataList:
392
393
  def get_metadata_list(self, string) -> list:
393
394
  if string is None or not isinstance(string, (str, bytes)):
394
395
  raise ValueError("No input found")
396
+ if self.via in [
397
+ "inveniordm",
398
+ ]:
399
+ return {"items": json.loads(string)}
395
400
  if self.via in [
396
401
  "commonmeta",
397
402
  "crossref",
398
403
  "csl",
399
404
  "datacite",
400
- "inveniordm",
401
405
  "jsonfeed",
402
406
  "openalex",
403
407
  "schema_org",
@@ -1,5 +1,7 @@
1
1
  """InvenioRDM reader for Commonmeta"""
2
2
 
3
+ from typing import Optional
4
+
3
5
  import requests
4
6
  from furl import furl
5
7
  from pydash import py_
@@ -12,8 +14,9 @@ from ..constants import (
12
14
  Commonmeta,
13
15
  )
14
16
  from ..date_utils import strip_milliseconds
15
- from ..doi_utils import doi_as_url, doi_from_url
17
+ from ..doi_utils import doi_as_url, doi_from_url, is_rogue_scholar_doi
16
18
  from ..utils import (
19
+ dict_to_fos,
17
20
  dict_to_spdx,
18
21
  from_inveniordm,
19
22
  get_language,
@@ -40,7 +43,15 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
40
43
  meta = data
41
44
  read_options = kwargs or {}
42
45
 
43
- url = normalize_url(py_.get(meta, "links.self_html"))
46
+ url = normalize_url(py_.get(meta, "links.self_html")) or next(
47
+ (
48
+ normalize_url(identifier.get("identifier"))
49
+ for identifier in wrap(py_.get(meta, "metadata.identifiers", []))
50
+ if identifier.get("scheme") == "url"
51
+ and identifier.get("identifier", None) is not None
52
+ ),
53
+ None,
54
+ )
44
55
  _id = (
45
56
  doi_as_url(meta.get("doi", None))
46
57
  or doi_as_url(py_.get(meta, "pids.doi.identifier"))
@@ -67,10 +78,22 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
67
78
  # titles += [{"title": sanitize("bla")} for i in wrap(additional_titles)]
68
79
 
69
80
  date: dict = {}
70
- date["published"] = py_.get(meta, ("metadata.publication_date"))
71
- if date["published"]:
72
- date["published"] = date["published"].split("/")[0]
73
- date["updated"] = strip_milliseconds(meta.get("updated", None))
81
+ date["published"] = next(
82
+ (
83
+ i.get("date")
84
+ for i in wrap(py_.get(meta, "metadata.dates", []))
85
+ if py_.get(i, "type.id") == "issued" and i.get("date", None) is not None
86
+ ),
87
+ None,
88
+ ) or py_.get(meta, ("metadata.publication_date"))
89
+ date["updated"] = next(
90
+ (
91
+ i.get("date")
92
+ for i in wrap(py_.get(meta, "metadata.dates", []))
93
+ if py_.get(i, "type.id") == "updated" and i.get("date", None) is not None
94
+ ),
95
+ None,
96
+ ) or strip_milliseconds(meta.get("updated", None))
74
97
  f = furl(url)
75
98
  if f.host == "zenodo.org":
76
99
  container = compact(
@@ -89,25 +112,31 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
89
112
  {
90
113
  "type": "Periodical",
91
114
  "title": container.get("title", None),
92
- "identifier": issn,
115
+ "identifier": issn if issn else None,
93
116
  "identifierType": "ISSN" if issn else None,
117
+ "platform": py_.get(meta, "custom_fields.rs:generator", None),
94
118
  }
95
119
  )
96
- license_ = py_.get(meta, "metadata.rights[0].id") or py_.get(
97
- meta, "metadata.license.id"
98
- )
99
- if license_:
100
- license_ = dict_to_spdx({"id": license_})
101
120
  descriptions = format_descriptions(
102
121
  [
103
122
  py_.get(meta, "metadata.description"),
104
123
  py_.get(meta, "metadata.notes"),
105
124
  ]
106
125
  )
126
+ identifiers = py_.compact(
127
+ [format_identifier(i) for i in wrap(py_.get(meta, "metadata.identifiers"))]
128
+ )
107
129
  language = py_.get(meta, "metadata.language") or py_.get(
108
130
  meta, "metadata.languages[0].id"
109
131
  )
110
- subjects = [name_to_fos(i) for i in wrap(py_.get(meta, "metadata.keywords"))]
132
+ license_ = py_.get(meta, "metadata.rights[0].id") or py_.get(
133
+ meta, "metadata.license.id"
134
+ )
135
+ if license_:
136
+ license_ = dict_to_spdx({"id": license_})
137
+ subjects = [dict_to_fos(i) for i in wrap(py_.get(meta, "metadata.subjects"))] or [
138
+ name_to_fos(i) for i in wrap(py_.get(meta, "metadata.keywords"))
139
+ ]
111
140
 
112
141
  references = get_references(wrap(py_.get(meta, "metadata.related_identifiers")))
113
142
  relations = get_relations(wrap(py_.get(meta, "metadata.related_identifiers")))
@@ -119,6 +148,9 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
119
148
  "type": "IsVersionOf",
120
149
  }
121
150
  )
151
+
152
+ content = py_.get(meta, "custom_fields.rs:content_html")
153
+ image = py_.get(meta, "custom_fields.rs:image")
122
154
  files = [get_file(i) for i in wrap(meta.get("files"))]
123
155
 
124
156
  return {
@@ -135,6 +167,7 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
135
167
  # recommended and optional properties
136
168
  # "additional_type": additional_type,
137
169
  "subjects": presence(subjects),
170
+ "identifiers": presence(identifiers),
138
171
  "language": get_language(language),
139
172
  "version": py_.get(meta, "metadata.version"),
140
173
  "license": presence(license_),
@@ -143,10 +176,12 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
143
176
  "fundingReferences": presence(funding_references),
144
177
  "references": presence(references),
145
178
  "relations": presence(relations),
179
+ "content": presence(content),
180
+ "image": presence(image),
181
+ "files": presence(files),
146
182
  # other properties
147
- "files": files,
148
183
  "container": container,
149
- "provider": "DataCite",
184
+ "provider": "Crossref" if is_rogue_scholar_doi(_id) else "Datacite",
150
185
  },
151
186
  **read_options,
152
187
  }
@@ -258,3 +293,27 @@ def format_descriptions(descriptions: list) -> list:
258
293
  for index, i in enumerate(descriptions)
259
294
  if i
260
295
  ]
296
+
297
+
298
+ def format_identifier(identifier: dict) -> Optional[dict]:
299
+ """format_identifier. scheme url is stored as url metadata."""
300
+ if (
301
+ identifier.get("identifier", None) is None
302
+ or identifier.get("scheme", None) is None
303
+ or identifier.get("scheme") == "url"
304
+ ):
305
+ return None
306
+
307
+ scheme = identifier.get("scheme")
308
+ if scheme == "doi":
309
+ identifier_type = "DOI"
310
+ elif scheme == "uuid":
311
+ identifier_type = "UUID"
312
+ elif scheme == "guid":
313
+ identifier_type = "GUID"
314
+ else:
315
+ identifier_type = None
316
+ return {
317
+ "identifier": identifier.get("identifier"),
318
+ "identifierType": identifier_type,
319
+ }
commonmeta/utils.py CHANGED
@@ -1367,6 +1367,15 @@ def name_to_fos(name: str) -> Optional[dict]:
1367
1367
  return {"subject": subject}
1368
1368
 
1369
1369
 
1370
+ def dict_to_fos(dct: dict) -> Optional[dict]:
1371
+ """Convert dict to Fields of Science (OECD) subject"""
1372
+ if not isinstance(dct, dict):
1373
+ return None
1374
+ if dct.get("subject", None) is not None:
1375
+ return name_to_fos(dct["subject"])
1376
+ return None
1377
+
1378
+
1370
1379
  def from_curie(id: Optional[str]) -> Optional[str]:
1371
1380
  """from CURIE"""
1372
1381
  if id is None:
@@ -452,7 +452,9 @@ def push_crossref_xml_list(
452
452
  if uuid:
453
453
  record["uuid"] = uuid
454
454
  record = update_legacy_record(
455
- record, legacy_key=legacy_key, field="doi"
455
+ # record, legacy_key=legacy_key, field="doi"
456
+ record,
457
+ legacy_key=legacy_key,
456
458
  )
457
459
  items.append(record)
458
460
 
@@ -382,9 +382,16 @@ def to_inveniordm_funding(funding: dict) -> Optional[dict]:
382
382
 
383
383
  def write_inveniordm_list(metalist):
384
384
  """Write InvenioRDM list"""
385
+
385
386
  if metalist is None:
386
387
  return None
387
- return [write_inveniordm(item) for item in metalist.items]
388
+
389
+ def write_item(item):
390
+ """write inveniordm item for inveniordm list"""
391
+
392
+ return write_inveniordm(item)
393
+
394
+ return [write_item(item) for item in metalist.items]
388
395
 
389
396
 
390
397
  def push_inveniordm(metadata: Commonmeta, host: str, token: str, **kwargs) -> Dict:
@@ -727,6 +734,7 @@ def update_legacy_record(record, legacy_key: str, field: str = None) -> dict:
727
734
  "indexed_at": now,
728
735
  "indexed": "true",
729
736
  "archived": "true",
737
+ "registered": "false",
730
738
  }
731
739
  elif record.get("doi", None) is not None:
732
740
  output = {
@@ -734,10 +742,12 @@ def update_legacy_record(record, legacy_key: str, field: str = None) -> dict:
734
742
  "indexed_at": now,
735
743
  "indexed": "true",
736
744
  "archived": "true",
745
+ "registered": "false",
737
746
  }
738
747
  else:
739
- print(f"nothing to update for id {record.get('uuid')}")
740
- return record # nothing to update
748
+ output = {
749
+ "registered": "true",
750
+ }
741
751
 
742
752
  request_url = f"https://{legacy_host}/rest/v1/posts?id=eq.{record['uuid']}"
743
753
  headers = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commonmeta-py
3
- Version: 0.137
3
+ Version: 0.139
4
4
  Summary: Library for conversions to/from the Commonmeta scholarly metadata format
5
5
  Project-URL: Homepage, https://python.commonmeta.org
6
6
  Project-URL: Repository, https://github.com/front-matter/commonmeta-py
@@ -1,16 +1,16 @@
1
- commonmeta/__init__.py,sha256=dHiaWJo_FPXFLyxr8wGWSwgUCHKUZAewRgsiCTu54rA,2118
1
+ commonmeta/__init__.py,sha256=0LNsQxOEovE9g84On2Y4q4nCnYHQcXN6TkJDbyChwcM,2118
2
2
  commonmeta/api_utils.py,sha256=P8LMHHYiF4OTi97_5k4KstcBreooMkOAKZ4ebxsAv4o,2691
3
3
  commonmeta/author_utils.py,sha256=3lYW5s1rOUWNTKs1FP6XLfEUY3yCLOe_3L_VdJTDMp0,8585
4
4
  commonmeta/base_utils.py,sha256=-MGy9q2uTiJEkPWQUYOJMdq-3tRpNnvBwlLjvllQ5g8,11164
5
5
  commonmeta/cli.py,sha256=kBDSn7hL29I_ICn8XKFFEaIWl_ZVE_KrNWpzfar9v3g,8639
6
6
  commonmeta/constants.py,sha256=wSTEUiHeRdXLwjXEQD9AU2hxFyEKi5OTX2iHOKO6nF0,19844
7
7
  commonmeta/date_utils.py,sha256=H2cCobX0JREIUOT_cCigGd3MG7prGiQpXk1m4ZNrFwU,6318
8
- commonmeta/doi_utils.py,sha256=uB5Zxr5ezo-5Pp_M_FCGM7jwuZ8ylRBtS1WHOCCLpsU,11491
8
+ commonmeta/doi_utils.py,sha256=0g53aGwYCLHmZZBpRBnxTO39IsF3fcDltEWbRMBY4HE,11511
9
9
  commonmeta/file_utils.py,sha256=eFYDWyR8Gr722nvFmp542hCm-TGmO_q4ciZ85IPHpjA,2893
10
- commonmeta/metadata.py,sha256=90aTe47d071wHxwcNsOqU5lSVPKP8wAPnPHhddj3Fuo,18443
10
+ commonmeta/metadata.py,sha256=xh5RNy9f7uKu5AjoPKyLqHGx149tGFy3IZwrf-fYHzg,18597
11
11
  commonmeta/schema_utils.py,sha256=zn3gqAHciUOQmrw9okR68weFs-yqPPyORFt-Zl1D3Lw,1924
12
12
  commonmeta/translators.py,sha256=CBMK4jrXRmGZiAhCh6wsJjhbDJWbcsda8UvXFXxccAw,1363
13
- commonmeta/utils.py,sha256=1Q6vh1mhQRTcPsEEymAPPJxBgDfNOR1ZXF_UaaW9ZoM,53612
13
+ commonmeta/utils.py,sha256=L84hESseuBbnY2iEjuBb9y2reUPmoX29R1hmlli8NW0,53877
14
14
  commonmeta/readers/__init__.py,sha256=vOf7UsOKNoh_ZCuyexxhAmPMt8wjB-pF_CfpWRaN8pk,45
15
15
  commonmeta/readers/bibtex_reader.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  commonmeta/readers/cff_reader.py,sha256=HMFK6QIg_XIlhmYIWL4EfIyuidYl5L_0TAwyG78XPlU,6244
@@ -21,7 +21,7 @@ commonmeta/readers/crossref_xml_reader.py,sha256=A2iAFT2IbhTNcfL-Dx4xO2SFSNOu_HN
21
21
  commonmeta/readers/csl_reader.py,sha256=OxzC2AZKfv43BCah4XGYvlK_LUK-5mxXFcjdzB5vv_o,3216
22
22
  commonmeta/readers/datacite_reader.py,sha256=4b_AP8m_aOUNVnVB0nU9j4-a8WTpmYJA8QPr5v35qyw,12219
23
23
  commonmeta/readers/datacite_xml_reader.py,sha256=nsPc7JBbIKgx6Yaauq8vmhUE-o6K0t_MAuExv6FO2AU,13205
24
- commonmeta/readers/inveniordm_reader.py,sha256=DtSloEZDu8bL-QLQAqAW1aDsS6ESTDZyhme379IekjY,8502
24
+ commonmeta/readers/inveniordm_reader.py,sha256=0zJABZMfncWDjhilFNkcxE7-hx2Ug_37RbksSkAJ_w4,10514
25
25
  commonmeta/readers/jsonfeed_reader.py,sha256=rrWsYfvgji0SW0wgvyT-eQ7J-nFraP6CXe1bWH0nx84,16134
26
26
  commonmeta/readers/kbase_reader.py,sha256=0Y9cHRNs_7kHyocN4IESXbgmXJiq4TXoxvGeUYGml1s,6896
27
27
  commonmeta/readers/openalex_reader.py,sha256=4HUkBsut_iUjhUcC5c1GHgxnKsYQc-fgY43QILgVZEg,12826
@@ -77,14 +77,14 @@ commonmeta/writers/__init__.py,sha256=47-snms6xBHkoEXKYV1DBtH1npAtlVtvY29Z4Zr45q
77
77
  commonmeta/writers/bibtex_writer.py,sha256=doAdyl1NEp60mPkHPo3GMH8B-HA6MzLAdlyNsIecTzU,4972
78
78
  commonmeta/writers/citation_writer.py,sha256=qs_4X3BjrSqHexmJFPvPDTp0mRIqzb0F70_Wuc7S9x0,2343
79
79
  commonmeta/writers/commonmeta_writer.py,sha256=QpfyhG__7o_XpsOTCPWxGymO7YKwZi2LQh8Zic44bdc,1365
80
- commonmeta/writers/crossref_xml_writer.py,sha256=nyNgnyluzd9jZ6jysrSg_TpMNOQuVjfMo7pN0HUb3c0,34832
80
+ commonmeta/writers/crossref_xml_writer.py,sha256=1DQNnjU_9TSz2YuBQprKK_3ostCBikZUn9OVhov78B8,34905
81
81
  commonmeta/writers/csl_writer.py,sha256=4gDYs1EzK4_L2UIRTfs25wgHmYRwdRP2zmfxF9387oU,2779
82
82
  commonmeta/writers/datacite_writer.py,sha256=bcinpwhq7XnVthKHH8-sdXA34dSlvFH4ImYH768iaQU,6428
83
- commonmeta/writers/inveniordm_writer.py,sha256=tiuq9JEkz02l615yVe9wUcJQqiIPJLUqNDyofEE8Aus,26726
83
+ commonmeta/writers/inveniordm_writer.py,sha256=Q28Ogj5M8nP6FuOLcJOO8Vrm6jHRoYxCEyAcT3FjzA4,26882
84
84
  commonmeta/writers/ris_writer.py,sha256=3SdyEvMRaPRP1SV1MB-MXBlunE7x6og7RF1zuWtetPc,2094
85
85
  commonmeta/writers/schema_org_writer.py,sha256=s18_x0ReXwAGBoEAwp2q-HCgFQ-h5qRg6JyAlqCoSFE,5871
86
- commonmeta_py-0.137.dist-info/METADATA,sha256=2AJlNYHWys5ZdUp3TT5_DZPa65pFTj-t2ohmJAedj1U,7656
87
- commonmeta_py-0.137.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
- commonmeta_py-0.137.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
- commonmeta_py-0.137.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
- commonmeta_py-0.137.dist-info/RECORD,,
86
+ commonmeta_py-0.139.dist-info/METADATA,sha256=-oF4TP5OQTDBUQYQJaBDfCKje5jKjtUlP3ludFAESJ4,7656
87
+ commonmeta_py-0.139.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
+ commonmeta_py-0.139.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
+ commonmeta_py-0.139.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
+ commonmeta_py-0.139.dist-info/RECORD,,