-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper.py
105 lines (88 loc) · 3.96 KB
/
paper.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
#!/usr/bin/env python3.8
import json
from typing import List
class Paper():
def __init__(self, id: str, title: str, authors: str, url: str, or_id: str, oral: str, short: str,
abstract: str, schedule: str = "", slides: str = "", yt_teaser: str = "",
yt_full: str = "", ignore_schedule: bool = False, award: str = "", pmlr_url=""):
self.id: int = int(id)
self.title: str = title
self.authors: List[str] = authors.split(', ')
self.url: str = url
self.or_id: str = or_id
self.oral: bool = oral == "True"
self.short: bool = short == "True"
self.poster: bool = (not self.short) and (not self.oral)
self.abstract: str = abstract
self.slides: str = slides
self.yt_teaser: str = yt_teaser
self.yt_full: str = yt_full
self.award: str = award
self.pmlr_url: str = pmlr_url
assert not (self.short and self.pmlr_url)
self.pdf_url: str
if self.short:
self.pdf_url = f'https://openreview.net/pdf?id={self.or_id}'
else:
pmlr_id: str = self.pmlr_url.split('/')[-1].replace(".html", "")
self.pdf_url = f"http://proceedings.mlr.press/v121/{pmlr_id}/{pmlr_id}.pdf"
self.schedule: List[str]
if not schedule:
self.schedule = []
else:
self.schedule = schedule.split('\n')
assert not (self.oral and self.short)
if self.short:
assert not self.oral
if not ignore_schedule:
try:
if not self.oral:
assert len(self.schedule) == 1
else:
assert len(self.schedule) == 2
except AssertionError:
print(self.id, self.schedule)
sanitized_abstract: str = self.abstract.replace("'", "\\'")
sanitized_abstract = sanitized_abstract.replace('"', '\\"')
sanitized_abstract = sanitized_abstract.replace('\n', '')
sanitized_abstract = sanitized_abstract.replace('`', '')
self.sanitized_abstract = sanitized_abstract
self.conf_sign: str = "O" if self.oral else ("S" if self.short else "P")
self.conf_id: str = f"{self.conf_sign}{self.id:03d}"
# self.__class__.__name__: str = "Paper"
def __str__(self) -> str:
sanitized_abstract: str = self.abstract.replace("'", "\\'")
sanitized_abstract = sanitized_abstract.replace('"', '\\"')
sanitized_abstract = sanitized_abstract.replace('\n', '')
sanitized_abstract = sanitized_abstract.replace('`', '')
sanitized_abstract = repr(sanitized_abstract)
# sanitized_abstract: str = repr(self.abstract)
return f'''{{{{ paper(\'{self.title}\',
\'{f'{", ".join(self.authors)}'}\',
openreview=\'{f'https://openreview.net/forum?id={self.or_id}'}\',
pdf=\'{self.pdf_url}\',
id='{self.conf_id}',
paper='{self.url}',
proceedings='{self.pmlr_url}',
teaser=\'{f'https://youtu.be/{self.yt_teaser}' if self.yt_teaser else ""}\',
video=\'{f'https://youtu.be/{self.yt_full}' if self.yt_full else ""}\',
abstract={sanitized_abstract})
}}}}'''
class PaperEncoder(json.JSONEncoder):
def default(self, paper):
if isinstance(paper, Paper):
return {"id": str(paper.id),
"title": paper.title,
"authors": ", ".join(paper.authors),
"url": paper.url,
"or_id": paper.or_id,
"oral": str(paper.oral),
"short": str(paper.short),
"abstract": paper.abstract,
"schedule": "\n".join(paper.schedule),
"slides": paper.slides,
"yt_teaser": paper.yt_teaser,
"yt_full": paper.yt_full,
"award": paper.award,
"pmlr_url": paper.pmlr_url}
return json.JSONEncoder.default(self, paper)