annotate ismi-python-neo4jrestclient/ismi-vis.py @ 29:2564732249b3

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