From bf74cd2294598c3dc1d73edd74ca88c87b7d6cd6 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 1 Mar 2014 15:26:45 -0500 Subject: Preliminary support for corrected text * It's slow, need to figure out how to load it in the background maybe * The bouding boxes could be improved --- web/utils.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'web/utils.py') diff --git a/web/utils.py b/web/utils.py index bb9a4fe..8522841 100644 --- a/web/utils.py +++ b/web/utils.py @@ -1,12 +1,21 @@ -from parsedjvutext import parse_book +import djvu_utils as du import sys - +import string_utils as su +from wikisource import get_page def gen_html(book, page_number): - d = parse_book(book, page=int(page_number), html=True) - if d[0]: - words, coords = zip(*d[0]) - return (list(enumerate(coords)), list(enumerate(words))) + doc = du.get_document("../" + book) + page = doc.pages[int(page_number)-1] + d = du.parse_page(page) + 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))) if __name__ == "__main__": gen_html(*sys.argv[1:3]) -- cgit v1.2.3-70-g09d2