changeset 29:2564732249b3

search for authors names uses normalization now.
author casties
date Thu, 10 Dec 2015 16:00:49 -0500
parents 5384b71df52a
children cccbcc845d54
files ismi-python-neo4jrestclient/ismi-vis.py ismi-python-neo4jrestclient/static/commentaries_authors2.html
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py	Thu Dec 10 07:26:40 2015 -0500
+++ b/ismi-python-neo4jrestclient/ismi-vis.py	Thu Dec 10 16:00:49 2015 -0500
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
-from json import dumps
+from json import dumps, loads
+import urllib.request
 
 from flask import Flask, Response, request, send_from_directory
 
@@ -8,11 +9,18 @@
 app = Flask(__name__, static_url_path='/static/')
 app.debug = True
 gdb = GraphDatabase("http://localhost:7474", username="neo4j", password="neo5j")
+ismi_db_baseurl = "http://localhost:18080/ismi-richfaces/"
+
+def loadJSON(url):
+    #print("JSON loading %s"%url)
+    wsh=urllib.request.urlopen(url)
+    txt = wsh.read()
+    return loads(txt.decode("utf-8"))
 
 
 @app.route("/")
 def get_index():
-    return app.send_static_file('commentaries.html')
+    return app.send_static_file('commentaries_authors2.html')
 
 @app.route("/commentaries.html")
 def get_commentaries():
@@ -148,15 +156,20 @@
 def get_search():
     try:
         q = request.args["q"]
+        norm_js = loadJSON(ismi_db_baseurl + "jsonInterface?method=normalize_string&type=arabic_translit&text=%s"%q)
+        nq = norm_js.get("normalized_text")            
     except KeyError:
         return []
     else:
-        query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})"
+        #query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})"
+        #         " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))")
+        query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON)"
+                 " WHERE p._n_label =~ {name}"
                  " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))")
         results = gdb.query(
             query,
             returns=(Node,Node,bool,bool),
-            params={"id": int(q)}
+            params={"name": ".*%s.*"%nq.lower()}
         )
         # {"name": "(?i).*" + q + ".*"}
         print("search for %s returned %s results"%(repr(q),len(results)))
--- a/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Thu Dec 10 07:26:40 2015 -0500
+++ b/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Thu Dec 10 16:00:49 2015 -0500
@@ -14,9 +14,9 @@
                     <li>
                         <form role="search" class="navbar-form" id="search">
                             <div class="form-group">
-                                <input type="text" value="7437" placeholder="Search for person-id" class="form-control" name="search">
+                                <input type="text" value="jaghmini" placeholder="Search for person name" class="form-control" name="search">
                             </div>
-                            <button class="btn btn-default" type="submit">Search for author id</button>
+                            <button class="btn btn-default" type="submit">Search for author name</button>
                         </form>
                     </li>
                 </ul>