-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticlenet2gexf.py
executable file
·52 lines (35 loc) · 1.21 KB
/
articlenet2gexf.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
#!/usr/bin/env python
# encoding: utf-8
__author__ = "Telmo Menezes ([email protected])"
__date__ = "Mar 2011"
import sys
import sqlite3
def articlenet2gexf(dbpath, outpath):
f = open(outpath, 'w')
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<gexf xmlns="http://www.gexf.net/1.1draft" version="1.1">\n')
f.write('<graph mode="static" defaultedgetype="directed">\n')
f.write('<nodes>\n')
conn = sqlite3.connect(dbpath)
cur = conn.cursor()
cur.execute("SELECT id FROM articles")
for row in cur:
articleid = row[0]
#f.write('<node id="%s" label="%s" />\n' % (articleid, articleid))
f.write('<node id="%s" />\n' % articleid)
f.write('</nodes>\n')
f.write('<edges>\n')
edge_count = 0
cur.execute("SELECT orig_id, targ_id FROM citations WHERE targ_id>=0")
for row in cur:
f.write('<edge id="%d" source="%d" target="%d" type="directed" />\n' % (edge_count, row[0], row[1]))
edge_count += 1
f.write('</edges>\n')
f.write('</graph>\n')
f.write('</gexf>\n')
cur.close()
conn.close()
f.close()
print('Done.')
if __name__ == '__main__':
articlenet2gexf(sys.argv[1], sys.argv[2])