commonmeta-py 0.17.3__py3-none-any.whl → 0.20__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.
Files changed (74) hide show
  1. commonmeta_py/__init__.py +2 -0
  2. {commonmeta_py-0.17.3.dist-info → commonmeta_py-0.20.dist-info}/METADATA +45 -56
  3. commonmeta_py-0.20.dist-info/RECORD +5 -0
  4. {commonmeta_py-0.17.3.dist-info → commonmeta_py-0.20.dist-info}/WHEEL +1 -1
  5. {commonmeta_py-0.17.3.dist-info → commonmeta_py-0.20.dist-info/licenses}/LICENSE +1 -1
  6. commonmeta/__init__.py +0 -96
  7. commonmeta/api_utils.py +0 -77
  8. commonmeta/author_utils.py +0 -261
  9. commonmeta/base_utils.py +0 -121
  10. commonmeta/cli.py +0 -200
  11. commonmeta/constants.py +0 -576
  12. commonmeta/crossref_utils.py +0 -575
  13. commonmeta/date_utils.py +0 -193
  14. commonmeta/doi_utils.py +0 -260
  15. commonmeta/metadata.py +0 -317
  16. commonmeta/readers/__init__.py +0 -1
  17. commonmeta/readers/bibtex_reader.py +0 -0
  18. commonmeta/readers/cff_reader.py +0 -199
  19. commonmeta/readers/codemeta_reader.py +0 -112
  20. commonmeta/readers/commonmeta_reader.py +0 -13
  21. commonmeta/readers/crossref_reader.py +0 -409
  22. commonmeta/readers/crossref_xml_reader.py +0 -508
  23. commonmeta/readers/csl_reader.py +0 -98
  24. commonmeta/readers/datacite_reader.py +0 -384
  25. commonmeta/readers/datacite_xml_reader.py +0 -357
  26. commonmeta/readers/inveniordm_reader.py +0 -199
  27. commonmeta/readers/json_feed_reader.py +0 -422
  28. commonmeta/readers/kbase_reader.py +0 -205
  29. commonmeta/readers/ris_reader.py +0 -103
  30. commonmeta/readers/schema_org_reader.py +0 -493
  31. commonmeta/resources/cff_v1.2.0.json +0 -1827
  32. commonmeta/resources/commonmeta_v0.12.json +0 -601
  33. commonmeta/resources/commonmeta_v0.13.json +0 -571
  34. commonmeta/resources/crossref/AccessIndicators.xsd +0 -47
  35. commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3-elements.xsd +0 -10130
  36. commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3.xsd +0 -48
  37. commonmeta/resources/crossref/JATS-journalpublishing1-elements.xsd +0 -8705
  38. commonmeta/resources/crossref/JATS-journalpublishing1-mathml3-elements.xsd +0 -8608
  39. commonmeta/resources/crossref/JATS-journalpublishing1-mathml3.xsd +0 -49
  40. commonmeta/resources/crossref/JATS-journalpublishing1.xsd +0 -6176
  41. commonmeta/resources/crossref/clinicaltrials.xsd +0 -61
  42. commonmeta/resources/crossref/common5.3.1.xsd +0 -1538
  43. commonmeta/resources/crossref/crossref5.3.1.xsd +0 -1949
  44. commonmeta/resources/crossref/crossref_query_output3.0.xsd +0 -1097
  45. commonmeta/resources/crossref/fundref.xsd +0 -49
  46. commonmeta/resources/crossref/module-ali.xsd +0 -39
  47. commonmeta/resources/crossref/relations.xsd +0 -444
  48. commonmeta/resources/crossref-v0.2.json +0 -60
  49. commonmeta/resources/csl-data.json +0 -538
  50. commonmeta/resources/datacite-v4.5.json +0 -829
  51. commonmeta/resources/ietf-bcp-47.json +0 -3025
  52. commonmeta/resources/iso-8601.json +0 -3182
  53. commonmeta/resources/spdx/licenses.json +0 -4851
  54. commonmeta/resources/spdx-schema..json +0 -903
  55. commonmeta/resources/styles/apa.csl +0 -1697
  56. commonmeta/resources/styles/chicago-author-date.csl +0 -684
  57. commonmeta/resources/styles/harvard-cite-them-right.csl +0 -321
  58. commonmeta/resources/styles/ieee.csl +0 -468
  59. commonmeta/resources/styles/modern-language-association.csl +0 -341
  60. commonmeta/resources/styles/vancouver.csl +0 -376
  61. commonmeta/schema_utils.py +0 -27
  62. commonmeta/translators.py +0 -47
  63. commonmeta/utils.py +0 -1075
  64. commonmeta/writers/__init__.py +0 -1
  65. commonmeta/writers/bibtex_writer.py +0 -149
  66. commonmeta/writers/citation_writer.py +0 -70
  67. commonmeta/writers/commonmeta_writer.py +0 -68
  68. commonmeta/writers/crossref_xml_writer.py +0 -17
  69. commonmeta/writers/csl_writer.py +0 -78
  70. commonmeta/writers/datacite_writer.py +0 -190
  71. commonmeta/writers/ris_writer.py +0 -58
  72. commonmeta/writers/schema_org_writer.py +0 -146
  73. commonmeta_py-0.17.3.dist-info/RECORD +0 -72
  74. commonmeta_py-0.17.3.dist-info/entry_points.txt +0 -3
