summaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-11-06 01:30:46 +0100
committerJules Laplace <julescarbon@gmail.com>2018-11-06 01:30:46 +0100
commitacc16d8f35a3b10021ff75db06503851feb8efde (patch)
treef4c347ed9fa1731b66bf3f1ee42b48ab7e702839 /util.py
parent4e7350603f294fa6eea31146f41711b79d9e1c64 (diff)
reports
Diffstat (limited to 'util.py')
-rw-r--r--util.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/util.py b/util.py
index d5796c8e..400c7ee3 100644
--- a/util.py
+++ b/util.py
@@ -59,8 +59,53 @@ def write_report(fn, title=None, keys=None, rows=[]):
for row in rows:
f.write("<tr>")
for cell in row:
- f.write("<td>{}</td>".format(cell))
+ if isinstance(cell, list) or isinstance(cell, tuple):
+ f.write("<td>{}</td>".format('<br/>'.join(str(x) for x in cell)))
+ else:
+ f.write("<td>{}</td>".format(cell))
f.write("</tr>")
f.write("</table>")
f.write("</body>")
f.write("</html>")
+
+def paper_path(key='papers', paper_id=''):
+ return '{}/{}/{}/{}/paper.json'.format('./datasets/s2', key, paper_id[0:2], paper_id)
+
+class DbPaper(object):
+ def __init__(self, paper_id):
+ self.paper_id = paper_id
+ self.data = read_json(paper_path('db_papers', paper_id))
+ @property
+ def title(self):
+ return self.data['title']
+ @property
+ def journal(self):
+ return self.data['journalName']
+ @property
+ def authors(self):
+ return [ (author['ids'][0] if len(author['ids']) else '', author['name']) for author in self.data['authors'] ]
+
+class RawPaper(object):
+ def __init__(self, paper_id):
+ self.paper_id = paper_id
+ self.data = read_json(paper_path('raw_papers', paper_id))['paper']
+ @property
+ def title(self):
+ return self.data['title']['text']
+ @property
+ def journal(self):
+ return self.data['journal']['name']
+ @property
+ def authors(self):
+ return [ (author[0]['ids'][0], author[0]['name']) for author in self.data['authors'] ]
+
+def load_paper(paper_id):
+ print('_______________')
+ if os.path.exists(paper_path('db_papers', paper_id)):
+ print('db paper')
+ return DbPaper(paper_id)
+ if os.path.exists(paper_path('raw_papers', paper_id)):
+ print('raw paper')
+ return RawPaper(paper_id)
+ print('no paper')
+ return None