-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDrawReferenceNetwork.py
180 lines (169 loc) · 6.2 KB
/
DrawReferenceNetwork.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import networkx as nx
import json
net_dir = 'all_conf.txt'
all_info = {}
id2num_file = 'id2num.txt'
num2id = {}
id2num = {}
with open(id2num_file, 'r') as f:
line = f.readline()
while line:
para = line.strip().split(' ')
num2id[int(para[1])] = para[0]
id2num[para[0]] = int(para[1])
line = f.readline()
'''
i = 0
G = nx.DiGraph()
scholar_dict = {}
score = {}
# 计算文章重要性
print("Article")
with open(net_dir, 'r') as reader:
line = reader.readline()
while line:
line_dic = eval(line)
id = line_dic['id']
references = []
if 'references' in line_dic.keys():
references = line_dic['references']
if references != []:
for reference in references:
G.add_edge(id,reference)
line = reader.readline()
score = nx.pagerank(G)
out = open('./PageRank/PageRank_score.json', 'w', encoding='utf-8')
json.dump(score, out)
out.close()
'''
f = open('./PageRank/PageRank_score.json', 'r', encoding='utf-8')
score = json.load(f)
'''
print("Author")
with open(net_dir) as reader:
line = reader.readline()
while line:
line_dic = eval(line)
id = line_dic['id']
authors = line_dic['authors']
nid = id2num[id]
if nid <= 12308:
tag = 'Distributed & Parallel Computing'
elif nid <= 29508:
tag = 'Machine Learning'
elif nid <= 47962:
tag = 'Data Mining'
elif nid <= 53586:
tag = 'Computer Education'
elif nid <= 65480:
tag = 'Natural Language Processing'
else:
tag = 'Operating Systems / Simulations'
line = reader.readline()
for author in authors:
if id not in score.keys():
continue
if author in scholar_dict.keys():
scholar_dict[author][0] += score[id]
if tag in scholar_dict[author][1].keys():
scholar_dict[author][1][tag] += 1
else:
scholar_dict[author][1][tag] = 1
else:
scholar_dict[author] = [score[id], {tag: 1}]
line = reader.readline()
out = open('./PageRank/Author_score.json', 'w', encoding='utf-8')
json.dump(scholar_dict, out)
out.close()
'''
# Draw a co-author network
nodes = {}
link = []
cat2num = {'Natural Language Processing': 0, 'Distributed & Parallel Computing': 1,
'Machine Learning': 2, 'Data Mining': 3, 'Computer Education': 4,
'Operating Systems / Simulations': 5}
print("Draw")
import numpy as np
def symbolsize(id):
if id in score.keys():
return int(np.log(score[id]*(10**6))*10)-10
def getcat(id):
global id2num
nid = id2num[id]
if nid <= 12308:
tag = 'Distributed & Parallel Computing'
elif nid <= 29508:
tag = 'Machine Learning'
elif nid <= 47962:
tag = 'Data Mining'
elif nid <= 53586:
tag = 'Computer Education'
elif nid <= 65480:
tag = 'Natural Language Processing'
else:
tag = 'Operating Systems / Simulations'
global cat2num
return cat2num[tag]
'''
# 按值切割全网络
with open(net_dir) as reader:
line = reader.readline()
while line:
line_dic = eval(line)
id = line_dic['id']
if id not in nodes.keys() and id in score.keys() and score[id]*(10**6) > 6:
print(score[id])
nodes[id] = {'name': id, 'value': score[id]*(10**6), "symbolSize": symbolsize(id),
'category': getcat(id)}
references = []
if 'references' in line_dic.keys():
references = line_dic['references']
if references != []:
for reference in references:
if reference not in nodes.keys() and reference in score.keys() \
and score[reference]*(10**6) > 6 and reference in id2num.keys():
nodes[reference] = {'name': reference, 'value': score[reference]*(10**6),
"symbolSize": symbolsize(reference),
'category': getcat(reference)}
if id in nodes.keys() and reference in nodes.keys():
link.append({'source': id, 'target': reference})
line = reader.readline()
'''
# 只绘制NLP领域
with open(net_dir) as reader:
line = reader.readline()
while line:
line_dic = eval(line)
id = line_dic['id']
if id not in nodes.keys() and id in score.keys() and score[id]*(10**6) > 5 and getcat(id)==0:
#print(score[id])
nodes[id] = {'name': id, 'value': score[id]*(10**6), "symbolSize": symbolsize(id),
'category': getcat(id)}
references = []
if 'references' in line_dic.keys():
references = line_dic['references']
if references != []:
for reference in references:
if reference not in nodes.keys() and reference in score.keys() \
and score[reference] * (10 ** 6) > 5 and reference in id2num.keys() \
and getcat(reference)==0:
nodes[reference] = {'name': reference, 'value': score[reference]*(10**6),
"symbolSize": symbolsize(reference),
'category': getcat(reference)}
if id in nodes.keys() and reference in nodes.keys():
link.append({'source': id, 'target': reference})
line = reader.readline()
nodes = [x[1] for x in nodes.items()]
categories = ['Natural Language Processing', 'Distributed & Parallel Computing',
'Machine Learning', 'Data Mining', 'Computer Education',
'Operating Systems / Simulations']
def formatter(params):
return params.name + ': ' + params.value+': '+params.symbolSize
print("Gnerate the Website")
from pyecharts import Graph
graph = Graph("Academic Reference Network", width=1200, height=800)
graph.add("", nodes, link, categories, label_pos="right",
graph_repulsion=50, is_legend_show=False,
line_curve=0.2, label_text_color=None,
tooltip_formatter=formatter)
graph.render("AcademicReferenceNetwork.html")