annotate ismi-python-neo4jrestclient/ismi-vis.py @ 17:09c0a9ceb778

more pimping of commentaries_authors.
author casties
date Wed, 07 Oct 2015 15:41:00 +0200
parents ad3eefa2cb80
children d8bbf6d5920b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
1 #!/usr/bin/env python
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
2 from json import dumps
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
3
16
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
4 from flask import Flask, Response, request, send_from_directory
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
5
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
6 from neo4jrestclient.client import GraphDatabase, Node, Relationship
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
7
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
8 app = Flask(__name__, static_url_path='/static/')
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
9 app.debug = True
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
10 gdb = GraphDatabase("http://localhost:7474", username="neo4j", password="neo5j")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
11
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
12
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
13 @app.route("/")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
14 def get_index():
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
15 return app.send_static_file('commentaries.html')
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
16
9
0f4846255b20 updated for ismi-dev.
casties
parents: 7
diff changeset
17 @app.route("/commentaries.html")
0f4846255b20 updated for ismi-dev.
casties
parents: 7
diff changeset
18 def get_commentaries():
0f4846255b20 updated for ismi-dev.
casties
parents: 7
diff changeset
19 return app.send_static_file('commentaries.html')
0f4846255b20 updated for ismi-dev.
casties
parents: 7
diff changeset
20
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
21 @app.route("/commentaries_authors.html")
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
22 def get_commentaries_authors():
16
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
23 return app.send_static_file('commentaries_authors2.html')
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
24
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
25 @app.route('/static/<filename>')
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
26 def get_file(filename):
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
27 return send_from_directory('static', filename)
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
28
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
29 @app.route("/graph")
16
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
30 def get_graph_commentaries():
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
31 query = ("match (t1:TEXT)-[r:is_commentary_on]->(t2:TEXT)"
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
32 " return t1,t2"
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
33 " limit {limit}")
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
34 results = gdb.query(query, returns=(Node,Node),
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
35 params={"limit": int(request.args.get("limit", 100))})
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
36
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
37 n4j_nodes = {}
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
38 node_idx = {}
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
39 nodes = []
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
40 rels = []
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
41 i = 0
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
42 for text1, text2 in results:
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
43 # source text
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
44 id1 = text1['ismi_id']
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
45 if id1 not in n4j_nodes:
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
46 n4j_nodes[id1] = text1
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
47 nodes.append({"title": "%s [%s]"%(text1['label'],id1), "label": "TEXT", "ismi_id": id1})
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
48 node_idx[id1] = i
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
49 source = i
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
50 i += 1
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
51
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
52 else:
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
53 source = node_idx[id1]
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
54
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
55 # target text
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
56 id2 = text2['ismi_id']
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
57 if id2 not in n4j_nodes:
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
58 n4j_nodes[id2] = text2
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
59 nodes.append({"title": "%s [%s]"%(text2['label'],id2), "label": "TEXT", "ismi_id": id2})
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
60 node_idx[id2] = i
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
61 target = i
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
62 i += 1
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
63
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
64 else:
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
65 target = node_idx[id2]
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
66
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
67 # relation is_commentary_on
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
68 rels.append({"source": source, "target": target})
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
69
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
70 return Response(dumps({"nodes": nodes, "links": rels}),
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
71 mimetype="application/json")
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
72
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
73
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
74 @app.route("/graph_commentaries_authors")
ad3eefa2cb80 pimped commentaries_authors.html visualisation.
casties
parents: 14
diff changeset
75 def get_graph_commentaries_authors():
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
76 query = ("match (a1:PERSON)<-[:was_created_by]-(t1:TEXT)-[r:is_commentary_on]->(t2:TEXT)-[:was_created_by]->(a2:PERSON)"
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
77 " return a1,t1,t2,a2"
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
78 " limit 100")
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
79 results = gdb.query(query, returns=(Node,Node,Node,Node))
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
80 n4j_nodes = {}
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
81 node_idx = {}
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
82 nodes = []
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
83 rels = []
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
84 i = 0
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
85 for author1, text1, text2, author2 in results:
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
86 # source text
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
87 id1 = text1['ismi_id']
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
88 if id1 not in n4j_nodes:
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
89 n4j_nodes[id1] = text1
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
90 nodes.append({"title": "%s [%s]"%(text1['label'],id1), "label": "TEXT"})
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
91 node_idx[id1] = i
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
92 source = i
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
93 i += 1
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
94
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
95 else:
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
96 source = node_idx[id1]
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
97
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
98 # target text
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
99 id2 = text2['ismi_id']
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
100 if id2 not in n4j_nodes:
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
101 n4j_nodes[id2] = text2
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
102 nodes.append({"title": "%s [%s]"%(text2['label'],id2), "label": "TEXT"})
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
103 node_idx[id2] = i
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
104 target = i
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
105 i += 1
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
106
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
107 else:
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
108 target = node_idx[id2]
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
109
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
110 # relation is_commentary_on
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
111 rels.append({"source": source, "target": target})
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
112
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
113 # source author
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
114 id3 = author1['ismi_id']
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
115 if id3 not in n4j_nodes:
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
116 n4j_nodes[id3] = author1
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
117 nodes.append({"title": "%s [%s]"%(author1['label'],id3), "label": "PERSON"})
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
118 node_idx[id3] = i
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
119 s_author = i
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
120 i += 1
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
121
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
122 else:
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
123 s_author = node_idx[id3]
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
124
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
125 # relation was_created_by
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
126 rels.append({"source": source, "target": s_author})
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
127
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
128 # target author
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
129 id4 = author1['ismi_id']
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
130 if id4 not in n4j_nodes:
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
131 n4j_nodes[id4] = author2
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
132 nodes.append({"title": "%s [%s]"%(author2['label'],id4), "label": "PERSON"})
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
133 node_idx[id4] = i
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
134 t_author = i
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
135 i += 1
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
136
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
137 else:
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
138 t_author = node_idx[id4]
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
139
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
140 # relation was_created_by
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
141 rels.append({"source": source, "target": t_author})
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
142
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
143 return Response(dumps({"nodes": nodes, "links": rels}),
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
144 mimetype="application/json")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
145
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
146
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
147 @app.route("/search")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
148 def get_search():
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
149 try:
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
150 q = request.args["q"]
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
151 except KeyError:
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
152 return []
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
153 else:
17
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
154 query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})"
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
155 " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))")
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
156 results = gdb.query(
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
157 query,
17
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
158 returns=(Node,Node,bool,bool),
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
159 params={"id": int(q)}
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
160 )
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
161 # {"name": "(?i).*" + q + ".*"}
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
162 print("search for %s returned %s results"%(repr(q),len(results)))
17
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
163 data = [{"text": t.properties,
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
164 "author": a.properties,
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
165 "is_commentary": is_com,
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
166 "has_commentaries": has_com}
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
167 for [t,a,is_com,has_com] in results]
09c0a9ceb778 more pimping of commentaries_authors.
casties
parents: 16
diff changeset
168 return Response(dumps(data),
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
169 mimetype="application/json")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
170
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
171
7
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
172 @app.route("/text/<text_id>")
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
173 def get_text(text_id):
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
174 query = ("MATCH (text:TEXT {ismi_id:{text_id}}) "
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
175 " RETURN text"
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
176 " LIMIT 1")
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
177 results = gdb.query(query, returns=Node, params={"text_id": int(text_id)})
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
178 node = results[0][0]
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
179 print("node:%s"%repr(node))
45dad9e38c82 first functional version of commentary visualisation.
casties
parents: 6
diff changeset
180 return Response(dumps({"title": node['label'], "attrs": node.properties}),
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
181 mimetype="application/json")
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
182
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
183 @app.route("/textandcommentaries/<text_id>")
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
184 def get_textandcommentaries(text_id):
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
185 query = ("match (t:TEXT {ismi_id:{text_id}})"
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
186 " optional match (t)-[:was_created_by]->(a:PERSON)"
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
187 " optional match (s:TEXT)<-[:is_commentary_on]-(t)"
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
188 " optional match (s)-[:was_created_by]->(sa:PERSON)"
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
189 " optional match (t)<-[:is_commentary_on]-(c:TEXT)"
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
190 " optional match (c)-[:was_created_by]->(ca:PERSON)"
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
191 " return t,a.label,s.label,s.ismi_id,sa.label,c.label,c.ismi_id,ca.label")
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
192 print("query:%s"%query)
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
193 results = gdb.query(query, returns=(Node,str,str,str,str,str,str,str),
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
194 params={"text_id": int(text_id)})
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
195
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
196 print("result:%s"%results)
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
197 text = None
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
198 author = None
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
199 scs = {}
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
200 cs = {}
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
201 for [t,a_label,s_label,s_id,sa_label,c_label,c_id,ca_label] in results:
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
202 text = t
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
203 author = a_label
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
204 if s_id is not None and s_id != "None":
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
205 scs[int(s_id)] = {"title": s_label, "author":sa_label}
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
206
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
207 if c_id is not None and c_id != "None":
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
208 cs[int(c_id)] = {"title": c_label, "author":ca_label}
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
209
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
210 print("text:%s scs:%s cs:%s"%(text, scs, cs))
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
211 return Response(dumps({"title": text['label'], "attrs": text.properties,
14
b33f35b57b93 added authors to details view.
casties
parents: 13
diff changeset
212 "author": author,
13
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
213 "commenting": scs, "commentaries": cs}),
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
214 mimetype="application/json")
394bd5cfc508 new commentaries_authors.html visualisation.
casties
parents: 9
diff changeset
215
6
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
216
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
217 if __name__ == '__main__':
aeef1fedd899 first version of ismi-python-neo4jrestclient. doesn't work yet.
casties
parents:
diff changeset
218 app.run(port=8080)