annotate ismi-python-neo4jrestclient/ismi-vis.py @ 39:88c5232f9d48 default tip

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