commonmeta-py 0.32__py3-none-any.whl → 0.33__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.32"
13
+ __version__ = "0.33"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
@@ -112,9 +112,11 @@ def insert_group_title(metadata, xml):
112
112
  """Insert group title"""
113
113
  if metadata.subjects is None or len(metadata.subjects) == 0:
114
114
  return xml
115
- etree.SubElement(xml, "group_title").text = metadata.subjects[0].get(
116
- "subject", None
117
- )
115
+ group_title = metadata.subjects[0].get("subject", None)
116
+ # strip optional FOS (Field of Science) prefix
117
+ if group_title.startswith("FOS: "):
118
+ group_title = group_title[5:]
119
+ etree.SubElement(xml, "group_title").text = group_title
118
120
  return xml
119
121
 
120
122
 
@@ -114,7 +114,10 @@ def read_json_feed_item(data: Optional[dict], **kwargs) -> Commonmeta:
114
114
  if category is not None:
115
115
  subjects = [name_to_fos(py_.human_case(category))]
116
116
  else:
117
- subjects = None
117
+ subjects = []
118
+ tags = wrap(py_.get(meta, "tags", None))
119
+ if tags is not None:
120
+ subjects += wrap([format_subject(i) for i in tags])
118
121
  references = get_references(wrap(meta.get("reference", None)))
119
122
  funding_references = get_funding_references(meta)
120
123
  relations = get_relations(wrap(meta.get("relationships", None)))
@@ -414,13 +417,10 @@ def get_json_feed_blog_slug(id: str):
414
417
  return py_.get(post, "blog.slug", None)
415
418
 
416
419
 
417
- def get_json_feed_blog_slug(id: str):
418
- """get JSON Feed item by id and return blog slug"""
419
- if id is None:
420
+ def format_subject(subject: str) -> Optional[dict]:
421
+ """format subject"""
422
+ if subject is None or not isinstance(subject, str):
420
423
  return None
