Mercurial > hg > NetworkVis
comparison ismi-python-neo4jrestclient/ismi-vis.py @ 16:ad3eefa2cb80
pimped commentaries_authors.html visualisation.
author | casties |
---|---|
date | Tue, 06 Oct 2015 19:26:46 +0200 |
parents | b33f35b57b93 |
children | 09c0a9ceb778 |
comparison
equal
deleted
inserted
replaced
15:7c4475cd747a | 16:ad3eefa2cb80 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 from json import dumps | 2 from json import dumps |
3 | 3 |
4 from flask import Flask, Response, request | 4 from flask import Flask, Response, request, send_from_directory |
5 | 5 |
6 from neo4jrestclient.client import GraphDatabase, Node, Relationship | 6 from neo4jrestclient.client import GraphDatabase, Node, Relationship |
7 | 7 |
8 app = Flask(__name__, static_url_path='/static/') | 8 app = Flask(__name__, static_url_path='/static/') |
9 app.debug = True | 9 app.debug = True |
18 def get_commentaries(): | 18 def get_commentaries(): |
19 return app.send_static_file('commentaries.html') | 19 return app.send_static_file('commentaries.html') |
20 | 20 |
21 @app.route("/commentaries_authors.html") | 21 @app.route("/commentaries_authors.html") |
22 def get_commentaries_authors(): | 22 def get_commentaries_authors(): |
23 return app.send_static_file('commentaries_authors.html') | 23 return app.send_static_file('commentaries_authors2.html') |
24 | |
25 @app.route('/static/<filename>') | |
26 def get_file(filename): | |
27 return send_from_directory('static', filename) | |
24 | 28 |
25 @app.route("/graph") | 29 @app.route("/graph") |
26 def get_graph(): | 30 def get_graph_commentaries(): |
31 query = ("match (t1:TEXT)-[r:is_commentary_on]->(t2:TEXT)" | |
32 " return t1,t2" | |
33 " limit {limit}") | |
34 results = gdb.query(query, returns=(Node,Node), | |
35 params={"limit": int(request.args.get("limit", 100))}) | |
36 | |
37 n4j_nodes = {} | |
38 node_idx = {} | |
39 nodes = [] | |
40 rels = [] | |
41 i = 0 | |
42 for text1, text2 in results: | |
43 # source text | |
44 id1 = text1['ismi_id'] | |
45 if id1 not in n4j_nodes: | |
46 n4j_nodes[id1] = text1 | |
47 nodes.append({"title": "%s [%s]"%(text1['label'],id1), "label": "TEXT", "ismi_id": id1}) | |
48 node_idx[id1] = i | |
49 source = i | |
50 i += 1 | |
51 | |
52 else: | |
53 source = node_idx[id1] | |
54 | |
55 # target text | |
56 id2 = text2['ismi_id'] | |
57 if id2 not in n4j_nodes: | |
58 n4j_nodes[id2] = text2 | |
59 nodes.append({"title": "%s [%s]"%(text2['label'],id2), "label": "TEXT", "ismi_id": id2}) | |
60 node_idx[id2] = i | |
61 target = i | |
62 i += 1 | |
63 | |
64 else: | |
65 target = node_idx[id2] | |
66 | |
67 # relation is_commentary_on | |
68 rels.append({"source": source, "target": target}) | |
69 | |
70 return Response(dumps({"nodes": nodes, "links": rels}), | |
71 mimetype="application/json") | |
72 | |
73 | |
74 @app.route("/graph_commentaries_authors") | |
75 def get_graph_commentaries_authors(): | |
27 query = ("match (a1:PERSON)<-[:was_created_by]-(t1:TEXT)-[r:is_commentary_on]->(t2:TEXT)-[:was_created_by]->(a2:PERSON)" | 76 query = ("match (a1:PERSON)<-[:was_created_by]-(t1:TEXT)-[r:is_commentary_on]->(t2:TEXT)-[:was_created_by]->(a2:PERSON)" |
28 " return a1,t1,t2,a2" | 77 " return a1,t1,t2,a2" |
29 " limit 100") | 78 " limit 100") |
30 results = gdb.query(query, returns=(Node,Node,Node,Node)) | 79 results = gdb.query(query, returns=(Node,Node,Node,Node)) |
31 n4j_nodes = {} | 80 n4j_nodes = {} |