aboutsummaryrefslogtreecommitdiffstats
path: root/string_utils.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2013-08-18 16:54:53 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2013-08-18 16:54:53 -0400
commit17c23c5d2b6680f90117a7804e65dd7fe541848f (patch)
tree767a541bde7c7d2f5141994fa503b2f1f4425dc1 /string_utils.py
parent4e99558cb00144d045fe1fc00793b4b16f0e6fab (diff)
downloadocr-layer-curation-17c23c5d2b6680f90117a7804e65dd7fe541848f.tar.gz
try to fix the alignment_to_sexp function
Diffstat (limited to 'string_utils.py')
-rw-r--r--string_utils.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/string_utils.py b/string_utils.py
index c4439da..12d22b8 100644
--- a/string_utils.py
+++ b/string_utils.py
@@ -172,9 +172,14 @@ def alignment_to_sexp(alignment, sexp, l2):
if index == -1:
break
else:
- re.sub("(?P<begin>\d+ \d+ \d+ \d+\s) \w+(?P<end>\)+$)",
- "\g<begin>{0}\g<end>".format(
- " ".join([l2[i] for i in list(index)])),
- line)
- line.encode('string-escape')
+ if type(index) == tuple:
+ word = " ".join([l2[i] for i in list(index)])
+ else:
+ try:
+ word = l2[index]
+ except IndexError:
+ print index
+ word = word.encode("utf-8").encode("string-escape")
+ re.sub("(?P<begin>\d+ \d+ \d+ \d+\s) \w+(?P<end>\)+$)",
+ "\g<begin>{0}\g<end>".format(word), line)
print line