421
- url = f"https://api.rogue-scholar.org/posts/#{id}"
422
- response = httpx.get(url, timeout=10)
423
- if response.status_code != 200:
424
- return None
425
- post = response.json()
426
- return py_.get(post, "blog.slug", None)
424
+ return {
425
+ "subject": subject,
426
+ }
commonmeta/utils.py CHANGED
@@ -77,6 +77,57 @@ UNKNOWN_INFORMATION = {
77
77
  HTTP_SCHEME = "http://"
78
78
  HTTPS_SCHEME = "https://"
79
79
 
80
+ FOS_MAPPINGS = {
81
+ "Natural sciences": "http://www.oecd.org/science/inno/38235147.pdf?1",
82
+ "Mathematics": "http://www.oecd.org/science/inno/38235147.pdf?1.1",
83
+ "Computer and information sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.2",
84
+ "Physical sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.3",
85
+ "Chemical sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.4",
86
+ "Earth and related environmental sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.5",
87
+ "Biological sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.6",
88
+ "Other natural sciences": "http://www.oecd.org/science/inno/38235147.pdf?1.7",
89
+ "Engineering and technology": "http://www.oecd.org/science/inno/38235147.pdf?2",
90
+ "Civil engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.1",
91
+ "Electrical engineering, electronic engineering, information engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.2",
92
+ "Mechanical engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.3",
93
+ "Chemical engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.4",
94
+ "Materials engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.5",
95
+ "Medical engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.6",
96
+ "Environmental engineering": "http://www.oecd.org/science/inno/38235147.pdf?2.7",
97
+ "Environmental biotechnology": "http://www.oecd.org/science/inno/38235147.pdf?2.8",
98
+ "Industrial biotechnology": "http://www.oecd.org/science/inno/38235147.pdf?2.9",
99
+ "Nano technology": "http://www.oecd.org/science/inno/38235147.pdf?2.10",
100
+ "Other engineering and technologies": "http://www.oecd.org/science/inno/38235147.pdf?2.11",
101
+ "Medical and health sciences": "http://www.oecd.org/science/inno/38235147.pdf?3",
102
+ "Basic medicine": "http://www.oecd.org/science/inno/38235147.pdf?3.1",
103
+ "Clinical medicine": "http://www.oecd.org/science/inno/38235147.pdf?3.2",
104
+ "Health sciences": "http://www.oecd.org/science/inno/38235147.pdf?3.3",
105
+ "Health biotechnology": "http://www.oecd.org/science/inno/38235147.pdf?3.4",
106
+ "Other medical sciences": "http://www.oecd.org/science/inno/38235147.pdf?3.5",
107
+ "Agricultural sciences": "http://www.oecd.org/science/inno/38235147.pdf?4",
108
+ "Agriculture, forestry, and fisheries": "http://www.oecd.org/science/inno/38235147.pdf?4.1",
109
+ "Animal and dairy science": "http://www.oecd.org/science/inno/38235147",
110
+ "Veterinary science": "http://www.oecd.org/science/inno/38235147",
111
+ "Agricultural biotechnology": "http://www.oecd.org/science/inno/38235147",
112
+ "Other agricultural sciences": "http://www.oecd.org/science/inno/38235147",
113
+ "Social science": "http://www.oecd.org/science/inno/38235147.pdf?5",
114
+ "Psychology": "http://www.oecd.org/science/inno/38235147.pdf?5.1",
115
+ "Economics and business": "http://www.oecd.org/science/inno/38235147.pdf?5.2",
116
+ "Educational sciences": "http://www.oecd.org/science/inno/38235147.pdf?5.3",
117
+ "Sociology": "http://www.oecd.org/science/inno/38235147.pdf?5.4",
118
+ "Law": "http://www.oecd.org/science/inno/38235147.pdf?5.5",
119
+ "Political science": "http://www.oecd.org/science/inno/38235147.pdf?5.6",
120
+ "Social and economic geography": "http://www.oecd.org/science/inno/38235147.pdf?5.7",
121
+ "Media and communications": "http://www.oecd.org/science/inno/38235147.pdf?5.8",
122
+ "Other social sciences": "http://www.oecd.org/science/inno/38235147.pdf?5.9",
123
+ "Humanities": "http://www.oecd.org/science/inno/38235147.pdf?6",
124
+ "History and archaeology": "http://www.oecd.org/science/inno/38235147.pdf?6.1",
125
+ "Languages and literature": "http://www.oecd.org/science/inno/38235147.pdf?6.2",
126
+ "Philosophy, ethics and religion": "http://www.oecd.org/science/inno/38235147.pdf?6.3",
127
+ "Arts (arts, history of arts, performing arts, music)": "http://www.oecd.org/science/inno/38235147.pdf?6.4",
128
+ "Other humanities": "http://www.oecd.org/science/inno/38235147.pdf?6.5",
129
+ }
130
+
80
131
 
81
132
  def normalize_id(pid: Optional[str], **kwargs) -> Optional[str]:
82
133
  """Check for valid DOI or HTTP(S) URL"""
@@ -982,45 +1033,12 @@ def subjects_as_string(subjects):
982
1033
 
983
1034
  def name_to_fos(name: str) -> Optional[dict]:
984
1035
  """Convert name to Fields of Science (OECD) subject"""
985
- # # first find subject in Fields of Science (OECD)
986
- # fos = JSON.load(File.read(File.expand_path('../../resources/oecd/fos-mappings.json',
987
- # __dir__))).fetch('fosFields')
988
-
989
- # subject = fos.find { |l| l['fosLabel'] == name || 'FOS: ' + l['fosLabel'] == name }
990
-
991
- # if subject
992
- # return [{
993
- # 'subject': sanitize(name).downcase
994
- # },
995
- # {
996
- # 'subject': 'FOS: ' + subject['fosLabel'],
997
- # 'subjectScheme': 'Fields of Science and Technology (FOS)',
998
- # 'schemeUri': 'http://www.oecd.org/science/inno/38235147.pdf'
999
- # }]
1000
- # end
1001
1036
 
1002
- # # if not found, look in Fields of Research (Australian and New Zealand Standard Research Classification)
1003
- # # and map to Fields of Science. Add an extra entry for the latter
1004
- # fores = JSON.load(File.read(File.expand_path('../../resources/oecd/for-mappings.json',
1005
- # __dir__)))
1006
- # for_fields = fores.fetch('forFields')
1007
- # for_disciplines = fores.fetch('forDisciplines')
1008
-
1009
- # subject = for_fields.find { |l| l['forLabel'] == name } ||
1010
- # for_disciplines.find { |l| l['forLabel'] == name }
1011
-
1012
- # if subject
1013
- # [{
1014
- # 'subject': sanitize(name).downcase
1015
- # },
1016
- # {
1017
- # 'subject': 'FOS: ' + subject['fosLabel'],
1018
- # 'subjectScheme': 'Fields of Science and Technology (FOS)',
1019
- # 'schemeUri': 'http://www.oecd.org/science/inno/38235147.pdf'
1020
- # }]
1021
- # else
1022
-
1023
- return {"subject": name.strip()}
1037
+ subject = name.strip()
1038
+ fos_subject = FOS_MAPPINGS.get(name, None)
1039
+ if fos_subject is not None:
1040
+ return {"subject": f"FOS: {subject}"}
1041
+ return {"subject": subject}
1024
1042
 
1025
1043
 
1026
1044
  def encode_doi(prefix):
@@ -1112,10 +1130,10 @@ def id_from_url(url: Optional[str]) -> Optional[str]:
1112
1130
  """Return a ID from a URL"""
1113
1131
  if url is None:
1114
1132
  return None
1115
-
1133
+
1116
1134
  f = furl(url)
1117
1135
  # check for allowed scheme if string is a URL
1118
1136
  if f.host is not None and f.scheme not in ["http", "https", "ftp"]:
1119
1137
  return None
1120
-
1138
+
1121
1139
  return str(f.path).strip("/")
@@ -3,11 +3,11 @@
3
3
  import orjson as json
4
4
  from typing import Optional
5
5
 
6
- from ..base_utils import compact, wrap, parse_attributes
6
+ from ..base_utils import compact, wrap, parse_attributes, presence
7
7
  from ..date_utils import get_iso8601_date
8
8
  from ..doi_utils import doi_from_url
9
9
  from ..constants import CM_TO_INVENIORDM_TRANSLATIONS, INVENIORDM_IDENTIFIER_TYPES
10
- from ..utils import get_language, validate_orcid, id_from_url
10
+ from ..utils import get_language, validate_orcid, id_from_url, FOS_MAPPINGS
11
11
 
12
12
 
13
13
  def write_inveniordm(metadata):
@@ -73,7 +73,7 @@ def write_inveniordm(metadata):
73
73
  "type": {"id": "updated"},
74
74
  }
