From 2ab5da4bfdce9f41e93a27082900da6ea72db6ed Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 29 Jul 2014 18:50:09 -0400 Subject: Webapp now show three columns image, original text and corrected text. The highlighting is functional as well. --- web/main.py | 4 ++-- web/static/css/style.css | 12 ++++++++++++ web/static/js/main.js | 24 +++++++++++++----------- web/templates/index.html | 31 +++++++++++++++++++++---------- web/utils.py | 12 ++++++------ 5 files changed, 54 insertions(+), 29 deletions(-) (limited to 'web') diff --git a/web/main.py b/web/main.py index 206eb86..b5174d8 100644 --- a/web/main.py +++ b/web/main.py @@ -9,9 +9,9 @@ import io class MainHandler(RequestHandler): def get(self, page_number): - areas, words = utils.gen_html(self.settings["book"], page_number) + orig_coords, orig_words, corr_coords_index, corr_words = utils.gen_html(self.settings["book"], page_number) self.render("index.html", page_number=page_number, - areas=areas, words=words) + orig_coords=orig_coords, orig_words=orig_words, corr_words=corr_words, corr_coords_index=corr_coords_index) class ImageHandler(RequestHandler): diff --git a/web/static/css/style.css b/web/static/css/style.css index e42975d..3005bc5 100644 --- a/web/static/css/style.css +++ b/web/static/css/style.css @@ -10,3 +10,15 @@ span:hover { float: left; margin-right: 1em; } + +#texte-non-corrige { + margin-top:0cm; + width: 10cm; + float: left; +} + +#texte-corrige { + margin-top:0cm; + width: 10cm; + float: left; +} diff --git a/web/static/js/main.js b/web/static/js/main.js index ff09fd1..2adf3ea 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -1,19 +1,21 @@ $(document).ready(function() { $('#page').mapster({ - mapKey: 'data-id', - fillColor: 'ff0000', - fillOpacity: 0.3, - onMouseover: function (e) { - $("#" + e.key).addClass("selected"); - }, - onMouseout: function (e) { - $("#" + e.key).removeClass("selected"); - } - + mapKey: 'data-id', + fillColor: 'ff0000', + fillOpacity: 0.3, + onMouseover: function (e) { + $("#" + "orig-" + e.key).addClass("selected"); + $("#" + "corr-" + e.key).addClass("selected"); + }, + onMouseout: function (e) { + $("#" + "orig-" + e.key).removeClass("selected"); + $("#" + "corr-" + e.key).removeClass("selected"); + } + }).mapster('resize', 500); $("span").mouseenter(function() { - $('area[data-id='+$(this).attr("id")+']').mapster("highlight"); + $('area[data-id='+$(this).attr("id").replace(/\D+/,"")+']').mapster("highlight"); }); $("span").mouseout(function() { diff --git a/web/templates/index.html b/web/templates/index.html index b3b5fe0..2ba18c1 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1,14 +1,25 @@ {% extends "layout.html" %} {% block main %} -
- -
- {% for id, coords in areas %} - {% end %} - -
- {% for id, word in words %} - {{word}} {% end %} -
+
+ +
+ + {% for i, coord in enumerate(orig_coords) %} + + {% end %} + + +
+

Texte original

+ {% for i, word in enumerate(orig_words) %} + {{word}} + {% end %} +
+
+

Texte corrigé