@@ -1 +0,0 @@
1
- """Writers for different metadata formats"""
@@ -1,149 +0,0 @@
1
- """Bibtex writer for commonmeta-py"""
2
- from bibtexparser.bwriter import BibTexWriter
3
- from bibtexparser.bibdatabase import BibDatabase
4
- from bibtexparser.customization import page_double_hyphen
5
-
6
- from ..utils import pages_as_string
7
- from ..base_utils import compact
8
- from ..author_utils import authors_as_string
9
- from ..date_utils import get_month_from_date, get_iso8601_date, MONTH_SHORT_NAMES
10
- from ..doi_utils import doi_from_url
11
- from ..constants import CM_TO_BIB_TRANSLATIONS, Commonmeta
12
-
13
-
14
- def write_bibtex(metadata: Commonmeta) -> str:
15
- """Write bibtex"""
16
- if metadata.write_errors is not None:
17
- return None
18
- item = write_bibtex_item(metadata)
19
- bibtex_str = """
20
- @comment{
21
- BibTeX entry created by commonmeta-py
22
- }
23
- """
24
- bib_database = BibDatabase()
25
- bib_database.entries = [item]
26
- bib_database.entries[0] = page_double_hyphen(bib_database.entries[0])
27
- writer = BibTexWriter()
28
- writer.common_strings = True
29
- writer.indent = " "
30
- bibtex_str = writer.write(bib_database)
31
-
32
- # Hack to remove curly braces around month names
33
- for month_name in MONTH_SHORT_NAMES:
34
- bibtex_str = bibtex_str.replace(f"{{{month_name}}}", month_name)
35
- return bibtex_str
36
-
37
-
38
- def write_bibtex_item(metadata: Commonmeta) -> dict:
39
- """Write bibtex item"""
40
- container = metadata.container if metadata.container else {}
41
- date_published = get_iso8601_date(metadata.date.get("published", None))
42
- authors = authors_as_string(metadata.contributors)
43
- if metadata.titles and len(metadata.titles) > 1:
44
- title = ": ".join(
45
- [
46
- metadata.titles[0].get("title", None),
47
- metadata.titles[1].get("title", None),
48
- ]
49
- )
50
- elif metadata.titles and len(metadata.titles) == 1:
51
- title = metadata.titles[0].get("title", None)
52
- else:
53
- title = None
54
- doi = doi_from_url(metadata.id)
55
- _id = doi if doi else metadata.id
56
- _type = CM_TO_BIB_TRANSLATIONS.get(metadata.type, "misc")
57
- abstract = (
58
- metadata.descriptions[0].get("description", None)
59
- if metadata.descriptions
60
- else None
61
- )
62
- author = authors if authors and len(authors) > 0 else None
63
- license_ = str(metadata.license.get("url")) if metadata.license else None
64
- institution = metadata.publisher.get("name", None) if _type == "phdthesis" else None
65
- issn = (
66
- container.get("identifier", None)
67
- if container.get("identifierType", None) == "ISSN"
68
- else None
69
- )
70
- isbn = (
71
- container.get("identifier", None)
72
- if container.get("identifierType", None) == "ISBN"
73
- else None
74
- )
75
- issue = container.get("issue", None)
76
- journal = (
77
- container.get("title", None)
78
- if _type not in ["inbook", "inproceedings"]
79
- and container.get("type") in ["Journal", "Periodical"]
80
- else None
81
- )
82
- booktitle = (
83
- container.get("title", None) if _type in ["inbook", "inproceedings"] else None
84
- )
85
- language = metadata.language
86
- location = (
87
- container.get("location", None)
88
- if _type not in ["article", "phdthesis"]
89
- else None
90
- )
91
- month = get_month_from_date(date_published)
92
- pages = pages_as_string(container)
93
- publisher = (
94
- metadata.publisher.get("name", None)
95
- if _type not in ["article", "phdthesis"]
96
- else None
97
- )
98
- series = container.get("series", None)
99
- url = metadata.url
100
- year = date_published[:4] if date_published else None
101
-
102
- return compact(
103
- {
104
- "ID": _id,
105
- "ENTRYTYPE": _type,
106
- "abstract": abstract,
107
- "author": author,
108
- "copyright": license_,
109
- "doi": doi,
110
- "institution": institution,
111
- "isbn": isbn,
112
- "issn": issn,
113
- "issue": issue,
114
- "journal": journal,
115
- "booktitle": booktitle,
116
- "language": language,
117
- "location": location,
118
- "month": month,
119
- "pages": pages,
120
- "publisher": publisher,
121
- "series": series,
122
- "title": title,
123
- "url": url,
124
- "urldate": date_published,
125
- "year": year,
126
- }
127
- )
128
-
129
-
130
- def write_bibtex_list(metalist):
131
- """Write bibtex list"""
132
- if metalist is None:
133
- return None
134
-
135
- bib_database = BibDatabase()
136
- bib_database.entries = [write_bibtex_item(item) for item in metalist.items]
137
-
138
- # TODO: Fix page_double_hyphen in write_bibtex_item
139
- bib_database.entries = [page_double_hyphen(entry) for entry in bib_database.entries]
140
- writer = BibTexWriter()
141
- writer.common_strings = True
142
- writer.indent = " "
143
- bibtex_str = writer.write(bib_database)
144
-
145
- # Hack to remove curly braces around month names
146
- # TODO: Fix this in write_bibtex_item
147
- for month_name in MONTH_SHORT_NAMES:
148
- bibtex_str = bibtex_str.replace(f"{{{month_name}}}", month_name)
149
- return bibtex_str
@@ -1,70 +0,0 @@
1
- """Citation writer for commonmeta-py"""
2
- import orjson as json
3
- import re
4
- from pydash import py_
5
- from citeproc import CitationStylesStyle, CitationStylesBibliography
6
- from citeproc import Citation, CitationItem
7
- from citeproc import formatter
8
- from citeproc.source.json import CiteProcJSON
9
- from citeproc_styles import get_style_filepath
10
-
11
-
12
- def write_citation(metadata):
13
- """Write citation"""
14
-
15
- # Process the JSON data to generate a citeproc-py BibliographySource.
16
- item = write_citation_item(metadata)
17
- style_path = get_style_filepath(metadata.style)
18
- style = CitationStylesStyle(style_path, locale=metadata.locale)
19
- bib = CitationStylesBibliography(style, item, formatter.html)
20
- citation = Citation([CitationItem(metadata.id)])
21
-
22
- # workaround for the issue with the vancouver style and de locale
23
- try:
24
- bib.register(citation)
25
- return _clean_result(str(bib.bibliography()[0]))
26
- except Exception as e:
27
- print(e)
28
- return f"Error: citation not available for style {metadata.style} and locale {metadata.locale}."
29
-
30
-
31
- def write_citation_item(metadata):
32
- """Write citation item"""
33
- if metadata.write_errors is not None:
34
- return None
35
- csl = json.loads(metadata.write(to="csl"))
36
-
37
- # Remove keys that are not supported by citeproc-py.
38
- csl = py_.omit(csl, "copyright", "categories")
39
- return CiteProcJSON([csl])
40
-
41
-
42
- def write_citation_list(metalist, **kwargs):
43
- """Write citation list"""
44
- if metalist is None:
45
- return None
46
-
47
- style = kwargs.get("style", "apa")
48
- locale = kwargs.get("locale", "en-US")
49
- style_path = get_style_filepath(style)
50
- style = CitationStylesStyle(style_path, locale=locale) #
51
-
52
- def format_citation(index, item):
53
- bib = CitationStylesBibliography(style, item, formatter.html)
54
- _id = metalist.items[index].id
55
- citation = Citation([CitationItem(_id)])
56
- bib.register(citation)
57
- return _clean_result(str(bib.bibliography()[0]))
58
-
59
- citations = [write_citation_item(item) for item in metalist.items]
60
- bibliographies = [
61
- format_citation(index, item) for index, item in enumerate(citations)
62
- ]
63
- return "\n\n".join(bibliographies)
64
-
65
-
66
- def _clean_result(text):
67
- """Remove double spaces, punctuation."""
68
- text = re.sub(r"\s\s+", " ", text)
69
- text = re.sub(r"\.\.+", ".", text)
70
- return text
@@ -1,68 +0,0 @@
1
- """Commonmeta writer for commonmeta-py"""
2
-
3
- import orjson as json
4
- import orjsonl
5
- import pydash as py_
6
- from ..base_utils import compact
7
-
8
-
9
- def write_commonmeta(metadata):
10
- """Write commonmeta"""
11
- if metadata is None:
12
- return None
13
-
14
- data = py_.omit(
15
- vars(metadata),
16
- [
17
- "via",
18
- "is_valid",
19
- "date_created",
20
- "date_published",
21
- "date_registered",
22
- "date_updated",
23
- "state",
24
- ],
25
- )
26
- data = py_.rename_keys(
27
- data,
28
- {
29
- "additional_type": "additionalType",
30
- "archive_locations": "archiveLocations",
31
- "geo_locations": "geoLocations",
32
- "funding_references": "fundingReferences",
33
- },
34
- )
35
- return json.dumps(compact(data))
36
-
37
-
38
- def write_commonmeta_list(metalist):
39
- """Write commonmeta list. If filename is provided,
40
- write to file. Optionally, use JSON Lines format."""
41
- if metalist is None:
42
- return None
43
-
44
- def format_item(item):
45
- """Format item for commonmeta list"""
46
- item = py_.omit(vars(item), ["via", "is_valid"])
47
- return compact(item)
48
-
49
- items = [format_item(item) for item in metalist.items]
50
- output = compact(
51
- {
52
- "id": metalist.id,
53
- "title": metalist.title,
54
- "description": metalist.description,
55
- "items": items,
56
- }
57
- )
58
-
59
- if metalist.filename and metalist.filename.rsplit(".", 1)[1] in ["jsonl", "json"]:
60
- if metalist.jsonlines:
61
- orjsonl.save(metalist.filename, items)
62
- else:
63
- json_output = json.dumps(output).decode("utf-8")
64
- with open(metalist.filename, "w") as file:
65
- file.write(json_output)
66
- return metalist.filename
67
- else:
68
- return json.dumps(output).decode("utf-8")
@@ -1,17 +0,0 @@
1
- """Crossref XML writer for commonmeta-py"""
2
- from typing import Optional
3
- from ..constants import Commonmeta
4
- from ..crossref_utils import generate_crossref_xml, generate_crossref_xml_list
5
-
6
-
7
- def write_crossref_xml(metadata: Commonmeta) -> Optional[str]:
8
- """Write Crossref XML"""
9
- return generate_crossref_xml(metadata)
10
-
11
-
12
- def write_crossref_xml_list(metalist):
13
- """Write crossref_xml list"""
14
- if metalist is None:
15
- return None
16
-
17
- return generate_crossref_xml_list(metalist)
@@ -1,78 +0,0 @@
1
- """CSL-JSON writer for commonmeta-py"""
2
- import orjson as json
3
- from typing import Optional
4
-
5
- from ..utils import pages_as_string, to_csl
6
- from ..base_utils import wrap, presence, parse_attributes, compact
7
- from ..date_utils import get_date_parts
8
- from ..doi_utils import doi_from_url
9
- from ..constants import CM_TO_CSL_TRANSLATIONS, Commonmeta
10
-
11
-
12
- def write_csl(metadata: Commonmeta) -> Optional[str]:
13
- """Write CSL-JSON"""
14
- item = write_csl_item(metadata)
15
- if item is None:
16
- return None
17
- return json.dumps(item)
18
-
19
-
20
- def write_csl_item(metadata) -> Optional[dict]:
21
- """Write CSL-JSON item"""
22
- if metadata is None or metadata.write_errors is not None:
23
- return None
24
- if len(wrap(metadata.contributors)) == 0:
25
- author = None
26
- else:
27
- author = to_csl(wrap(metadata.contributors))
28
-
29
- if metadata.type == "Software" and metadata.version is not None:
30
- _type = "book"
31
- else:
32
- _type = CM_TO_CSL_TRANSLATIONS.get(metadata.type, "Document")
33
-
34
- container = metadata.container or {}
35
- publisher = metadata.publisher or {}
36
- return compact(
37
- {
38
- "type": _type,
39
- "id": metadata.id,
40
- "DOI": doi_from_url(metadata.id),
41
- "URL": metadata.url,
42
- "categories": presence(
43
- parse_attributes(
44
- wrap(metadata.subjects), content="subject", first=False
45
- )
46
- ),
47
- "language": metadata.language,
48
- "author": author,
49
- # "contributor": to_csl(wrap(metadata.contributors)),
50
- "issued": get_date_parts(metadata.date.get("published"))
51
- if metadata.date.get("published", None)
52
- else None,
53
- "submitted": get_date_parts(metadata.date.get("submitted"))
54
- if metadata.date.get("submitted", None)
55
- else None,
56
- "accessed": get_date_parts(metadata.date.get("accessed"))
57
- if metadata.date.get("accessed", None) else None,
58
- "abstract": parse_attributes(
59
- metadata.descriptions, content="description", first=True
60
- ),
61
- "container-title": container.get("title", None),
62
- "volume": container.get("volume", None),
63
- "issue": container.get("issue", None),
64
- "page": pages_as_string(container),
65
- "publisher": publisher.get("name", None),
66
- "title": parse_attributes(metadata.titles, content="title", first=True),
67
- "copyright": metadata.license.get("id", None) if metadata.license else None,
68
- "version": metadata.version,
69
- }
70
- )
71
-
72
-
73
- def write_csl_list(metalist):
74
- """Write CSL-JSON list"""
75
- if metalist is None:
76
- return None
77
- items = [write_csl_item(item) for item in metalist.items]
78
- return json.dumps(items)
@@ -1,190 +0,0 @@
1
- """DataCite writer for commonmeta-py"""
2
- import orjson as json
3
- from typing import Optional, Union
4
-
5
- from ..base_utils import wrap, compact
6
- from ..doi_utils import doi_from_url, normalize_doi
7
- from ..constants import (
8
- CM_TO_BIB_TRANSLATIONS,
9
- CM_TO_CSL_TRANSLATIONS,
10
- CM_TO_CR_TRANSLATIONS,
11
- CM_TO_DC_TRANSLATIONS,
12
- CM_TO_RIS_TRANSLATIONS,
13
- CM_TO_SO_TRANSLATIONS,
14
- Commonmeta,
15
- )
16
-
17
-
18
- def write_datacite(metadata: Commonmeta) -> Optional[Union[str, dict]]:
19
- """Write datacite. Make sure JSON Schema validates before writing"""
20
- if metadata.write_errors is not None:
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
- ]
30
-
31
- creators = [
32
- to_datacite_creator(i)
33
- for i in wrap(metadata.contributors)
34
- if i.get("contributorRoles", None) == ["Author"]
35
- ]
36
- contributors = [
37
- to_datacite_creator(i)
38
- for i in wrap(metadata.contributors)
39
- if i.get("contributorRoles", None) != ["Author"]
40
- ]
41
- related_identifiers = [
42
- to_datacite_related_identifier(i)
43
- for i in wrap(metadata.references)
44
- if i.get("id", None)
45
- ]
46
-
47
- resource__typegeneral = CM_TO_DC_TRANSLATIONS.get(metadata.type, "Other")
48
- resource_type = CM_TO_CR_TRANSLATIONS.get(metadata.type, "Other")
49
- if resource__typegeneral == resource_type or resource__typegeneral in [
50
- "Dataset",
51
- "JournalArticle",
52
- "Other",
53
- "Preprint",
54
- "Software",
55
- ]:
56
- resource_type = None
57
- types = compact(
58
- {
59
- "resourceTypeGeneral": resource__typegeneral,
60
- "resourceType": resource_type,
61
- "schemaOrg": CM_TO_SO_TRANSLATIONS.get(metadata.type, "CreativeWork"),
62
- "citeproc": CM_TO_CSL_TRANSLATIONS.get(metadata.type, "article"),
63
- "bibtex": CM_TO_BIB_TRANSLATIONS.get(metadata.type, "misc"),
64
- "ris": CM_TO_RIS_TRANSLATIONS.get(metadata.type, "GEN"),
65
- }
66
- )
67
- publication_year = (
68
- metadata.date.get("published")[:4]
69
- if metadata.date.get("published", None)
70
- else None
71
- )
72
-
73
- def to_datacite_date(date: dict) -> dict:
74
- """Convert dates to datacite dates"""
75
- for k, v in date.items():
76
- if k == "published":
77
- k = "issued"
78
- return {
79
- "date": v,
80
- "dateType": k.title(),
81
- }
82
-
83
- dates = [to_datacite_date(i) for i in wrap(metadata.date)]
84
-
85
- license_ = (
86
- [
87
- compact(
88
- {
89
- "rightsIdentifier": metadata.license.get("id").lower()
90
- if metadata.license.get("id", None)
91
- else None,
92
- "rightsIdentifierScheme": "SPDX",
93
- "rightsUri": metadata.license.get("url", None),
94
- "schemeUri": "https://spdx.org/licenses/",
95
- }
96
- )
97
- ]
98
- if metadata.license
99
- else None
100
- )
101
-
102
- descriptions = [
103
- compact({
104
- "description": i.get("description", None),
105
- "descriptionType": i.get("type", None) or "Other",
106
- "lang": i.get("language", None),
107
- })
108
- for i in wrap(metadata.descriptions)
109
- ]
110
-
111
- data = compact(
112
- {
113
- "id": metadata.id,
114
- "doi": doi_from_url(metadata.id),
115
- "url": metadata.url,
116
- "creators": creators,
117
- "titles": metadata.titles,
118
- "publisher": metadata.publisher,
119
- "publicationYear": publication_year,
120
- "subjects": metadata.subjects,
121
- "contributors": contributors,
122
- "dates": dates,
123
- "language": metadata.language,
124
- "types": types,
125
- "alternateIdentifiers": alternate_identifiers,
126
- "relatedIdentifiers": related_identifiers,
127
- "version": metadata.version,
128
- "rightsList": license_,
129
- "descriptions": descriptions,
130
- "geoLocations": metadata.geo_locations,
131
- "fundingReferences": metadata.funding_references,
132
- "schemaVersion": "http://datacite.org/schema/kernel-4",
133
- }
134
- )
135
- return json.dumps(data)
136
-
137
-
138
- def to_datacite_creator(creator: dict) -> dict:
139
- """Convert creators to datacite creators"""
140
- _type = creator.get("type", None)
141
- if creator.get("familyName", None):
142
- name = ", ".join([creator.get("familyName", ""), creator.get("givenName", "")])
143
- elif creator.get("name", None):
144
- name = creator.get("name", None)
145
- name_identifiers = creator.get("id", None)
146
- if name_identifiers:
147
-
148
- def format_name_identifier(name_identifier):
149
- return {
150
- "nameIdentifier": name_identifier,
151
- "nameIdentifierScheme": "ORCID",
152
- "schemeUri": "https://orcid.org",
153
- }
154
-
155
- name_identifiers = [format_name_identifier(i) for i in wrap(name_identifiers)]
156
- return compact(
157
- {
158
- "name": name,
159
- "givenName": creator.get("givenName", None),
160
- "familyName": creator.get("familyName", None),
161
- "nameType": _type + "al" if _type else None,
162
- "nameIdentifiers": name_identifiers,
163
- "affiliation": creator.get("affiliations", None),
164
- }
165
- )
166
-
167
-
168
- def to_datacite_titles(titles: list) -> list:
169
- """Convert titles to datacite titles"""
170
- return [
171
- {
172
- "title": title.get("title", None),
173
- "titleType": title.get("type", None),
174
- "lang": title.get("language", None),
175
- }
176
- for title in titles
177
- ]
178
-
179
-
180
- def to_datacite_related_identifier(reference: dict) -> dict:
181
- """Convert reference to datacite related_identifier"""
182
- _id = normalize_doi(reference.get("id", None))
183
- url = reference.get("id", None)
184
- return compact(
185
- {
186
- "relatedIdentifier": _id if _id else url,
187
- "relatedIdentifierType": "DOI" if _id else "URL",
188
- "relationType": "References",
189
- }
190
- )
@@ -1,58 +0,0 @@
1
- """RIS writer for commonmeta-py"""
2
- from ..utils import to_ris
3
- from ..base_utils import compact, wrap, presence, parse_attributes
4
- from ..doi_utils import doi_from_url
5
- from ..constants import CM_TO_RIS_TRANSLATIONS
6
-
7
-
8
- def write_ris(metadata):
9
- """Write ris"""
10
- container = metadata.container or {}
11
- _type = CM_TO_RIS_TRANSLATIONS.get(metadata.type, "GEN")
12
- ris = compact(
13
- {
14
- "TY": _type,
15
- "T1": parse_attributes(metadata.titles, content="title", first=True),
16
- "T2": container.get("title", None),
17
- "AU": to_ris(metadata.contributors),
18
- "DO": doi_from_url(metadata.id),
19
- "UR": metadata.url,
20
- "AB": parse_attributes(
21
- metadata.descriptions, content="description", first=True
22
- ),
23
- "KW": presence(
24
- parse_attributes(
25
- wrap(metadata.subjects), content="subject", first=False
26
- )
27
- ),
28
- "PY": metadata.date.get("published")[:4]
29
- if metadata.date.get("published", None)
30
- else None,
31
- "PB": metadata.publisher.get("name", None),
32
- "LA": metadata.language,
33
- "VL": container.get("volume", None),
34
- "IS": container.get("issue", None),
35
- "SP": container.get("firstPage", None),
36
- "EP": container.get("lastPage", None),
37
- # 'SN'= > Array.wrap(related_identifiers).find do | ri |
38
- # ri['relationType'] == 'IsPartOf'
39
- # end.to_h.fetch('relatedIdentifier', nil),
40
- "ER": "",
41
- }
42
- )
43
- string = []
44
- for key, val in ris.items():
45
- if isinstance(val, list) and val not in [[], [None]]:
46
- for vai in val:
47
- string.append(f"{key} - {vai}")
48
- elif val not in [[], [None]]:
49
- string.append(f"{key} - {val}")
50
- return "\r\n".join(string)
51
-
52
-
53
- def write_ris_list(metalist):
54
- """Write RIS list"""
55
- if metalist is None:
56
- return None
57
- items = [write_ris(item) for item in metalist.items]
58
- return "\r\n\r\n".join(items)