75
75
  ],
76
- "subjects": subjects,
76
+ "subjects": presence(subjects),
77
77
  "description": parse_attributes(
78
78
  metadata.descriptions, content="description", first=True
79
79
  ),
@@ -133,12 +133,22 @@ def to_inveniordm_creator(creator: dict) -> dict:
133
133
  )
134
134
 
135
135
 
136
- def to_inveniordm_subject(subject: dict) -> dict:
137
- """Convert subjects to inveniordm subjects"""
136
+ def to_inveniordm_subject(sub: dict) -> Optional[dict]:
137
+ """Convert subject to inveniordm subject"""
138
+ if sub.get("subject", None) is None:
139
+ return None
140
+ if sub.get("subject").startswith("FOS: "):
141
+ subject = sub.get("subject")[5:]
142
+ id_ = FOS_MAPPINGS.get(subject, None)
143
+ return compact(
144
+ {
145
+ "id": id_,
146
+ "subject": subject,
147
+ }
148
+ )
138
149
  return compact(
139
150
  {
140
- "id": subject.get("id", None),
141
- "subject": subject.get("subject", None),
151
+ "subject": sub.get("subject"),
142
152
  }
143
153
  )
144
154
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commonmeta-py
3
- Version: 0.32
3
+ Version: 0.33
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,10 +1,10 @@
1
- commonmeta/__init__.py,sha256=39W6oIc0av4brPAFRuXXJ5wLX43-XDRtrl6X1evn1Oc,1779
1
+ commonmeta/__init__.py,sha256=2iZDueWNzIzIbOQjnBw80FTSqsczN0N6HAFrBEDRI8Q,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
6
  commonmeta/constants.py,sha256=fB2oMjnPYCJG3Zx6080u0R0ujmXkPRLGSgYOulWyOFw,16411
7
- commonmeta/crossref_utils.py,sha256=uffkjbs3732yCzD7hEA5lZ9ZZ648Mftl_n0GGcnEPHc,21918
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
10
10
  commonmeta/metadata.py,sha256=dqqk4IW-_OwtS_PVs0i7AuxrkNqOYjJCqhQJ2X-I1DQ,12398
@@ -19,7 +19,7 @@ commonmeta/readers/csl_reader.py,sha256=5V_sHSJwcAWJmhB8SYk199nB96BWYX1Sq9vkQ3iE
19
19
  commonmeta/readers/datacite_reader.py,sha256=CdOtxhthrakBoQMsLTdPx6sUCmqtEWo5ICYE6ZsWDdo,12026
20
20
  commonmeta/readers/datacite_xml_reader.py,sha256=nhnO92fZihr1HZlbXjyem-HJXc9_DWLgJ2zeltuPMIg,13041
21
21
  commonmeta/readers/inveniordm_reader.py,sha256=ejhpj4KX6bJU79lKrkTQeG3AATw0h2DdNdieNlx5j0w,7521
22
- commonmeta/readers/json_feed_reader.py,sha256=_rOAIGhBoEwmNbGGlYixEzVHhUszVNlzmwkjqFQY1kw,13946
22
+ commonmeta/readers/json_feed_reader.py,sha256=YUJlZ7P44HEb-VKZHGr84ePGmHTVnfco_K36koooKnQ,13917
23
23
  commonmeta/readers/kbase_reader.py,sha256=NpIK-_fh5QFN4Q_ArqcrnH4tS5zR1gqbPew6VEjrUbs,6764
