Skip to content

Commit bfc2ca1

Browse files
committed
improve resulttype mapping in bibtex
1 parent ef602e0 commit bfc2ca1

1 file changed

Lines changed: 156 additions & 5 deletions

File tree

server/workers/api/src/apis/export.py

Lines changed: 156 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,43 @@ def transform2bibtex(metadata):
2020
id = metadata.get("id", "")
2121
published_in = metadata.get("published_in", "")
2222
url = metadata.get("list_link", {}).get("address", "")
23+
24+
bibtextypes = [get_bibtextype(r) for r in metadata.get("resulttype")]
25+
if len(bibtextypes) == 0 or set(bibtextypes) == {"misc"}:
26+
entrytype = "misc"
27+
else:
28+
entrytype = list(filter(lambda x: x != "misc", bibtextypes))[0]
2329
fields = {
2430
"title": title,
2531
"author": author,
2632
"year": year,
27-
"doi": doi,
28-
"journal": published_in,
29-
"url": url,
30-
"ENTRYTYPE": "article",
3133
"ID": id
3234
}
35+
if doi != "":
36+
fields["doi"] = doi
37+
if url != "":
38+
fields["url"] = url
39+
if entrytype == "article":
40+
if published_in != "":
41+
fields["journal"] = published_in
42+
else:
43+
entrytype = "misc"
44+
if entrytype == "misc" and published_in != "":
45+
entrytype = "article"
46+
if entrytype == "book":
47+
fields["publisher"] = published_in
48+
if entrytype == "inbook":
49+
fields["publisher"] = published_in
50+
if entrytype == "inproceedings":
51+
fields["booktitle"] = published_in
52+
if entrytype == "phdthesis":
53+
fields["school"] = published_in
54+
if entrytype == "mastersthesis":
55+
fields["school"] = published_in
56+
if entrytype == "conference":
57+
fields["booktitle"] = published_in
58+
fields["ENTRYTYPE"] = entrytype
59+
3360
db = BibDatabase()
3461
writer = BibTexWriter()
3562
db.entries.append(fields)
@@ -89,4 +116,128 @@ def get(self):
89116
class Healthcheck(Resource):
90117
def get(self):
91118
result = {"status": "I'm good"}
92-
return make_response(result, 200, {"Content-Type": "application/json"})
119+
return make_response(result, 200, {"Content-Type": "application/json"})
120+
121+
122+
123+
def get_bibtextype(resulttype):
124+
mapper = {
125+
"Audio": "audio",
126+
"Book": "book",
127+
"Book part": "inbook",
128+
"Conference object": "conference / inproceedings // proceedings",
129+
"Course material": "misc",
130+
"Dataset": "misc",
131+
"Image/video": "misc",
132+
"Journal/newspaper": "misc",
133+
"Journal/newspaper article": "article",
134+
"Journal/newspaper other content": "misc",
135+
"Lecture": "misc",
136+
"Manuscript": "unpublished / misc",
137+
"Map": "misc",
138+
"Moving image/video": "video",
139+
"Musical notation": "misc",
140+
"Other/Unknown material": "misc",
141+
"Patent": "patent",
142+
"Report": "techreport / report",
143+
"Review": "misc",
144+
"Software": "software",
145+
"Still image": "misc",
146+
"Text": "misc",
147+
"Thesis": "thesis",
148+
"Thesis: bachelor": "thesis",
149+
"Thesis: doctoral and postdoctoral": "phdthesis",
150+
"Thesis: master": "mastersthesis",
151+
"Adaptive Clinical Trial": "misc",
152+
"Address": "misc",
153+
"Autobiography": "book",
154+
"Bibliography": "misc",
155+
"Biography": "book",
156+
"Book Illustrations": "misc",
157+
"Case Reports": "misc",
158+
"Classical Article": "article",
159+
"Clinical Conference": "conference",
160+
"Clinical Study": "misc",
161+
"Clinical Trial": "misc",
162+
"Clinical Trial Protocol": "misc",
163+
"Clinical Trial, Phase I": "misc",
164+
"Clinical Trial, Phase II": "misc",
165+
"Clinical Trial, Phase III": "misc",
166+
"Clinical Trial, Phase IV": "misc",
167+
"Clinical Trial, Veterinary": "misc",
168+
"Collected Work": "misc",
169+
"Collected Works": "misc",
170+
"Comment": "misc",
171+
"Comparative Study": "misc",
172+
"Congress": "conference",
173+
"Consensus Development Conference": "conference",
174+
"Consensus Development Conference, NIH": "conference",
175+
"Controlled Clinical Trial": "misc",
176+
"Corrected and Republished Article": "article",
177+
"Dataset": "misc",
178+
"Dictionary": "misc",
179+
"Directory": "misc",
180+
"Duplicate Publication": "misc",
181+
"Editorial": "article",
182+
"Electronic Supplementary Materials": "electronic",
183+
"English Abstract": "misc",
184+
"Ephemera": "misc",
185+
"Equivalence Trial": "misc",
186+
"Evaluation Studies": "misc",
187+
"Evaluation Study": "misc",
188+
"Expression of Concern": "misc",
189+
"Festschrift": "misc",
190+
"Government Publication": "misc",
191+
"Guideline": "misc",
192+
"Historical Article": "article",
193+
"Interactive Tutorial": "misc",
194+
"Interview": "misc",
195+
"Introductory Journal Article": "article",
196+
"Journal Article": "article",
197+
"Lecture": "misc",
198+
"Legal Case": "misc",
199+
"Legislation": "misc",
200+
"Letter": "misc",
201+
"Manuscript": "unpublished",
202+
"Meta-Analysis": "misc",
203+
"Multicenter Study": "misc",
204+
"News": "misc",
205+
"Newspaper Article": "article",
206+
"Observational Study": "misc",
207+
"Observational Study, Veterinary": "misc",
208+
"Overall": "misc",
209+
"Patient Education Handout": "misc",
210+
"Periodical Index": "misc",
211+
"Personal Narrative": "misc",
212+
"Pictorial Work": "misc",
213+
"Popular Work": "misc",
214+
"Portrait": "misc",
215+
"Practice Guideline": "misc",
216+
"Pragmatic Clinical Trial": "misc",
217+
"Preprint": "misc",
218+
"Publication Components": "misc",
219+
"Publication Formats": "misc",
220+
"Publication Type Category": "misc",
221+
"Published Erratum": "misc",
222+
"Randomized Controlled Trial": "misc",
223+
"Randomized Controlled Trial, Veterinary": "misc",
224+
"Research Support, American Recovery and Reinvestment Act": "misc",
225+
"Research Support, N.I.H., Extramural": "misc",
226+
"Research Support, N.I.H., Intramural": "misc",
227+
"Research Support, Non-U.S. Gov't": "misc",
228+
"Research Support, U.S. Gov't, Non-P.H.S.": "misc",
229+
"Research Support, U.S. Gov't, P.H.S.": "misc",
230+
"Retracted Publication": "misc",
231+
"Retraction of Publication": "misc",
232+
"Review": "misc",
233+
"Scientific Integrity Review": "misc",
234+
"Study Characteristics": "misc",
235+
"Support of Research": "misc",
236+
"Systematic Review": "misc",
237+
"Technical Report": "techreport / report",
238+
"Twin Study": "misc",
239+
"Validation Study": "misc",
240+
"Video Audio Media": "video",
241+
"Webcasts": "misc"
242+
}
243+
return mapper.get(resulttype, "article")

0 commit comments

Comments
 (0)