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. --- string_utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'string_utils.py') 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 -- cgit v1.2.3-70-g09d2 From 070c4f8f2a74cb677808c203890a584c1dd6c88f Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 1 Aug 2014 14:37:50 -0400 Subject: add function to inverse alignment --- string_utils.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'string_utils.py') diff --git a/string_utils.py b/string_utils.py index 7120219..fb3fe50 100644 --- a/string_utils.py +++ b/string_utils.py @@ -156,6 +156,13 @@ def print_alignment(l1, l2, c2, alignment): for word in l2: print u"{0:>25} | {1}".format("", word) +def invert_align(alignment, n): + l = [[]] *n + for i, e in enumerate(alignment): + for a in e: + l[a].append(i) + + def alignment_to_coord(l1, alignment): # l1 list of corrected words # alignment list of size len(l1) qui mappe mots dans l2 @@ -165,13 +172,15 @@ def alignment_to_coord(l1, alignment): 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, 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, begin]) - else: - r.append([word, begin]) + r.append([word, index]) + # if not index: + # 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, begin]) + # else: + # r.append([word, begin]) return r -- cgit v1.2.3-70-g09d2 From 102a573a7e6fd711da874c76f74b47df37ff124e Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 3 Aug 2014 19:16:03 -0400 Subject: fix invert_align --- string_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'string_utils.py') diff --git a/string_utils.py b/string_utils.py index fb3fe50..0588418 100644 --- a/string_utils.py +++ b/string_utils.py @@ -157,11 +157,11 @@ def print_alignment(l1, l2, c2, alignment): print u"{0:>25} | {1}".format("", word) def invert_align(alignment, n): - l = [[]] *n + l = [[] for _ in range(n)] for i, e in enumerate(alignment): for a in e: l[a].append(i) - + return l def alignment_to_coord(l1, alignment): # l1 list of corrected words -- cgit v1.2.3-70-g09d2