Skip to content

Commit 1e09901

Browse files
committed
Fixed a bug with one letter sentence.
1 parent 0200ff0 commit 1e09901

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

arabic_reshaper.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
[u'\u066E', u'\uFBE4', u'\uFBE8', u'\uFBE9', u'\uFBE5', 4],
126126
[u'\u06AA', u'\uFB8E', u'\uFB90', u'\uFB91', u'\uFB8F', 4],
127127
[u'\u06C1', u'\uFBA6', u'\uFBA8', u'\uFBA9', u'\uFBA7', 4],
128-
[u'\u06E4', u'\u06E4', u'\u06E4', u'\u06E4', u'\uFEEE', 2]
129128
]
130129

131130
def get_reshaped_glyph(target, location):
@@ -223,18 +222,29 @@ def get_reshaped_word(unshaped_word):
223222
return decomposed_word.reconstruct_word(result)
224223

225224
def reshape_it(unshaped_word):
226-
reshaped_word = [get_reshaped_glyph(unshaped_word[0], 2)]
227-
for i in range(1, len(unshaped_word) - 1):
228-
if get_glyph_type(unshaped_word[i - 1]) == 2:
229-
reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 2))
225+
if not unshaped_word:
226+
return u''
227+
if len(unshaped_word) == 1:
228+
return get_reshaped_glyph(unshaped_word[0], 1)
229+
reshaped_word = []
230+
for i in range(len(unshaped_word)):
231+
before = False
232+
after = False
233+
if i == 0:
234+
after = get_glyph_type(unshaped_word[i]) == 4
235+
elif i == len(unshaped_word) - 1:
236+
before = get_glyph_type(unshaped_word[i - 1]) == 4
230237
else:
238+
after = get_glyph_type(unshaped_word[i]) == 4
239+
before = get_glyph_type(unshaped_word[i - 1]) == 4
240+
if after and before:
231241
reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 3))
232-
233-
if len(unshaped_word) >= 2:
234-
if get_glyph_type(unshaped_word[-2]) == 2:
235-
reshaped_word.append(get_reshaped_glyph(unshaped_word[-1], 1))
236-
else:
237-
reshaped_word.append(get_reshaped_glyph(unshaped_word[-1], 4))
242+
elif after and not before:
243+
reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 2))
244+
elif not after and before:
245+
reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 4))
246+
elif not after and not before:
247+
reshaped_word.append(get_reshaped_glyph(unshaped_word[i], 1))
238248

239249
return u''.join(reshaped_word)
240250

0 commit comments

Comments
 (0)