-
Notifications
You must be signed in to change notification settings - Fork 6
/
UI.py
225 lines (208 loc) · 6.73 KB
/
UI.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# encoding=utf-8
from pathlib import Path
import os
from bottle import route, view, run, request, post, template
import network_construction.network as nc
import network_construction.database as db
from network_analysis import network
from data_platform.config import ConfigManager
from data_platform.datasource.networkx import NetworkXDS
# 下面三行是我为了解决template not found ERROR 自己添加的。
# 2020.1.24
from bottle import TEMPLATE_PATH
import os
TEMPLATE_PATH.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "views")))
@route('/load')
def load():
return template('loadgraph')
@route('/construction')
@view('construction')
def do_construction():
graphtype = request.query.graphtype
print(graphtype)
data = {'graphtype': graphtype, }
print(data)
return data
@post('/text')
@view('create')
def do_text():
database = request.forms.get('database')
print(database)
db.create_database(database)
db.flush()
source = request.forms.get('source')
document = request.forms.get('document')
node = request.forms.get('node')
relation = request.forms.get('relation')
nc.create_network_text(source, document, node, relation, database)
db.flush()
current_location = Path(os.getcwd())
data_location = current_location / 'data'
graph_location = data_location / 'graph'
config = ConfigManager({
"init": {
"location": graph_location
},
"file_format": "graphml"
})
print(graph_location)
nxds = NetworkXDS(config) # 读取网络用模块
print(nxds.read_graph())
network0 = nxds.read_graph(database)[database]
scale = network0.number_of_nodes()
size = network0.number_of_edges()
print(scale)
print(size)
data = {'database': database + '.graphml',
'source': source,
'document': document,
'node': node,
'relation': relation,
'node_number': scale,
'edge_number': size,
'nettype': node + ' ' + 'word network',
'weighttype': 'count'}
print(data)
return data
@post('/author')
@view('create')
def do_author():
database = request.forms.get('database')
print(database)
db.flush()
db.create_database(database)
source = request.forms.get('source')
document = request.forms.get('document')
relation = request.forms.get('relation')
nc.create_network_author(source, document, relation, database)
db.flush()
current_location = Path(os.getcwd())
data_location = current_location / 'data'
graph_location = data_location / 'graph'
config = ConfigManager({
"init": {
"location": graph_location
},
"file_format": "graphml"
})
print(graph_location)
nxds = NetworkXDS(config) # 读取网络用模块
print(nxds.read_graph())
network0 = nxds.read_graph(database)[database]
scale = network0.number_of_nodes()
size = network0.number_of_edges()
print(scale)
print(size)
data = {'database': database + '.graphml',
'source': source,
'document': document,
'node': "undefined",
'relation': relation,
'node_number': scale,
'edge_number': size,
'nettype': 'author citation network',
'weighttype': 'cite_count'}
#nettype可以为co work network,此时weighttype改为co_count,这个要在后续版本中再进行动态的修改,暂时只使用citation即可。
print(data)
return data
@post('/paper')
@view('create')
def do_paper():
database = request.forms.get('database')
print(database)
db.flush()
db.create_database(database)
source = request.forms.get('source')
document = request.forms.get('document')
relation = request.forms.get('relation')
nc.create_network_paper(source, document, relation, database)
db.flush()
current_location = Path(os.getcwd())
data_location = current_location / 'data'
graph_location = data_location / 'graph'
config = ConfigManager({
"init": {
"location": graph_location
},
"file_format": "graphml"
})
print(graph_location)
nxds = NetworkXDS(config) # 读取网络用模块
print(nxds.read_graph())
network0 = nxds.read_graph(database)[database]
scale = network0.number_of_nodes()
size = network0.number_of_edges()
print(scale)
print(size)
data = {'database': database + '.graphml',
'source': source,
'document': document,
'node': "undefined",
'relation': relation,
'node_number': scale,
'edge_number': size,
'nettype': 'paper citation network',
'weighttype': 'cite_count'}
print(data)
return data
@post('/other')
@view('create')
def do_other():
database = request.forms.get('database')
print(database)
db.flush()
db.create_database(database)
source = request.forms.get('source')
document = request.forms.get('document')
relation = request.forms.get('relation')
nc.create_other(source, document, relation, database)
db.flush()
current_location = Path(os.getcwd())
data_location = current_location / 'data'
graph_location = data_location / 'graph'
config = ConfigManager({
"init": {
"location": graph_location
},
"file_format": "graphml"
})
print(graph_location)
nxds = NetworkXDS(config) # 读取网络用模块
print(nxds.read_graph())
network0 = nxds.read_graph(database)[database]
scale = network0.number_of_nodes()
size = network0.number_of_edges()
print(scale)
print(size)
data = {'database': database + '.graphml',
'source': source,
'document': document,
'node': "undefined",
'relation': relation,
'node_number': scale,
'edge_number': size,
'nettype': 'paper author or paper word network',
'weighttype': 'relation_count'}
print(data)
return data
@route('/analysis', method='get')
@view('analysis')
def do_analysis():
gname = request.query.graphname
gtype = request.query.graphtype
net_type = request.query.nettype
weight_type = request.query.weighttype
g = network.Net(gname, net_type, weight_type)
if gtype == 'component':
g = g.extract_max_component()
elif gtype == 'ego':
core = request.query.ego_core
radius = int(request.query.ego_radius)
g = g.extract_ego_network(core, radius)
elif gtype == 'community':
g = g.extract_louvain_communities()
data = {'graphname': gname,
'graphtype': gtype,
'g': g}
return data
run(host='localhost', port=8080, reloader=True, debug=True)