--- a/fetch.py +++ /dev/null @@ -1,154 +1 @@ -from flask import Flask -from flask import request -from flask import render_template -from flask import make_response -from flask import jsonify -import logging -from logging import FileHandler -import pymongo -import os -import lxml.html -import urllib2 -import StringIO -import json - -app = Flask(__name__) - - -@app.route('/', methods=['GET']) -def index(): - if request.args.has_key('url'): - return render_template('index.html', url=request.args['url']) - else: - return render_template('index.html') - - -@app.route('/fetch', methods=['GET']) -def fetch(): - connection = pymongo.Connection() - db = connection['mural'] - collection = db['data'] - ret = {} - x = 0 - resource = "default" - if request.args.has_key('uri'): - resource = request.args['uri'] - for i in collection.find({'uri':resource}): - del(i['_id']) - ret[x] = i - x = x + 1 - if len(ret) == 0: - ret['error'] = "Sorry! No re-treats for you." - return jsonify(ret) - - -@app.route('/search', methods=['GET']) -def search(): - connection = pymongo.Connection() - db = connection['mural'] - collection = db['data'] - y = 0 - ret = {} - keywords_dict = json.loads(request.args['data']) - keywords = json.loads(keywords_dict)['data'] - for i in collection.find(): - for keyword in keywords: - print keyword - try: - if keyword in i['nodes']: - del(i['_id']) - ret[y] = i - y = y + 1 - except: - pass - return render_template('blank.html', content = ret) - - -@app.route('/submit', methods=['POST']) -def submit(): - c = pymongo.Connection() - db = c['mural'] - coll = db['data'] - requestData = json.loads(request.form['data']) - try: - for i in requestData: - coll.insert(i) - response = make_response() - response.headers['Access-Control-Allow-Origin'] = '*' - response.status = '200 OK' - response.status_code = 200 - return response - except: - response = make_response() - response.status = "500" - response.data = "Your post could not be saved. Try posting again." - return response - -@app.route('/web', methods=['GET']) -def web(): - return render_template('web.html') - -@app.route('/SWeeText', methods=['GET']) -def SWeeText(): - if request.args.has_key('url'): - myhandler1 = urllib2.Request(request.args['url'], headers={'User-Agent': "Mozilla/5.0(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"}) - a = urllib2.urlopen(myhandler1) - page = a.read() - a.close() - try: - page = unicode(page, 'utf-8') - except UnicodeDecodeError: - pass - root = lxml.html.parse(StringIO.StringIO(page)).getroot() - root.make_links_absolute(request.args['url'], resolve_base_href = True) - - # inject the JS toolbar to annotate text - script = root.makeelement('script') - script.set('src', 'static/text-annotation.js') - tree = root.makeelement('script') - tree.set('src', 'static/tree.js') - bs_js = root.makeelement('script') - bs_js.set('src', 'static/bootstrap.js') - jq = root.makeelement('script') - jq.set('src', 'static/jquery-1.9.1.min.js') - jit = root.makeelement('script') - jit.set('src', 'static/jit.js') - us = root.makeelement('script') - us.set('src', 'static/underscore-min-1.4.4.js') - - link = root.makeelement('link') - link.set('href', 'static/text-annotation.css') - link.set('type', 'text/css') - link.set('rel', 'stylesheet') - bs = root.makeelement('link') - bs.set('href', 'static/bootstrap.css') - bs.set('type', 'text/css') - bs.set('rel', 'stylesheet') - tree_css = root.makeelement('link') - tree_css.set('href', 'static/tree.css') - tree_css.set('type', 'text/css') - tree_css.set('rel', 'stylesheet') - - root.body.append(jq) - root.body.append(bs_js) - root.body.append(jit) - root.body.append(us) - root.body.append(tree) - root.body.append(script) - - root.head.append(bs) - root.head.append(link) - root.head.append(tree_css) - - return lxml.html.tostring(root) - - -#Log the errors, don't depend on apache to log it for you. - fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') - fil.setLevel(logging.ERROR) - app.logger.addHandler(fil) - - -if __name__ == "__main__": - app.run(debug=True, host='0.0.0.0') --- /dev/null +++ b/server.py @@ -1 +1,165 @@ +from flask import Flask +from flask import request +from flask import render_template +from flask import make_response +from flask import jsonify +import logging +from logging import FileHandler +import pymongo +import os +import lxml.html +import urllib2 +import StringIO +import json + +app = Flask(__name__) + + +@app.route('/', methods=['GET']) +def index(): + if request.args.has_key('url'): + return render_template('index.html', url=request.args['url']) + else: + return render_template('index.html') + + +@app.route('/fetch', methods=['GET']) +def fetch(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + ret = {} + x = 0 + resource = "default" + if request.args.has_key('uri'): + resource = request.args['uri'] + for i in collection.find({'uri':resource}): + del(i['_id']) + ret[x] = i + x = x + 1 + if len(ret) == 0: + ret['error'] = "Sorry! No re-treats for you." + return jsonify(ret) + + +@app.route('/search', methods=['GET']) +def search(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + y = 0 + ret = {} + keywords_dict = json.loads(request.args['data']) + keywords = json.loads(keywords_dict)['data'] + for i in collection.find(): + for keyword in keywords: + print keyword + try: + if keyword in i['nodes']: + del(i['_id']) + ret[y] = i + y = y + 1 + except: + pass + return render_template('blank.html', content = ret) + + +@app.route('/submit', methods=['POST']) +def submit(): + c = pymongo.Connection() + db = c['mural'] + coll = db['data'] + requestData = json.loads(request.form['data']) + try: + for i in requestData: + coll.insert(i) + response = make_response() + response.headers['Access-Control-Allow-Origin'] = '*' + response.status = '200 OK' + response.status_code = 200 + return response + except: + response = make_response() + response.status = "500" + response.data = "Your post could not be saved. Try posting again." + return response + +@app.route('/web', methods=['GET']) +def web(): + return render_template('web.html') + +@app.route('/SWeeText', methods=['GET']) +def SWeeText(): + if request.args.has_key('url'): + # Log -- comment them + print "Got URL " + request.args['url'] + " .. Fetching and Parsing.." + myhandler1 = urllib2.Request(request.args['url'], headers={'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"}) + a = urllib2.urlopen(myhandler1) + page = a.read() + a.close() + try: + page = unicode(page, 'utf-8') + except UnicodeDecodeError: + pass + root = lxml.html.parse(StringIO.StringIO(page)).getroot() + root.make_links_absolute(request.args['url'], resolve_base_href = True) + # Log -- comment them + print "Page parsed.. Preparing to send.." + + # inject the JS toolbar to annotate text + jq = root.makeelement('script') + jq.set('src', 'static/jquery-1.9.1.min.js') + + script = root.makeelement('script') + script.set('src', 'static/text-annotation.js') + + tree = root.makeelement('script') + tree.set('src', 'static/tree.js') + + bs_js = root.makeelement('script') + bs_js.set('src', 'static/bootstrap.js') + + jit = root.makeelement('script') + jit.set('src', 'static/jit.js') + + us = root.makeelement('script') + us.set('src', 'static/underscore-min-1.4.4.js') + + link = root.makeelement('link') + link.set('href', 'static/text-annotation.css') + link.set('type', 'text/css') + link.set('rel', 'stylesheet') + + bs = root.makeelement('link') + bs.set('href', 'static/bootstrap.css') + bs.set('type', 'text/css') + bs.set('rel', 'stylesheet') + + tree_css = root.makeelement('link') + tree_css.set('href', 'static/tree.css') + tree_css.set('type', 'text/css') + tree_css.set('rel', 'stylesheet') + + root.head.append(bs) + root.head.append(link) + root.head.append(tree_css) + + root.head.append(jq) + root.head.append(bs_js) + root.head.append(jit) + root.head.append(us) + root.head.append(tree) + root.head.append(script) + + return lxml.html.tostring(root) + + +#Log the errors, don't depend on apache to log it for you. + fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') + fil.setLevel(logging.ERROR) + app.logger.addHandler(fil) + + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0') --- /dev/null +++ b/static/graphs/GirijaKalyanaStory.json @@ -1 +1,170 @@ +[{ +"adjacencies" :[{"nodeTo" :"ShivaPurana", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"ShivaPurana", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"ShivaPurana","name":"ShivaPurana" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaMural", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"PalaPuja", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"KalyanUtsav", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"PampapathiEg1", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"PampapathiEg2", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Snake", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Nandi", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"Pampapathi", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"Hampamma", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"Hampamma", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Hampamma", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"Daksha", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Daksha", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaEg", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Anklet", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"KalyanaMantapa", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"VijaynagaraTradition", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"NandiEg", +"nodeFrom":"Nandi", + "data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodeDir":""},"id":"Nandi","name":"Nandi" +}] --- a/static/text-annotation.css +++ b/static/text-annotation.css @@ -1,31 +1,17 @@ #annotate-bar { - position: absolute; + position: fixed; + width: 80%; top: 1px; - left: 35%; - width: 180px; - height: 35px; - margin: auto; - border: 1px solid black; - background-color: #F0F0F0; - border-radius: 3px; - opacity: 0.9; - z-index: 1000; - padding: 3px 10px; } -#anno-btn { - margin: 0 5px; - opacity: 1; -} -#publish { - opacity:1; - margin: 0 5px; -} #sweeted { - opacity: 1; z-index: 1000 !important; display: none; - width: 400px !important; - font-style: bold !important; font-size: 16px; + width: 100%; +} +.alert { + margin: auto; + width: 700px; + box-shadow: 3px 3px 3px #468847; } --- a/static/text-annotation.js +++ b/static/text-annotation.js @@ -32,6 +32,8 @@ nodes[i].addEventListener('mouseout', onHoverOut); } } + //$(document).mouseover(onHover); + //$(document).mouseout(onHoverOut); }; var removeSelect = function() { var nodes = document.getElementsByTagName('*'); @@ -43,13 +45,22 @@ nodes[i].removeEventListener('mouseout', onHoverOut); } } + //$(document).unbind('mouseover', onHover); + //$(document).unbind('mouseout', onHoverOut); }; var toolbar_template = function() { - return '
' + - '
'+ - ''; + return '' + + '
'; }; + var modal_template = function() { return ''; }; @@ -73,10 +84,11 @@ elem.removeEventListener('click', onClick); }; var onClick = function(event) { - console.log(event); - //$(event).preventDefault(); + //console.log(event); + //event.stopImmediatePropagation(); event.stopPropagation(); - var elem = event.currentTarget; + event.preventDefault(); + var elem = event.target; elem.style.border = 'none'; elem.style.boxShadow = ''; //console.log('clicked', elem); @@ -88,66 +100,56 @@ return false; }; - -var DOM = { - getXpath : function (element) - { - var str = ''; - var currentNode = element; - var path = ''; - var index = -1; - - if (currentNode.nodeName != "#text") - { - path = DOM.makePath(currentNode); - } - else - { - path = DOM.makePath(currentNode.parentNode); - } - - - return path; + // Object containing methods to find out xpath of an + // element + var DOM = { + getXpath: function(element) { + var str = ''; + var currentNode = element; + var path = ''; + var index = -1; + if (currentNode.nodeName != "#text") { + path = DOM.makePath(currentNode); + } + else { + path = DOM.makePath(currentNode.parentNode); + } + return path; }, - getElementIdx : function getElementIdx(elt) - { - var count = 1; - for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling) - { - if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++ - } - - return count; + getElementIdx: function(elt) { + var count = 1; + for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling) { + if(sib.nodeType == 1 && sib.tagName == elt.tagName) { + count++; + } + } + return count; }, - - makePath : function makePath(elt){ - var path = ''; - for (; elt && elt.nodeType == 1; elt = elt.parentNode) - { - if(elt.id == "") - { - idx = DOM.getElementIdx(elt); - xname = elt.tagName; - if (idx > 1) - xname += "[" + idx + "]"; - path = "/" + xname + path; - } - else - { - path = "//*[@id='"+elt.id+"']"+path; - break; - } - } - return path; + makePath: function(elt) { + var path = ''; + for (; elt && elt.nodeType == 1; elt = elt.parentNode) { + if(elt.id == "") { + idx = DOM.getElementIdx(elt); + xname = elt.tagName; + if (idx > 1) { + xname += "[" + idx + "]"; + } + path = "/" + xname + path; + } + else { + path = "//*[@id='"+elt.id+"']"+path; + break; + } + } + return path; }, - settextContent : function(element, content){ - $(element).html(content); + settextContent: function(element, content) { + $(element).html(content); }, - gettextContent:function(element) - { - return $(element).html(); - }, -}; + gettextContent: function(element) { + return $(element).html(); + } + }; })(); var config = { 'postTweetUrl':'http://localhost:5001', --- a/static/tree.js +++ b/static/tree.js @@ -43,7 +43,7 @@ return; } console.log('Loading ontology file'); - var url = 'static/graphs/Hampi_GirijaKalyana.json' + var url = 'static/graphs/GirijaKalyanaStory.json' $.ajax({ type: 'GET', url: url, @@ -204,7 +204,8 @@ $('#fail-posting').show(); } });*/ - $('#posted').show(); + //$('#posted').html(posted_template()); + //$('#posted').show(); var swts = ''; for(var i in sweet.swts) { var data = sweet.swts[i]; @@ -220,17 +221,28 @@ swts += swt + '\n'; } console.log(swts); + $('#sweeted').html(sweeted_template(swts)); $('#sweeted').show(); - $('#sweet').html(swts); sweet.swts = []; }, error: function() { - //$('#fail-posting').show(); + $('#fail-posting').html(fail_posting_template()); + $('#fail-posting').show(); } }); } }; +var sweeted_template = function(msg) { + return '
' + msg + '
'; + }; + var posted_template = function() { + return '
Success!
'; + }; + var fail_posting_template = function() { + return '
Error! Something went wrong. Could not post.
'; + }; + function closeAnnotationTree() { $('#annotation-tree').modal('hide'); $('#infovis').html(''); @@ -245,7 +257,7 @@ injectInto: 'infovis', Navigation: { enable: true, - //panning: 'avoid nodes', + panning: 'avoid nodes', zooming: 10 }, Node: { --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,7 @@ - Lepakshi Mural Annotation + IDH-SWeeTer Annotation @@ -24,7 +24,7 @@