24
24
  commonmeta/readers/ris_reader.py,sha256=v6qOd-i2OcMTEFy5RGd3MlYthJcYSU6yzmZ5yHDzmII,3677
25
25
  commonmeta/readers/schema_org_reader.py,sha256=xyWzO2XAWlI2pYVl2EbVRsUmfiWXEwP64CHRBQNRN-M,16835
@@ -57,7 +57,7 @@ commonmeta/resources/styles/modern-language-association.csl,sha256=HI2iU4krze1aH
57
57
  commonmeta/resources/styles/vancouver.csl,sha256=lun3_i2oTilgsANk4LjFao2UDPQlGj_hgFgKAWC_DF8,12878
58
58
  commonmeta/schema_utils.py,sha256=Ep8suJgqtgDAvbjVkQxwzAY1MqwwqPwNRKDTMAxMQTg,915
59
59
  commonmeta/translators.py,sha256=RpGJtKNLjmz41VREZDY7KyyE2eXOi8j7m-da4jHmknI,1362
60
- commonmeta/utils.py,sha256=3OX4BfOkDTkHye4-xpGoTfMrPMvN-02FdS_IBOfoRvw,39796
60
+ commonmeta/utils.py,sha256=TjspdiI9g6WEcbvEiUOc6ARV7j_PHAdY2nRrEHrNXQs,42310
61
61
  commonmeta/writers/__init__.py,sha256=47-snms6xBHkoEXKYV1DBtH1npAtlVtvY29Z4Zr45qI,45
62
62
  commonmeta/writers/bibtex_writer.py,sha256=s3hIJIgWvSG7TAriZMRQEAyuitw6ebwWSI1YcYFQ-do,4971
63
63
  commonmeta/writers/citation_writer.py,sha256=RjaNh9EALxq6gfODLRWVJxGxPArGd6ZiHUlkYnCT6MA,2355
@@ -65,11 +65,11 @@ commonmeta/writers/commonmeta_writer.py,sha256=2qlttCfYpGhfVjrYkjzbIra7AywssRLT3
65
65
  commonmeta/writers/crossref_xml_writer.py,sha256=0Ds494RnXfdfjWw5CLX1kwV2zP7gqffdVqO-X74Uc6c,492
66
66
  commonmeta/writers/csl_writer.py,sha256=rlCeShkvC6ui9By0yVfNCMay_JfaZ4AooUPOPg-g-2M,2819
67
67
  commonmeta/writers/datacite_writer.py,sha256=G7Lr0aZ4sAEdbfXe3dG4Y6AyGUKA9UWr_iiaQRDnV24,6233
68
- commonmeta/writers/inveniordm_writer.py,sha256=oWxGweLdIUSw0pcP9SHlS0XCUYV-WqiuR4owKdkAps4,5499
68
+ commonmeta/writers/inveniordm_writer.py,sha256=c4Z-s_fME_Kke4Wc5Hv2GhwxecxhOiThjHYSLpTONTs,5804
69
69
  commonmeta/writers/ris_writer.py,sha256=AcnCszS3WY9lF594NbFBtLylsA8ownnYp_XLQJ84Ios,2093
70
70
  commonmeta/writers/schema_org_writer.py,sha256=5j002uCNLdlScZMNQmPjodcVWqaBh2z38zL1H4lo2hY,5741
71
- commonmeta_py-0.32.dist-info/LICENSE,sha256=746hEF2wZCKkcckk5-_DcBLtHewfaEMS4iXTlA1PVwk,1074
72
- commonmeta_py-0.32.dist-info/METADATA,sha256=jrhitlV03nvAJ8VaKjwqHHK6tegUJrnsvEi9TcpfbqI,8331
73
- commonmeta_py-0.32.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
74
- commonmeta_py-0.32.dist-info/entry_points.txt,sha256=vbcDw3_2lMTKdcAL2VUF4DRYRpKuzXVYLMCdgKVf88U,49
75
- commonmeta_py-0.32.dist-info/RECORD,,
71
+ commonmeta_py-0.33.dist-info/LICENSE,sha256=746hEF2wZCKkcckk5-_DcBLtHewfaEMS4iXTlA1PVwk,1074
72
+ commonmeta_py-0.33.dist-info/METADATA,sha256=G7zkJ6L1biUiEGKgUMYY1a1xTdzRdxApaKjPZR22tSA,8331
73
+ commonmeta_py-0.33.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
74
+ commonmeta_py-0.33.dist-info/entry_points.txt,sha256=vbcDw3_2lMTKdcAL2VUF4DRYRpKuzXVYLMCdgKVf88U,49
75
+ commonmeta_py-0.33.dist-info/RECORD,,