From bc3a00c11397840b52ddb2e032fac885b29b8601 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 15 Dec 2022 19:35:32 +0800 Subject: [PATCH] feat: double punctuation check --- src/punctuation/check.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/punctuation/check.py b/src/punctuation/check.py index 5627c96..c98abf1 100755 --- a/src/punctuation/check.py +++ b/src/punctuation/check.py @@ -21,9 +21,6 @@ endingPunctuations = [ ':', # special: letter beginning ] -# '…', -# '—', - warningPunctuations = [ ' ', '-', '·', '.', ';', ] @@ -90,6 +87,32 @@ def endingCheck(sentence: str) -> bool: return False +def doubleCheck(sentence: str) -> bool: + + def groupCombine(content: str) -> list: # combine same character + group = '' + result = [] + for c in content: + if c in group: + group += c + continue + if len(group) != 0: + result.append(group) + group = c + result.append(group) + return result + + flag = False + sentence = groupCombine(sentence) + for (p, i) in product(['…', '—'], range(0, len(sentence))): + if p in sentence[i] and len(sentence[i]) != 2: + flag = True + sentence[i] = '\033[0;31m%s\033[0;39m' % sentence[i] + if flag: + print('%s\n%s' % ('-' * 128, ''.join(sentence))) + return not flag + + def existCheck(sentence: str) -> bool: if isCaption(sentence): # skip caption return True @@ -114,6 +137,7 @@ def contentCheck(content: list) -> None: runCheck(pairsCheck) runCheck(endingCheck) + runCheck(doubleCheck) runCheck(existCheck)