+ {% for i, word in enumerate(corr_words) %} + {{word}} + {% end %} +
{% end %} diff --git a/web/utils.py b/web/utils.py index 8522841..71a5048 100644 --- a/web/utils.py +++ b/web/utils.py @@ -10,12 +10,12 @@ def gen_html(book, page_number): corrected_text = get_page(book, int(page_number)) corrected_words = su.simplify(corrected_text).split() if d: - words, coords = zip(*d) - C = su.align(corrected_words, list(words), list(coords)) - r = su.alignment_to_sexp(corrected_text.split(), words, coords, C[1]) - corrected_words, coords = zip(*r) - coords_html = du.convert_to_htmlcoord(coords, page.size[1]) - return (list(enumerate(coords_html)), list(enumerate(corrected_words))) + orig_words, orig_coords = zip(*d) + C = su.align(corrected_words, list(orig_words), list(orig_coords)) + r = su.alignment_to_coord(corrected_text.split(), C[1]) + corr_words, corr_coords_index = zip(*r) + orig_coords_html = du.convert_to_htmlcoord(orig_coords, page.size[1]) + return orig_coords_html, orig_words, corr_coords_index, corr_words if __name__ == "__main__": gen_html(*sys.argv[1:3]) -- cgit v1.2.3-70-g09d2 From 6283b6582960544dc02e438e739775e3239b802c Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 3 Aug 2014 21:19:55 -0400 Subject: better 2-way highlighting, still not perfect --- web/main.py | 7 ++++--- web/static/js/main.js | 6 ++++-- web/templates/index.html | 5 +++-- web/utils.py | 5 ++--- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'web') diff --git a/web/main.py b/web/main.py index b5174d8..a6826c1 100644 --- a/web/main.py +++ b/web/main.py @@ -9,9 +9,10 @@ import io class MainHandler(RequestHandler): def get(self, page_number): - orig_coords, orig_words, corr_coords_index, corr_words = utils.gen_html(self.settings["book"], page_number) - self.render("index.html", page_number=page_number, - orig_coords=orig_coords, orig_words=orig_words, corr_words=corr_words, corr_coords_index=corr_coords_index) + orig_coords, orig_words, corr_words, align = \ + utils.gen_html(self.settings["book"], page_number) + self.render("index.html", page_number=page_number, orig_coords=orig_coords, + orig_words=orig_words, corr_words=corr_words, align=align) class ImageHandler(RequestHandler): diff --git a/web/static/js/main.js b/web/static/js/main.js index 2adf3ea..c790e34 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -1,6 +1,6 @@ $(document).ready(function() { $('#page').mapster({ - mapKey: 'data-id', + mapKey: 'data-orig', fillColor: 'ff0000', fillOpacity: 0.3, onMouseover: function (e) { @@ -15,7 +15,9 @@ $(document).ready(function() { }).mapster('resize', 500); $("span").mouseenter(function() { - $('area[data-id='+$(this).attr("id").replace(/\D+/,"")+']').mapster("highlight"); + $(this).attr("id").replace(/\D+/,"").split(",").map(function(e){ + $('area[data-orig='+e+']').mapster("highlight"); + }) }); $("span").mouseout(function() { diff --git a/web/templates/index.html b/web/templates/index.html index 2ba18c1..0a07be1 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -6,7 +6,8 @@ {% for i, coord in enumerate(orig_coords) %} - + + {# data-corr="{{",".join(map(str,corr_coords_index[i]))}}" #} {% end %} @@ -19,7 +20,7 @@

Texte corrigé

{% for i, word in enumerate(corr_words) %} - {{word}} + {{word}} {% end %}
{% end %} diff --git a/web/utils.py b/web/utils.py index 71a5048..7e20858 100644 --- a/web/utils.py +++ b/web/utils.py @@ -12,10 +12,9 @@ def gen_html(book, page_number): if d: orig_words, orig_coords = zip(*d) C = su.align(corrected_words, list(orig_words), list(orig_coords)) - r = su.alignment_to_coord(corrected_text.split(), C[1]) - corr_words, corr_coords_index = zip(*r) + corr_words = corrected_text.split() orig_coords_html = du.convert_to_htmlcoord(orig_coords, page.size[1]) - return orig_coords_html, orig_words, corr_coords_index, corr_words + return orig_coords_html, orig_words, corr_words, C[1] if __name__ == "__main__": gen_html(*sys.argv[1:3]) -- cgit v1.2.3-70-g09d2