Commit d1dac3f5e8f3851008633b4be364efdd5a782df2

For Hyd Demo
 Some changes. Please check diff.
  • Diff rendering mode:
  • inline
  • side by side

fetch.py

1from flask import Flask
2from flask import request
3from flask import render_template
4from flask import make_response
5from flask import jsonify
6import logging
7from logging import FileHandler
8import pymongo
9import os
10import lxml.html
11import urllib2
12import StringIO
13import json
14
15app = Flask(__name__)
16
17
18@app.route('/', methods=['GET'])
19def index():
20 if request.args.has_key('url'):
21 return render_template('index.html', url=request.args['url'])
22 else:
23 return render_template('index.html')
24
25
26@app.route('/fetch', methods=['GET'])
27def fetch():
28 connection = pymongo.Connection()
29 db = connection['mural']
30 collection = db['data']
31 ret = {}
32 x = 0
33 resource = "default"
34 if request.args.has_key('uri'):
35 resource = request.args['uri']
36 for i in collection.find({'uri':resource}):
37 del(i['_id'])
38 ret[x] = i
39 x = x + 1
40 if len(ret) == 0:
41 ret['error'] = "Sorry! No re-treats for you."
42 return jsonify(ret)
43
44
45@app.route('/search', methods=['GET'])
46def search():
47 connection = pymongo.Connection()
48 db = connection['mural']
49 collection = db['data']
50 y = 0
51 ret = {}
52 keywords_dict = json.loads(request.args['data'])
53 keywords = json.loads(keywords_dict)['data']
54 for i in collection.find():
55 for keyword in keywords:
56 print keyword
57 try:
58 if keyword in i['nodes']:
59 del(i['_id'])
60 ret[y] = i
61 y = y + 1
62 except:
63 pass
64 return render_template('blank.html', content = ret)
65
66
67@app.route('/submit', methods=['POST'])
68def submit():
69 c = pymongo.Connection()
70 db = c['mural']
71 coll = db['data']
72 requestData = json.loads(request.form['data'])
73 try:
74 for i in requestData:
75 coll.insert(i)
76 response = make_response()
77 response.headers['Access-Control-Allow-Origin'] = '*'
78 response.status = '200 OK'
79 response.status_code = 200
80 return response
81 except:
82 response = make_response()
83 response.status = "500"
84 response.data = "Your post could not be saved. Try posting again."
85 return response
86
87@app.route('/web', methods=['GET'])
88def web():
89 return render_template('web.html')
90
91@app.route('/SWeeText', methods=['GET'])
92def SWeeText():
93 if request.args.has_key('url'):
94 myhandler1 = urllib2.Request(request.args['url'], headers={'User-Agent': "Mozilla/5.0(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"})
95 a = urllib2.urlopen(myhandler1)
96 page = a.read()
97 a.close()
98 try:
99 page = unicode(page, 'utf-8')
100 except UnicodeDecodeError:
101 pass
102 root = lxml.html.parse(StringIO.StringIO(page)).getroot()
103 root.make_links_absolute(request.args['url'], resolve_base_href = True)
104
105 # inject the JS toolbar to annotate text
106 script = root.makeelement('script')
107 script.set('src', 'static/text-annotation.js')
108 tree = root.makeelement('script')
109 tree.set('src', 'static/tree.js')
110 bs_js = root.makeelement('script')
111 bs_js.set('src', 'static/bootstrap.js')
112 jq = root.makeelement('script')
113 jq.set('src', 'static/jquery-1.9.1.min.js')
114 jit = root.makeelement('script')
115 jit.set('src', 'static/jit.js')
116 us = root.makeelement('script')
117 us.set('src', 'static/underscore-min-1.4.4.js')
118
119 link = root.makeelement('link')
120 link.set('href', 'static/text-annotation.css')
121 link.set('type', 'text/css')
122 link.set('rel', 'stylesheet')
123 bs = root.makeelement('link')
124 bs.set('href', 'static/bootstrap.css')
125 bs.set('type', 'text/css')
126 bs.set('rel', 'stylesheet')
127 tree_css = root.makeelement('link')
128 tree_css.set('href', 'static/tree.css')
129 tree_css.set('type', 'text/css')
130 tree_css.set('rel', 'stylesheet')
131
132 root.body.append(jq)
133 root.body.append(bs_js)
134 root.body.append(jit)
135 root.body.append(us)
136 root.body.append(tree)
137 root.body.append(script)
138
139 root.head.append(bs)
140 root.head.append(link)
141 root.head.append(tree_css)
142
143 return lxml.html.tostring(root)
144
145
146#Log the errors, don't depend on apache to log it for you.
147 fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a')
148 fil.setLevel(logging.ERROR)
149 app.logger.addHandler(fil)
150
151
152if __name__ == "__main__":
153 app.run(debug=True, host='0.0.0.0')

