-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathauthor_dict.py
154 lines (112 loc) · 4.18 KB
/
author_dict.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
##create author dictionary
pub_authors=[]
##f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\figshare\figshare.txt')
##figshare=[eval(i.strip()) for i in f]
##for i in figshare:
## for author in i[1]:
## pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\peerj\peerj.txt')
peerj=[eval(i.strip()) for i in f]
for i in peerj:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\biorxiv\biorxiv.txt')
biorxiv=[eval(i.strip()) for i in f]
for i in biorxiv:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\f1000research\f1000research.txt')
f1000research=[eval(i.strip()) for i in f]
for i in f1000research:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\arxiv\arxiv.txt')
arxiv=[eval(i.strip()) for i in f]
for i in arxiv:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\winnower\winnower.txt')
winnower=[eval(i.strip()) for i in f]
for i in winnower:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\preprints\preprints.txt')
preprints=[eval(i.strip()) for i in f]
for i in preprints:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\wellcome\wellcome.txt')
wellcome=[eval(i.strip()) for i in f]
for i in wellcome:
for author in i[1]:
pub_authors.append(author)
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\nature\nature.txt')
nature=[eval(i.strip()) for i in f]
for i in nature:
for author in i[1]:
pub_authors.append(author)
def middle_function(name):
if name=='':
return ''
else:
return name[0]
##this is for abb, needed
def first_function(name):
try:
if '-' in name:
name_split=name.split('-')
return name_split[0][0]+name_split[1][0]
else:
return name[0]
except:
return ''
##i'm changing unique to include full first name 2016 04 19
##actually, need two unique lists, one for first name and one for last name
name_first={}
name_last={}
unique_last={}
unique_first={}
for i in pub_authors:
i=i.replace(',','').replace('.','').lower()
if i!='':
if i[:3]=='jr ':
i=i[3:]
if i[-3:]==' jr':
i=i[:-3]
if i[:3]=='sr ':
i=i[3:]
if i[-3:]==' sr':
i=i[:-3]
last_name=i.split()[-1]
if len(i.split())==1:
first_name=''
middle_name=''
elif len(i.split())==2:
first_name=i.split()[0]
middle_name=''
else:
first_name=i.split()[0]
middle_name=i.replace(first_name+' ','').replace(' '+last_name,'').strip()
##need separate unique dictionaries
myauthor_first=(last_name,first_name,middle_function(middle_name))
myauthor_last=(last_name,first_function(first_name),middle_function(middle_name))
if myauthor_first not in unique_first:
unique_first[(last_name,first_name,middle_function(middle_name))]=''
name_first[first_name]=[name_first.get(first_name,[[],[]])[0]+[last_name],\
name_first.get(first_name,[[],[]])[1]+[middle_function(middle_name)]]
if myauthor_last not in unique_last:
unique_last[(last_name,first_function(first_name),middle_function(middle_name))]=''
name_last[last_name]=[name_last.get(last_name,[[],[]])[0]+[first_function(first_name)],\
name_last.get(last_name,[[],[]])[1]+[middle_function(middle_name)]]
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\papers\unique_last.py','w')
f.write('unique_last='+str(unique_last))
f.close()
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\papers\unique_first.py','w')
f.write('unique_first='+str(unique_first))
f.close()
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\papers\name_last.py','w')
f.write('name_last='+str(name_last))
f.close()
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\papers\name_first.py','w')
f.write('name_first='+str(name_first))
f.close()