/
genpubs.py
executable file
·282 lines (234 loc) · 5.87 KB
/
genpubs.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import click
import yaml
import sys
mine = """Daniel Alabi
Fotis Psallidas
Pavan Kalyan
Zachary Huang
Lana Ramjit
Lampros Flokas
Gabriel Ryan
Hamed Nilforoshan
Haneen Mohammed
Qianrui Zhang
Viraj Rai
Jacob Fisher
Haoci Zhang
Ian Yiran Huang
Lauren Arnett
Robert Netzorg
James Sands
Kevin Lin
Rahul Khanna
Thibault Sellam
Yiliang Shi
Yiru Chen
Jeffrey Tao
Pavan Kalyan
Jiaxiang Liu
Yilan Jiang
Zezhou Huang
Alexander Yao
Charlie Summers
Charles Summers
Zhengjie Miao"""
mine = set([auth.strip().lower() for auth in mine.split("\n")])
def format_auth(auth):
parts = auth.split()
name = []
for part in parts[:-1]:
name.append(part[0] + ".")
name.append(parts[-1])
name = " ".join(name)
if auth.lower() in mine:
return "\\underline{\\bf %s}" % name
if auth.lower() == "eugene wu":
return "\\underline{%s}" % name
else:
return name
def format_text_auth(auth):
parts = auth.split()
name = []
for part in parts[:-1]:
name.append(part[0] + ".")
name.append(parts[-1])
name = " ".join(name)
return name
def format_auths(auths):
return ", ".join(map(format_auth, auths))
def format_bibtex_auth(auth):
parts = auth.split()
name = ", ".join([parts[-1], parts[0]])
return name
def format_bibtex_auths(auths):
return " and ".join(map(format_bibtex_auth, auths))
def format_text_auths(auths):
return ", ".join(map(format_text_auth, auths))
def print_pub(pub):
if not pub: return
try:
auths = pub.get("authors", "")
auths = [auth.strip() for auth in auths.split(",")]
auths = format_auths(auths)
title = pub.get("title", "")
title = title.strip(".")
conf = pub.get("conf", "")
conf = conf.strip(".")
rate = pub.get("rate", "")
citations = pub.get("citations", "")
misc = []
if rate:
misc.append("acceptance rate: %s\\%%" % rate)
if citations:
misc.append("citations: %d" % citations)
misc = ", ".join(misc)
if misc:
misc = "(%s)" % misc
return "%s. ``{\\it %s.}'' %s. %s" % (auths, title, conf, misc)
except Exception as e:
print(e)
print(pub)
raise e
def print_text_pub(pub):
try:
auths = pub.get("authors", "")
auths = [auth.strip() for auth in auths.split(",")]
auths = format_text_auths(auths)
title = pub.get("title", "")
title = title.strip(".")
conf = pub.get("conf", "")
conf = conf.strip(".")
return "%s. ''%s.'' %s." % (auths, title, conf)
except Exception as e:
print(e)
print(pub)
raise e
def print_bibtex(pub, id):
try:
auths = pub.get("authors", "")
auths = [auth.strip() for auth in auths.split(",")]
auths = format_bibtex_auths(auths)
title = pub.get("title", "")
title = title.strip(".")
conf = get_conf_name(pub)
conf = conf.strip(".")
year = get_year(pub)
return """
@inproceedings{pub%s,
title={%s},
author={%s},
booktitle={%s},
year={%s}
}
""" % (id, title, auths, conf, year)
except Exception as e:
print(e)
print(pub)
raise e
def print_medline(pub, id):
try:
auths = pub.get("authors", "")
auths = [auth.strip() for auth in auths.split(",")]
auths = "\n".join(["AU - %s,\r" % a.replace(" ", "") for a in map(format_bibtex_auth, auths)])
title = pub.get("title", "")
title = title.strip(".")
conf = get_conf_name(pub)
conf = conf.strip(".")
year = get_year(pub)
return """TI - %s\r
DP - %s\r
%s\r
PG - \r
TA - %s\r
\r""" % (title, year, auths, conf)
except Exception as e:
print(e)
print(pub)
raise e
def print_latex(pub, i, b_year):
year = b_year and get_year(pub) or ""
pub = print_pub(pub)
if pub:
return "\\smallskip %s& $[%d]$ \\smallskip %s\\\\" % (year, i, pub)
def get_conf_name(pub):
ret = []
for v in pub['conf'].strip().split():
try:
int(v)
except:
ret.append(v)
return " ".join(ret)
def get_year(pub):
for v in pub['conf'].strip().split():
try:
return int(v)
except:
pass
return None
@click.command()
@click.argument("pubfname")
@click.option("-b", is_flag=True, help="Print bibtex, then exit")
@click.option("-a", is_flag=True, help="Include anticipated papers")
@click.option("-m", is_flag=True, help="Print MEDLINE format, then exit")
def main(pubfname, b, a, m):
"""
Input is the YML pubs file from the website
"""
bibtex = b
medline = m
with open(pubfname, "r") as f:
try:
data = yaml.load(f, Loader=yaml.FullLoader)
except Exception as e:
print(e)
return
data = list(filter(get_year, data))
data.sort(key=get_year, reverse=True)
# TODO: print future, full, then short papers.
i = 0
if bibtex:
for pub in data:
try:
print(print_bibtex(pub, i))
i += 1
except:
print >>sys.stderr, pub
return
if medline:
for pub in data:
try:
print(print_medline(pub, i))
i += 1
except:
print(pub, file=sys.stderr)
return
prev_year = None
i = 0
if a:
print("\n\n")
print("&\\section{In Progress or In Review}\\\\")
for pub in filter(lambda pub: pub.get("future"), data):
year = get_year(pub)
print(print_latex(pub, i+1, prev_year != year))
prev_year = year
i += 1
print("\n\n")
print("&\\section{Full Publications}\\\\")
for pub in filter(lambda pub: not pub.get("future") and not pub.get("short"), data):
year = get_year(pub)
print(print_latex(pub, i+1, prev_year != year))
prev_year = year
i += 1
print("\n\n")
print("&\\section{Short Papers, Technical Reports, and Demos}\\\\")
for pub in filter(lambda pub: not pub.get("future") and pub.get("short"), data):
year = get_year(pub)
print(print_latex(pub, i+1, prev_year != year))
prev_year = year
i += 1
# print "\n\n"
# for i, pub in enumerate(filter(lambda pub: not pub.get("future"), data)):
# pub = print_text_pub(pub)
# print "[%d] %s" % (i+1, pub)
if __name__ == "__main__":
main()