server.py

1from flask import Flask
2from flask import request
3from flask import render_template
4from flask import make_response
5from flask import jsonify
6import logging
7from logging import FileHandler
8import pymongo
9import os
10import lxml.html
11import urllib2
12import StringIO
13import json
14
15app = Flask(__name__)
16
17
18@app.route('/', methods=['GET'])
19def index():
20 if request.args.has_key('url'):
21 return render_template('index.html', url=request.args['url'])
22 else:
23 return render_template('index.html')
24
25
26@app.route('/fetch', methods=['GET'])
27def fetch():
28 connection = pymongo.Connection()
29 db = connection['mural']
30 collection = db['data']
31 ret = {}
32 x = 0
33 resource = "default"
34 if request.args.has_key('uri'):
35 resource = request.args['uri']
36 for i in collection.find({'uri':resource}):
37 del(i['_id'])
38 ret[x] = i
39 x = x + 1
40 if len(ret) == 0:
41 ret['error'] = "Sorry! No re-treats for you."
42 return jsonify(ret)
43
44
45@app.route('/search', methods=['GET'])
46def search():
47 connection = pymongo.Connection()
48 db = connection['mural']
49 collection = db['data']
50 y = 0
51 ret = {}
52 keywords_dict = json.loads(request.args['data'])
53 keywords = json.loads(keywords_dict)['data']
54 for i in collection.find():
55 for keyword in keywords:
56 print keyword
57 try:
58 if keyword in i['nodes']:
59 del(i['_id'])
60 ret[y] = i
61 y = y + 1
62 except:
63 pass
64 return render_template('blank.html', content = ret)
65
66
67@app.route('/submit', methods=['POST'])
68def submit():
69 c = pymongo.Connection()
70 db = c['mural']
71 coll = db['data']
72 requestData = json.loads(request.form['data'])
73 try:
74 for i in requestData:
75 coll.insert(i)
76 response = make_response()
77 response.headers['Access-Control-Allow-Origin'] = '*'
78 response.status = '200 OK'
79 response.status_code = 200
80 return response
81 except:
82 response = make_response()
83 response.status = "500"
84 response.data = "Your post could not be saved. Try posting again."
85 return response
86
87@app.route('/web', methods=['GET'])
88def web():
89 return render_template('web.html')
90
91@app.route('/SWeeText', methods=['GET'])
92def SWeeText():
93 if request.args.has_key('url'):
94 # Log -- comment them
95 print "Got URL " + request.args['url'] + " .. Fetching and Parsing.."
96 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"})
97 a = urllib2.urlopen(myhandler1)
98 page = a.read()
99 a.close()
100 try:
101 page = unicode(page, 'utf-8')
102 except UnicodeDecodeError:
103 pass
104 root = lxml.html.parse(StringIO.StringIO(page)).getroot()
105 root.make_links_absolute(request.args['url'], resolve_base_href = True)
106 # Log -- comment them
107 print "Page parsed.. Preparing to send.."
108
109 # inject the JS toolbar to annotate text
110 jq = root.makeelement('script')
111 jq.set('src', 'static/jquery-1.9.1.min.js')
112
113 script = root.makeelement('script')
114 script.set('src', 'static/text-annotation.js')
115
116 tree = root.makeelement('script')
117 tree.set('src', 'static/tree.js')
118
119 bs_js = root.makeelement('script')
120 bs_js.set('src', 'static/bootstrap.js')
121
122 jit = root.makeelement('script')
123 jit.set('src', 'static/jit.js')
124
125 us = root.makeelement('script')
126 us.set('src', 'static/underscore-min-1.4.4.js')
127
128 link = root.makeelement('link')
129 link.set('href', 'static/text-annotation.css')
130 link.set('type', 'text/css')
131 link.set('rel', 'stylesheet')
132
133 bs = root.makeelement('link')
134 bs.set('href', 'static/bootstrap.css')
135 bs.set('type', 'text/css')
136 bs.set('rel', 'stylesheet')
137
138 tree_css = root.makeelement('link')
139 tree_css.set('href', 'static/tree.css')
140 tree_css.set('type', 'text/css')
141 tree_css.set('rel', 'stylesheet')
142
143 root.head.append(bs)
144 root.head.append(link)
145 root.head.append(tree_css)
146
147 root.head.append(jq)
148 root.head.append(bs_js)
149 root.head.append(jit)
150 root.head.append(us)
151 root.head.append(tree)
152 root.head.append(script)
153
154 return lxml.html.tostring(root)
155
156
157#Log the errors, don't depend on apache to log it for you.
158 fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a')
159 fil.setLevel(logging.ERROR)
160 app.logger.addHandler(fil)
161
162
163if __name__ == "__main__":
164 app.run(debug=True, host='0.0.0.0')

