Browse Source

feat: warning punctuations check

master
Dnomd343 2 years ago
parent
commit
a7416989e9
  1. 34
      src/punctuation/check.py

34
src/punctuation/check.py

@ -21,6 +21,14 @@ endingPunctuations = [
'', # special: letter beginning '', # special: letter beginning
] ]
# '…',
# '—',
warningPunctuations = [
# ' ',
'-', '·', '.', '',
]
defaultPath = os.path.join( defaultPath = os.path.join(
os.path.dirname(os.path.realpath(__file__)), '../../release/' os.path.dirname(os.path.realpath(__file__)), '../../release/'
) )
@ -39,6 +47,10 @@ def loadContent(filename: str) -> list: # load json content
return combine return combine
def isCaption(content: str) -> bool:
return re.search(r'^第\d+章 \S*$', content) is not None
def pairsCheck(sentence: str) -> bool: def pairsCheck(sentence: str) -> bool:
errorFlag = False errorFlag = False
punctuationStack = [] punctuationStack = []
@ -70,15 +82,26 @@ def pairsCheck(sentence: str) -> bool:
def endingCheck(sentence: str) -> bool: def endingCheck(sentence: str) -> bool:
if re.search(r'^第\d+章 \S*$', sentence) is not None: # skip caption if isCaption(sentence): # skip caption
return True return True
for endingPunctuation in endingPunctuations: for endingPunctuation in endingPunctuations:
if sentence.endswith(endingPunctuation): # match ending punctuation if sentence.endswith(endingPunctuation): # match ending punctuation
return True return True
print('%s\033[0;31m_\033[0;39m' % sentence) print('%s\n%s\033[0;31m_\033[0;39m' % ('-' * 128, sentence))
return False return False
def existCheck(sentence: str) -> bool:
flag = False
for warningPunctuation in warningPunctuations:
if warningPunctuation in sentence:
flag = True
sentence = sentence.replace(warningPunctuation, '\033[0;31m%s\033[0;39m' % warningPunctuation)
if flag:
print('%s\n%s' % ('-' * 128, sentence))
return not flag
def contentCheck(content: list) -> None: def contentCheck(content: list) -> None:
flag = True flag = True
for row in content: # pairs check for row in content: # pairs check
@ -92,7 +115,12 @@ def contentCheck(content: list) -> None:
if not flag: if not flag:
print('-' * 128) # split line print('-' * 128) # split line
# other check process flag = True
for row in content: # ending check
flag &= existCheck(row)
if not flag:
print('-' * 128) # split line
contentCheck(loadContent(sys.argv[1])) contentCheck(loadContent(sys.argv[1]))

Loading…
Cancel
Save