-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
48 lines (39 loc) · 1.24 KB
/
parser.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
"""
A Parser processes a single input into a Paper instances (possibly incomplete)
In general, a parser parses a references' page and the references as displayed
on its page (in whichever format the parser expects).
The references are written to a dictionary (see Paper documentation).
A parser should always accept both file and url input; file input is default.
Partial parsers may accept text input (usually an iterable, such as a file object).
Order: text > file > uri
A parser may use sub-parser(s) to modularize certain steps that repeat, or to
process different outputs from the same source (e.g., a DOI resolver could be
implemented this way).
Workflow for parsers:
create instance -> read -> process -> read Parser.paper
"""
from paper import Paper
class Parser():
debugmode=False
uri=None
myFile=None
text=None
paper=None
def __init__(self, myFile=None, uri=None, text=None):
if not file and not uri and not text:
raise Exception("Must provide file, text or uri")
elif text:
self.text=text
elif myFile:
self.myFile=myFile
elif uri:
self.uri=uri
def read(self):
if myFile:
pass
elif uri:
pass
else:
raise Exception("Invalid state!")
def process(self):
pass