-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAuthors.py
More file actions
91 lines (78 loc) · 2.67 KB
/
Copy pathgetAuthors.py
File metadata and controls
91 lines (78 loc) · 2.67 KB
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
'''
dblp.xml -> authors.txt
'''
import codecs
from xml.sax import handler, make_parser
paper_tag = (
'article',
'inproceedings',
'proceedings',
'book',
'incollection',
'phdthesis',
'mastersthesis',
'www'
)
keywords = ('attention', 'transformer')
specific_year = 2017
split_str = ' ||| '
class mHandler(handler.ContentHandler):
def __init__(self,result):
self.result = result
self.flag_author = False
self.flag_title = False
self.flag_year = False
self.work_info = {}
def startElement(self, name, attrs):
if name == 'year':
self.flag_year = True
if name == 'title':
self.flag_title = True
if name == 'author':
self.flag_author = True
def endElement(self, name):
if name == 'year':
self.flag_year = False
if name == 'title':
self.flag_title = False
if name == 'author':
self.flag_author = False
if name in paper_tag:
if self.work_info.get('year', 0) >= specific_year and \
(keywords[0] in self.work_info.get('title', '') or \
keywords[1] in self.work_info.get('title', '')):
self.result.write(str(self.work_info['year'])+split_str)
self.result.write(str(self.work_info['title'])+split_str)
authors = self.work_info.get('author', tuple())
for author in authors:
if len(author)>3 and author[-4] == '0':
author = author[:-5]
self.result.write(author+split_str)
self.result.write('\r\n')
self.work_info = {}
self.flag_write = False
self.flag_title = False
self.flag_year = False
def characters(self, content):
if self.flag_year:
self.work_info['year'] = int(content)
if self.flag_title:
self.work_info['title'] = str.lower(content)
if self.flag_author:
self.work_info['author'] = self.work_info.get('author', tuple()) + (str.lower(content),)
def parserDblpXml(source,result):
handler = mHandler(result)
parser = make_parser()
parser.setContentHandler(handler)
parser.parse(source)
if __name__ == '__main__':
xml_file_name = './dblp-2022-04-01.xml'
# xml_file_name = './test.xml'
source = codecs.open(xml_file_name, 'r', 'utf-8')
result = codecs.open('./authors.txt', 'w', 'utf-8')
parserDblpXml(source,result)
result.close()
source.close()
'''
python getAuthors.py
'''