diff options
| -rw-r--r-- | string_utils.py | 12 | ||||
| -rw-r--r-- | web/main.py | 4 | ||||
| -rw-r--r-- | web/static/css/style.css | 12 | ||||
| -rw-r--r-- | web/static/js/main.js | 24 | ||||
| -rw-r--r-- | web/templates/index.html | 31 | ||||
| -rw-r--r-- | web/utils.py | 12 |
6 files changed, 62 insertions, 33 deletions
diff --git a/string_utils.py b/string_utils.py index a8a38c0..7120219 100644 --- a/string_utils.py +++ b/string_utils.py @@ -156,18 +156,22 @@ def print_alignment(l1, l2, c2, alignment): for word in l2: print u"{0:>25} | {1}".format("", word) -def alignment_to_sexp(l1, l2, c2, alignment): +def alignment_to_coord(l1, alignment): + # l1 list of corrected words + # alignment list of size len(l1) qui mappe mots dans l2 + # returns indices in l2 + r = [] prev = 0 for index, g in itertools.groupby(zip(l1, alignment), lambda x:x[1]): word = " ".join([a[0] for a in g]) if not index: - r.append([word, []]) + r.append([word, None]) else: begin, end = index[0], index[-1] if end > begin: #need to find a better way to get the box coordinates - r.append([word, c2[begin]]) + r.append([word, begin]) else: - r.append([word, c2[begin]]) + r.append([word, begin]) return r 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 %} - <div id="image_container"> - <img id="page" src="{{page_number}}.jpg" usemap="#wordmap" /> - </div> - <map name="wordmap">{% for id, coords in areas %} - <area href="#" shape="rect" coords="{{coords}}" data-id="{{id}}" />{% end %} - </map> - <div id="text"> - {% for id, word in words %} - <span id="{{id}}">{{word}}</span> {% end %} - </div> +<div id="image_container"> + <img id="page" src="{{page_number}}.jpg" usemap="#wordmap" /> +</div> +<map name="wordmap"> + {% for i, coord in enumerate(orig_coords) %} + <area href="#" shape="rect" coords="{{coord}}" data-id="{{i}}" /> + {% end %} +</map> + +<div id="texte-non-corrige"> + <h3>Texte original</h3> + {% for i, word in enumerate(orig_words) %} + <span id="orig-{{i}}">{{word}}</span> + {% end %} +</div> +<div id="texte-corrige"> + <h3>Texte corrigé</h3> + {% for i, word in enumerate(corr_words) %} + <span id="corr-{{corr_coords_index[i]}}">{{word}}</span> + {% end %} +</div> {% 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]) |
