changeset 33:758a5313baf4

Changes merged.
author arussell
date Sat, 19 Dec 2015 09:17:45 -0500
parents acc60a20582c (current diff) a6b2a09ea413 (diff)
children 4bbb832c53ac
files
diffstat 3 files changed, 51 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py	Sat Dec 19 09:15:43 2015 -0500
+++ b/ismi-python-neo4jrestclient/ismi-vis.py	Sat Dec 19 09:17:45 2015 -0500
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
-from json import dumps
+from json import dumps, loads
+import urllib.request, urllib.parse
 
 from flask import Flask, Response, request, send_from_directory
 
@@ -8,6 +9,13 @@
 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("/")
@@ -148,15 +156,21 @@
 def get_search():
     try:
         q = request.args["q"]
+        qs = urllib.parse.quote(q)
+        norm_js = loadJSON(ismi_db_baseurl + "jsonInterface?method=normalize_string&type=arabic_translit&text=%s"%qs)
+        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.html	Sat Dec 19 09:15:43 2015 -0500
+++ b/ismi-python-neo4jrestclient/static/commentaries.html	Sat Dec 19 09:17:45 2015 -0500
@@ -14,7 +14,7 @@
                     <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>
                         </form>
@@ -114,7 +114,7 @@
        $(this).next().slideToggle();
     });
     // provide search and graph
-    backendApiPrefix = "/netvis-ismi";
+    backendApiPrefix = "";
     searchApi = {};
     $(function () {
         function showText(text_id) {
@@ -125,9 +125,10 @@
                         var $list = $("#info").empty();
                         $list.append($("<li>Author: " + data.author.label + " [" + data.author.ismi_id + "]</li>")
                                 .click(function() { 
-                                    search(data.author.ismi_id, true); 
+                                    search(data.author.label, true); 
                                     }));
                         for (var key in data.attrs) {
+                            if (key[0] === "_") continue;
                             var val = data.attrs[key];
                             if (key === "link") {
                                 val = "<a href=\"" + val + "\" target=\"_blank\">" + val + "</a>";
@@ -179,7 +180,7 @@
                             $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")});
                         });
                         if (!keep_detail_view) {
-                            // show first title
+                            // show first title in detail view
                             showText(data[0].text.ismi_id);
                         }
                     }, "json");
--- a/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Sat Dec 19 09:15:43 2015 -0500
+++ b/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Sat Dec 19 09:17:45 2015 -0500
@@ -14,7 +14,7 @@
                     <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>
                         </form>
@@ -100,7 +100,8 @@
     .node.TEXT { fill: #888; }
     .node.TEXT.marked { stroke: red; }
     .node.TEXT.selected { fill: red; }
-    .link { stroke: #999; stroke-opacity: .6; stroke-width: 1px; }
+    .link { stroke: #999; stroke-opacity: .6; stroke-width: 2px; }
+    .arrowHead { fill: #999 }
     tr.marked {border: 2px solid red;}
 </style>
 
@@ -123,8 +124,9 @@
                         if (!data) return;
                         $("#title").text("Title: "+data.title);
                         var $list = $("#info").empty();
-                        $list.append($("<li> author: " + data.author + "</li>"));
+                        $list.append($("<li> author: " + data.author.label + "</li>"));
                         for (var key in data.attrs) {
+                            if (key[0] === "_") continue;
                             var val = data.attrs[key];
                             if (key === "link") {
                                 val = "<a href=\"" + val + "\" target=\"_blank\">" + val + "</a>";
@@ -157,6 +159,7 @@
                         if (!data || data.length == 0) return;
                         // clear all marks
                         $("#graph .marked").each(function(){this.classList.remove("marked")});
+                        // fill list of texts
                         data.forEach(function (row) {
                             var text = row.text;
                             var author = row.author;
@@ -169,6 +172,7 @@
                             // set mark
                             $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")});
                         });
+                        // show details of the first text
                         showText(data[0].text.ismi_id);
                     }, "json");
             return false;
@@ -187,13 +191,30 @@
 
     var force = d3.layout.force()
             .charge(-100) // -200
-            .linkDistance(15) // 30
+            .linkDistance(20) // 30
             .size([width, height]);
 
     var svg = d3.select("#graph").append("svg")
             .attr("width", "1400px").attr("height", "1400px")
             .attr("pointer-events", "all");
 
+    // arrow head marker
+    var defs = svg.append("defs").append("marker")
+                .attr({
+                    "id":"arrow",
+                    "markerUnits": "strokeWidth",
+                    "viewBox":"0 -5 10 10",
+                    "refX": 20, // 5
+                    "refY":0,
+                    "markerWidth":4,
+                    "markerHeight":4,
+                    "orient":"auto"
+                })
+                .append("path")
+                    .attr("d", "M0,-5 L10,0 L0,5")
+                    .attr("class","arrowHead");
+
+    // load graph
     d3.json(backendApiPrefix+"/graph?limit=1000", function(error, graph) {
 		if (error) return;
 		
@@ -201,7 +222,10 @@
 
         var link = svg.selectAll(".link")
                 .data(graph.links).enter()
-                .append("line").attr("class", "link");
+                .append("line").attr({
+                    "class": "link",
+                    "marker-end": "url(#arrow)"
+                    });
 
         var node = svg.selectAll(".node")
                 .data(graph.nodes).enter()