-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataparser.py
51 lines (40 loc) · 1.51 KB
/
dataparser.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
class DataParser:
@staticmethod
def readandparsefile(FilePath):
Papers = []
data = open(FilePath, 'r')
records_list = data.read().split('\n\n')
for i in range(len(records_list)):
records_list[i] = records_list[i].replace('\n', '')
data.close()
records_list = list(filter(None, records_list))
temp_dict = {}
for paper in records_list:
if '#index' in paper:
temp_dict['index'] = int(paper.split('#index')[-1])
paper = paper.split('#index')[0]
if '#c' in paper:
temp_dict['venue'] = paper.split('#c')[-1]
if temp_dict['venue'] == ' ':
temp_dict['venue'] = ''
paper = paper.split('#c')[0]
else:
temp_dict['venue'] = ''
if '#t' in paper:
temp_dict['date'] = int(paper.split('#t')[-1])
paper = paper.split('#t')[0]
else:
temp_dict['date'] = -1
if '#@' in paper:
temp_dict['author'] = paper.split('#@')[-1].split(',')
paper = paper.split('#@')[0]
else:
temp_dict['author'] = ['']
if '#*' in paper:
temp_dict['name'] = paper.split('#*')[-1]
paper = paper.split('#*')[0]
else:
temp_dict['name'] = ['']
Papers.append(temp_dict)
temp_dict = {}
return Papers