commit 484c48a9b590a86af96c1c7d32d17ba4159c6a44
parent d7c04b0f6cbf165720881422f20cadc60eabe641
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sun, 27 Jul 2014 14:06:25 +0200
fix crash on "quinqu-"
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/verse.py b/verse.py
@@ -145,9 +145,6 @@ class Verse:
if w[i]['text'].endswith('g') and len(w[i+1]['text']) >= 2:
if w[i+1]['text'][1] in "eéèa":
w[i+1]['text'] = w[i+1]['text'][1:]
- # remove empty chunks created by simplifications
- for i, w in enumerate(self.chunks):
- self.chunks[i] = [x for x in w if len(x['text']) > 0]
# remove leading and trailing crap
for w in self.chunks:
@@ -157,6 +154,18 @@ class Verse:
while len(w[p]['text']) > 0 and w[p]['text'][-1] in ' -':
w[p]['text'] = w[p]['text'][:-1]
+ # collapse empty chunks created by simplifications
+ for i, w in enumerate(self.chunks):
+ new_chunks = []
+ for x in self.chunks[i]:
+ if len(x['text']) > 0:
+ new_chunks.append(x)
+ else:
+ # propagate the original text
+ # newly empty chunks cannot be the first ones
+ new_chunks[-1]['original'] += x['original']
+ self.chunks[i] = new_chunks
+
# sigles
for i, w in enumerate(self.chunks):
if len(w) == 1 and is_consonants(w[0]['text']):