-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_to_medline.py
37 lines (30 loc) · 1.07 KB
/
convert_to_medline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from pub_data import *
from people import *
from venue import *
def convert_to_medline(pub):
"""
Converts a publication dictionary to a MEDLINE format string.
Args:
pub (dict): A dictionary containing publication information.
Returns:
str: A string formatted in the MEDLINE style.
"""
# Format author names
authors = []
for author in pub['author']:
first, last = people.get(author, (author, None))[0].rsplit(' ', 1)
authors.append(last + ',' + ''.join([f[0].upper() for f in first.split(' ')]))
authors = '\n'.join(f'AU - {author}' for author in authors)
# Format title
title = pub['title']
journal = venue[pub["venue"]][1]
year = pub['year']
# Combine all parts
medline_format = f'{authors}\nTI - {title}\nJT - {journal}\nDP - {year}'
return medline_format
# Convert to MEDLINE format
medline_formatted_publications = [convert_to_medline(pub) for pub in pubs]
with open('pubs_medline.txt', 'w') as fout:
for pub in medline_formatted_publications:
fout.write(pub + '\n\n')