static/graphs/GirijaKalyanaStory.json

1[{
2"adjacencies" :[{"nodeTo" :"ShivaPurana",
3"nodeFrom":"GirijaKalyanaStory",
4"data":{"$color":"blue"}}] ,
5"data":{"$color":"white","$type":"ellipse",
6"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
7},{
8"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory",
9"nodeFrom":"ShivaPurana",
10"data":{"$color":"blue"}}] ,
11"data":{"$color":"white","$type":"ellipse",
12"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"ShivaPurana","name":"ShivaPurana"
13},{
14"adjacencies" :[{"nodeTo" :"Pampapathi",
15"nodeFrom":"GirijaKalyanaStory",
16"data":{"$color":"blue"}}] ,
17"data":{"$color":"white","$type":"ellipse",
18"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
19},{
20"adjacencies" :[{"nodeTo" :"Hampamma",
21"nodeFrom":"GirijaKalyanaStory",
22"data":{"$color":"blue"}}] ,
23"data":{"$color":"white","$type":"ellipse",
24"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
25},{
26"adjacencies" :[{"nodeTo" :"Daksha",
27"nodeFrom":"GirijaKalyanaStory",
28"data":{"$color":"blue"}}] ,
29"data":{"$color":"white","$type":"ellipse",
30"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
31},{
32"adjacencies" :[{"nodeTo" :"GirijaKalyanaMural",
33"nodeFrom":"GirijaKalyanaStory",
34"data":{"$color":"blue"}}] ,
35"data":{"$color":"white","$type":"ellipse",
36"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
37},{
38"adjacencies" :[{"nodeTo" :"PalaPuja",
39"nodeFrom":"GirijaKalyanaStory",
40"data":{"$color":"blue"}}] ,
41"data":{"$color":"white","$type":"ellipse",
42"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
43},{
44"adjacencies" :[{"nodeTo" :"KalyanUtsav",
45"nodeFrom":"GirijaKalyanaStory",
46"data":{"$color":"blue"}}] ,
47"data":{"$color":"white","$type":"ellipse",
48"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory"
49},{
50"adjacencies" :[{"nodeTo" :"PampapathiEg1",
51"nodeFrom":"Pampapathi",
52"data":{"$color":"blue"}}] ,
53"data":{"$color":"lightgray","$type":"rectangle",
54"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
55},{
56"adjacencies" :[{"nodeTo" :"PampapathiEg2",
57"nodeFrom":"Pampapathi",
58"data":{"$color":"blue"}}] ,
59"data":{"$color":"lightgray","$type":"rectangle",
60"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
61},{
62"adjacencies" :[{"nodeTo" :"Snake",
63"nodeFrom":"Pampapathi",
64"data":{"$color":"blue"}}] ,
65"data":{"$color":"lightgray","$type":"rectangle",
66"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
67},{
68"adjacencies" :[{"nodeTo" :"Nandi",
69"nodeFrom":"Pampapathi",
70"data":{"$color":"blue"}}] ,
71"data":{"$color":"lightgray","$type":"rectangle",
72"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
73},{
74"adjacencies" :[{"nodeTo" :"Hampamma",
75"nodeFrom":"Pampapathi",
76"data":{"$color":"black"}}] ,
77"data":{"$color":"lightgray","$type":"rectangle",
78"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
79},{
80"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory",
81"nodeFrom":"Pampapathi",
82"data":{"$color":"blue"}}] ,
83"data":{"$color":"lightgray","$type":"rectangle",
84"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi"
85},{
86"adjacencies" :[{"nodeTo" :"Pampapathi",
87"nodeFrom":"Hampamma",
88"data":{"$color":"black"}}] ,
89"data":{"$color":"lightgray","$type":"rectangle",
90"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma"
91},{
92"adjacencies" :[{"nodeTo" :"Daksha",
93"nodeFrom":"Hampamma",
94"data":{"$color":"black"}}] ,
95"data":{"$color":"lightgray","$type":"rectangle",
96"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma"
97},{
98"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory",
99"nodeFrom":"Hampamma",
100"data":{"$color":"blue"}}] ,
101"data":{"$color":"lightgray","$type":"rectangle",
102"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma"
103},{
104"adjacencies" :[{"nodeTo" :"Hampamma",
105"nodeFrom":"Daksha",
106"data":{"$color":"black"}}] ,
107"data":{"$color":"lightgray","$type":"rectangle",
108"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha"
109},{
110"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory",
111"nodeFrom":"Daksha",
112"data":{"$color":"blue"}}] ,
113"data":{"$color":"lightgray","$type":"rectangle",
114"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha"
115},{
116"adjacencies" :[{"nodeTo" :"GirijaKalyanaEg",
117"nodeFrom":"GirijaKalyanaMural",
118"data":{"$color":"blue"}}] ,
119"data":{"$color":"white","$type":"ellipse",
120"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
121},{
122"adjacencies" :[{"nodeTo" :"Anklet",
123"nodeFrom":"GirijaKalyanaMural",
124"data":{"$color":"blue"}}] ,
125"data":{"$color":"white","$type":"ellipse",
126"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
127},{
128"adjacencies" :[{"nodeTo" :"Pampapathi",
129"nodeFrom":"GirijaKalyanaMural",
130"data":{"$color":"blue"}}] ,
131"data":{"$color":"white","$type":"ellipse",
132"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
133},{
134"adjacencies" :[{"nodeTo" :"Hampamma",
135"nodeFrom":"GirijaKalyanaMural",
136"data":{"$color":"blue"}}] ,
137"data":{"$color":"white","$type":"ellipse",
138"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
139},{
140"adjacencies" :[{"nodeTo" :"Daksha",
141"nodeFrom":"GirijaKalyanaMural",
142"data":{"$color":"blue"}}] ,
143"data":{"$color":"white","$type":"ellipse",
144"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
145},{
146"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory",
147"nodeFrom":"GirijaKalyanaMural",
148"data":{"$color":"blue"}}] ,
149"data":{"$color":"white","$type":"ellipse",
150"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
151},{
152"adjacencies" :[{"nodeTo" :"KalyanaMantapa",
153"nodeFrom":"GirijaKalyanaMural",
154"data":{"$color":"blue"}}] ,
155"data":{"$color":"white","$type":"ellipse",
156"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
157},{
158"adjacencies" :[{"nodeTo" :"VijaynagaraTradition",
159"nodeFrom":"GirijaKalyanaMural",
160"data":{"$color":"blue"}}] ,
161"data":{"$color":"white","$type":"ellipse",
162"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural"
163},{
164"adjacencies" :[{"nodeTo" :"NandiEg",
165"nodeFrom":"Nandi",
166 "data":{"$color":"blue"}}] ,
167"data":{"$color":"lightgray","$type":"rectangle",
168"$label-color":"black","$label-size":"20","$nodeDir":""},"id":"Nandi","name":"Nandi"
169}]

static/text-annotation.css

1#annotate-bar {1#annotate-bar {
2 position: absolute;
2 position: fixed;
3 width: 80%;
3 top: 1px;4 top: 1px;
4 left: 35%;
5 width: 180px;
6 height: 35px;
7 margin: auto;
8 border: 1px solid black;
9 background-color: #F0F0F0;
10 border-radius: 3px;
11 opacity: 0.9;
12 z-index: 1000;
13 padding: 3px 10px;
14}5}
15#anno-btn {
16 margin: 0 5px;
17 opacity: 1;
18}
19#publish {
20 opacity:1;
21 margin: 0 5px;
22}
23#sweeted {6#sweeted {
24 opacity: 1;
25 z-index: 1000 !important;7 z-index: 1000 !important;
26 display: none;8 display: none;
27 width: 400px !important;
28 font-style: bold !important;
29 font-size: 16px;9 font-size: 16px;
10 width: 100%;
11}
12.alert {
13 margin: auto;
14 width: 700px;
15 box-shadow: 3px 3px 3px #468847;
30}16}

static/text-annotation.js

32 nodes[i].addEventListener('mouseout', onHoverOut);32 nodes[i].addEventListener('mouseout', onHoverOut);
33 }33 }
34 }34 }
35 //$(document).mouseover(onHover);
36 //$(document).mouseout(onHoverOut);
35 };37 };
36 var removeSelect = function() {38 var removeSelect = function() {
37 var nodes = document.getElementsByTagName('*');39 var nodes = document.getElementsByTagName('*');
45 nodes[i].removeEventListener('mouseout', onHoverOut);45 nodes[i].removeEventListener('mouseout', onHoverOut);
46 }46 }
47 }47 }
48 //$(document).unbind('mouseover', onHover);
49 //$(document).unbind('mouseout', onHoverOut);
48 };50 };
49 var toolbar_template = function() {51 var toolbar_template = function() {
50 return '<div class="toolbar"><button class="btn" id="anno-btn" onclick="initSelect();">'+
51 'Annotate</button> <button class="btn" id="publish">Publish</button></div>' +
52 '<div class="alert alert-error" id="sweeted"><button type="button" class="close" data-dismiss="alert">&times;</button><div id="sweet"></div></div>'+
53 '<div id="posted" class="alert alert-success" style="display: none; width: 300px; margin: auto;"><button type="button" class="close" data-dismiss="alert">&times;</button><b>Success!</b> </div><div id="fail-posting" class="alert alert-error" style="display: none; width: 300px; margin: auto;"><button type="button" class="close" data-dismiss="alert">&times;</button><b>Error!</b> Something went wrong. Could not post.</div>';
52 return '<div class="navbar">'+
53 '<div class="navbar-inner"> <ul class="nav">'+
54 '<li><a class="brand" href="#"> IDH-SWeeTer Annotation </a></li>' +
55 '<li><a></a></li>'+
56 '<li><a></a></li>'+
57 '<li><button class="btn" id="anno-btn" onclick="initSelect();">Annotate</button></li>' +
58 '<li><a></a></li>'+
59 '<li><button class="btn" id="publish">Publish</button></li>' +
60 '</ul></div></div>' +
61 '<div id="sweeted"></div> <div id="posted"></div> <div id="fail-posting"></div>';
54 };62 };
63
55 var modal_template = function() {64 var modal_template = function() {
56 return '<div id="annotation-tree" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <div id="myModalLabel"> <h3>Annotation attributes</h3> <small>Select attributes for annotation</small> </div> </div> <div class="modal-body"> <div id="stats"> <div id="node-info"></div> <div id="selected-nodes"></div> </div> <div id="infovis"></div> <div id="status"></div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button class="btn btn-primary" onclick="closeAnnotationTree();">Save changes</button> </div> </div>';65 return '<div id="annotation-tree" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <div id="myModalLabel"> <h3>Annotation attributes</h3> <small>Select attributes for annotation</small> </div> </div> <div class="modal-body"> <div id="stats"> <div id="node-info"></div> <div id="selected-nodes"></div> </div> <div id="infovis"></div> <div id="status"></div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button class="btn btn-primary" onclick="closeAnnotationTree();">Save changes</button> </div> </div>';
57 };66 };
84 elem.removeEventListener('click', onClick);84 elem.removeEventListener('click', onClick);
85 };85 };
86 var onClick = function(event) {86 var onClick = function(event) {
87 console.log(event);
88 //$(event).preventDefault();
87 //console.log(event);
88 //event.stopImmediatePropagation();
89 event.stopPropagation();89 event.stopPropagation();
90 var elem = event.currentTarget;
90 event.preventDefault();
91 var elem = event.target;
91 elem.style.border = 'none';92 elem.style.border = 'none';
92 elem.style.boxShadow = '';93 elem.style.boxShadow = '';
93 //console.log('clicked', elem);94 //console.log('clicked', elem);
100 return false;100 return false;
101 };101 };
102102
103
104var DOM = {
105 getXpath : function (element)
106 {
107 var str = '';
108 var currentNode = element;
109 var path = '';
110 var index = -1;
111
112 if (currentNode.nodeName != "#text")
113 {
114 path = DOM.makePath(currentNode);
115 }
116 else
117 {
118 path = DOM.makePath(currentNode.parentNode);
119 }
120
121
122 return path;
103 // Object containing methods to find out xpath of an
104 // element
105 var DOM = {
106 getXpath: function(element) {
107 var str = '';
108 var currentNode = element;
109 var path = '';
110 var index = -1;
111 if (currentNode.nodeName != "#text") {
112 path = DOM.makePath(currentNode);
113 }
114 else {
115 path = DOM.makePath(currentNode.parentNode);
116 }
117 return path;
123 },118 },
124 getElementIdx : function getElementIdx(elt)
125 {
126 var count = 1;
127 for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling)
128 {
129 if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++
130 }
131
132 return count;
119 getElementIdx: function(elt) {
120 var count = 1;
121 for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling) {
122 if(sib.nodeType == 1 && sib.tagName == elt.tagName) {
123 count++;
124 }
125 }
126 return count;
133 },127 },
134
135 makePath : function makePath(elt){
136 var path = '';
137 for (; elt && elt.nodeType == 1; elt = elt.parentNode)
138 {
139 if(elt.id == "")
140 {
141 idx = DOM.getElementIdx(elt);
142 xname = elt.tagName;
143 if (idx > 1)
144 xname += "[" + idx + "]";
145 path = "/" + xname + path;
146 }
147 else
148 {
149 path = "//*[@id='"+elt.id+"']"+path;
150 break;
151 }
152 }
153 return path;
128 makePath: function(elt) {
129 var path = '';
130 for (; elt && elt.nodeType == 1; elt = elt.parentNode) {
131 if(elt.id == "") {
132 idx = DOM.getElementIdx(elt);
133 xname = elt.tagName;
134 if (idx > 1) {
135 xname += "[" + idx + "]";
136 }
137 path = "/" + xname + path;
138 }
139 else {
140 path = "//*[@id='"+elt.id+"']"+path;
141 break;
142 }
143 }
144 return path;
154 },145 },
155 settextContent : function(element, content){
156 $(element).html(content);
146 settextContent: function(element, content) {
147 $(element).html(content);
157 },148 },
158 gettextContent:function(element)
159 {
160 return $(element).html();
161 },
162};
149 gettextContent: function(element) {
150 return $(element).html();
151 }
152 };
163})();153})();
164var config = {154var config = {
165 'postTweetUrl':'http://localhost:5001',155 'postTweetUrl':'http://localhost:5001',

static/tree.js

43 return;43 return;
44 }44 }
45 console.log('Loading ontology file');45 console.log('Loading ontology file');
46 var url = 'static/graphs/Hampi_GirijaKalyana.json'
46 var url = 'static/graphs/GirijaKalyanaStory.json'
47 $.ajax({47 $.ajax({
48 type: 'GET',48 type: 'GET',
49 url: url,49 url: url,
204 $('#fail-posting').show();204 $('#fail-posting').show();
205 }205 }
206 });*/206 });*/
207 $('#posted').show();
207 //$('#posted').html(posted_template());
208 //$('#posted').show();
208 var swts = '';209 var swts = '';
209 for(var i in sweet.swts) {210 for(var i in sweet.swts) {
210 var data = sweet.swts[i];211 var data = sweet.swts[i];
221 swts += swt + '\n';221 swts += swt + '\n';
222 }222 }
223 console.log(swts);223 console.log(swts);
224 $('#sweeted').html(sweeted_template(swts));
224 $('#sweeted').show();225 $('#sweeted').show();
225 $('#sweet').html(swts);
226 sweet.swts = [];226 sweet.swts = [];
227 },227 },
228 error: function() {228 error: function() {
229 //$('#fail-posting').show();
229 $('#fail-posting').html(fail_posting_template());
230 $('#fail-posting').show();
230 }231 }
231 });232 });
232 }233 }
233};234};
234235
236var sweeted_template = function(msg) {
237 return '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button><div>' + msg + '</div></div>';
238 };
239 var posted_template = function() {
240 return '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button><b>Success!</b> </div>';
241 };
242 var fail_posting_template = function() {
243 return '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button><b>Error!</b> Something went wrong. Could not post.</div>';
244 };
245
235function closeAnnotationTree() {246function closeAnnotationTree() {
236 $('#annotation-tree').modal('hide');247 $('#annotation-tree').modal('hide');
237 $('#infovis').html('');248 $('#infovis').html('');
257 injectInto: 'infovis',257 injectInto: 'infovis',
258 Navigation: {258 Navigation: {
259 enable: true,259 enable: true,
260 //panning: 'avoid nodes',
260 panning: 'avoid nodes',
261 zooming: 10261 zooming: 10
262 },262 },
263 Node: {263 Node: {

templates/index.html

3<head>3<head>
4 <meta charset="utf-8">4 <meta charset="utf-8">
5 <meta http-equiv='imagetoolbar' content='no'/>5 <meta http-equiv='imagetoolbar' content='no'/>
6 <title> Lepakshi Mural Annotation </title>
6 <title> IDH-SWeeTer Annotation </title>
7 <link rel="stylesheet" type="text/css" href="static/bootstrap.css"></link>7 <link rel="stylesheet" type="text/css" href="static/bootstrap.css"></link>
8 <link rel="stylesheet" type="text/css" href="static/tree.css"></link>8 <link rel="stylesheet" type="text/css" href="static/tree.css"></link>
9 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>9 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
2424
25 <div class="navbar">25 <div class="navbar">
26 <div class="navbar-inner">26 <div class="navbar-inner">
27 <a class="brand" href="#">Lepakshi Mural</a>
27 <a class="brand" href="#"> IDH-SWeeTer Annotation </a>
28 <ul class="nav">28 <ul class="nav">
29 <li class="active"><a href="#">Home</a></li>29 <li class="active"><a href="#">Home</a></li>
30 <li><a></a></li>30 <li><a></a></li>
5050
51 <div id="notification">51 <div id="notification">
52 </div>52 </div>
53 <div id="posted" class="alert alert-success" style="display: none; width: 300px; margin: auto;">
54 <button type="button" class="close" data-dismiss="alert">&times;</button>
55 <b>Success!</b> Post successfully posted.
56 </div>
57 <div id="fail-posting" class="alert alert-error" style="display: none; width: 300px; margin: auto;">
58 <button type="button" class="close" data-dismiss="alert">&times;</button>
59 <b>Error!</b> Something went wrong. Could not post.
60 </div>
53 <div id="sweeted"></div>
54 <div id="posted"></div>
55 <div id="fail-posting"></div>
6156
62 <!--div class="btn-group">57 <!--div class="btn-group">
63 <button onclick="handler.trigger();" class="btn btn-small">Mural</button>58 <button onclick="handler.trigger();" class="btn btn-small">Mural</button>

templates/web.html

3<head>3<head>
4 <meta charset="utf-8">4 <meta charset="utf-8">
5 <meta http-equiv='imagetoolbar' content='no'/>5 <meta http-equiv='imagetoolbar' content='no'/>
6 <title> Text Annotation </title>
6 <title> Web Annotation </title>
7 <link rel="stylesheet" type="text/css" href="static/bootstrap.css"></link>7 <link rel="stylesheet" type="text/css" href="static/bootstrap.css"></link>
8 <script type="text/javascript" src="static/jquery-1.9.1.min.js"></script>
8 <script type="text/javascript" src="static/bootstrap.js"></script>9 <script type="text/javascript" src="static/bootstrap.js"></script>
10 <style type="text/css">
11 .container {
12 margin-top: 30px;
13 }
14 </style>
9</head>15</head>
10 <body>16 <body>
11 <div class="fluid-container">
12 <div class="explain lead"> Text annotation of Hampi related content using the IDH Mowl</div>
17 <div class="container">
18 <div class="explain lead"> IDH-SWeeTer Annotation for Web Pages </div>
13 <div class="input span9">19 <div class="input span9">
14 Enter URL to annotate: <input id="url" type="text" placeholder="http://hampi.co.in">
20 Enter URL to annotate: <input id="url" type="text" placeholder="http://vijayanagara.in">
15 <button class="btn" onclick="loadURL();"> Load </button>21 <button class="btn" onclick="loadURL();"> Load </button>
16 </div>22 </div>
17 </div>23 </div>
18 <script>24 <script>
19 function loadURL() {25 function loadURL() {
20 var url = document.getElementById('url').value;26 var url = document.getElementById('url').value;
27 if(!url) {
28 url = 'http://vijayanagara.in';
29 }
21 if(!url.match(/http/)) {30 if(!url.match(/http/)) {
22 url = 'http://' + url;31 url = 'http://' + url;
23 }32 }