1- import re
21from datetime import date
32from types import SimpleNamespace
43from typing import Literal
2019 Venue ,
2120 VenueType ,
2221)
23- from ..utils import url_to_id
2422from .fetch import register_fetch
25- from .formats import institution_from_ror , paper_from_jats
23+ from .formats import paper_from_crossref , paper_from_jats
2624
2725
2826@register_fetch
@@ -48,106 +46,7 @@ def crossref(type: Literal["doi"], link: str):
4846 raise Exception ("Request failed" , data )
4947
5048 data = SimpleNamespace (** data ["message" ])
51-
52- releases = []
53- if getattr (data , "event" , None ) or getattr (data , "container-title" , None ):
54- date_parts = None
55-
56- if evt := getattr (data , "event" , None ):
57- venue_name = evt ["name" ]
58- venue_type = VenueType .conference
59- if "start" in evt :
60- date_parts = evt ["start" ]["date-parts" ][0 ]
61-
62- if venue := getattr (data , "container-title" , None ):
63- venue_name = venue [0 ]
64- if data .type == "journal-article" :
65- venue_type = VenueType .journal
66- else :
67- venue_type = VenueType .conference
68-
69- if not date_parts :
70- for field in (
71- "published-online" ,
72- "published-print" ,
73- "published" ,
74- "issued" ,
75- "created" ,
76- ):
77- if dateholder := getattr (data , field , None ):
78- date_parts = dateholder ["date-parts" ][0 ]
79- break
80-
81- precision = [
82- DatePrecision .year ,
83- DatePrecision .month ,
84- DatePrecision .day ,
85- ][len (date_parts ) - 1 ]
86- date_parts += [1 ] * (3 - len (date_parts ))
87- release = Release (
88- venue = Venue (
89- aliases = [],
90- name = venue_name ,
91- type = venue_type ,
92- series = venue_name ,
93- links = [],
94- open = False ,
95- peer_reviewed = False ,
96- publisher = None ,
97- date_precision = precision ,
98- date = date (* date_parts ),
99- ),
100- status = "published" ,
101- pages = None ,
102- )
103- releases = [release ]
104-
105- required_keys = {"given" , "family" , "affiliation" }
106-
107- def extract_affiliation (aff ):
108- if "id" in aff and isinstance (aff ["id" ], list ):
109- for id_entry in aff ["id" ]:
110- if (
111- isinstance (id_entry , dict )
112- and id_entry .get ("id-type" ) == "ROR"
113- and "id" in id_entry
114- ):
115- ror_url = id_entry ["id" ]
116- _ , ror_id = url_to_id (ror_url )
117- return institution_from_ror (ror_id )
118-
119- else :
120- return Institution (
121- name = aff ["name" ],
122- category = InstitutionCategory .unknown ,
123- aliases = [],
124- )
125-
126- abstract = getattr (data , "abstract" , None )
127- if abstract :
128- abstract = re .sub (r"<jats:title>.*</jats:title>" , "" , abstract )
129- abstract = re .sub (r"</?jats:[^>]+>" , "" , abstract )
130-
131- return Paper (
132- title = data .title [0 ],
133- authors = [
134- PaperAuthor (
135- display_name = (dn := f"{ author ['given' ]} { author ['family' ]} " ),
136- author = Author (name = dn ),
137- affiliations = [
138- extract_affiliation (aff )
139- for aff in author ["affiliation" ]
140- if "name" in aff
141- ],
142- )
143- for author in data .author
144- if not (required_keys - author .keys ())
145- ],
146- abstract = abstract ,
147- links = [Link (type = "doi" , link = doi )],
148- topics = [],
149- releases = releases ,
150- )
49+ return paper_from_crossref (data )
15150
15251
15352@register_fetch
@@ -301,8 +200,13 @@ def datacite(type: Literal["doi"], link: str):
301200 identifier = related_identifier ["relatedIdentifier" ]
302201 # Available identifier types:
303202 # ARK arXiv bibcode DOI EAN13 EISSN Handle IGSN ISBN ISSN ISTC LISSN LSID PMID PURL UPC URL URN w3id
304- if identifier_type in {"ARK" , "arXiv" , "DOI" , "PURL" , "URL" , "w3id" }:
305- links .append (Link (type = f"{ relation_type } .{ identifier_type } " , link = identifier ))
203+ allowed_types = {"ARK" , "arXiv" , "DOI" , "PURL" , "URL" , "w3id" }
204+ if relation_type == "IsVersionOf" and identifier_type in allowed_types :
205+ identifier_type = identifier_type .lower ()
206+ normalized_identifier = (
207+ identifier .lower () if identifier_type == "doi" else identifier
208+ )
209+ links .append (Link (type = f"{ identifier_type } " , link = normalized_identifier ))
306210
307211 return Paper (
308212 title = raw_paper .titles [0 ]["title" ],
0 commit comments