Skip to content

Commit

Permalink
#34 fixs bug with shey punctuation །
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey committed Oct 5, 2020
1 parent becc6ae commit 022672d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion managers/TokenManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from horology import timed
from diff_match_patch import diff
from click.core import fast_exit

class TokenList(list):
def __getitem__(self, key):
Expand Down Expand Up @@ -264,6 +265,8 @@ def diff(self, tokens, oldText, newText):
oldString = ''
newString = ''
sameStringLength = 0
isDeleteShey = False
i = 0
for op, string in changes:
if op == "-" or op == "+":
if not sameStringLength:
Expand Down Expand Up @@ -295,7 +298,7 @@ def diff(self, tokens, oldText, newText):
start = -1

changePos = len(oldString)
# 當是加入 ། 時,換得+1,讓後面找 endNew 時不會用到現在加的
# 當是加入 ། 時,換的位置+1,讓後面找 endNew 時不會用到現在加的
if string == '།':
changePos += 1
else:
Expand All @@ -311,6 +314,10 @@ def diff(self, tokens, oldText, newText):

# op == "-" 時才找得到
changePos = oldString.find(string, sameStringLength - 1)
# 當是刪除 ། 時,且所在位置前一個非 ། 無,換的位置-1,讓後面找 endOld 時不會用到現在的
if string == '།' and changes[i-1][1][-1] != '།':
isDeleteShey = True


if start == -1: # 改的地方前面沒有'།'或'\n'
start = 0
Expand All @@ -319,6 +326,8 @@ def diff(self, tokens, oldText, newText):
oldString = oldString + string
newString = newString + string

i += 1

# 往後 scan ,結束位置
endOld = oldString.find('།', changePos)
endNew = newString.find('།', changePos)
Expand All @@ -328,6 +337,9 @@ def diff(self, tokens, oldText, newText):
#當 ། 有很多個同時在一起時
if endOld == endNew:
endOld += 1
if isDeleteShey:
endOld = endNew + 1

# 在文章最後面加字
if (tokens[-1].end == changePos) or (changePos == -1):
if (tokens[-1].end == changePos):
Expand Down

0 comments on commit 022672d

Please sign in to comment.