Uninvert text prior to filtering

merge-requests/30/head
Bob Mottram 2024-02-02 13:03:50 +00:00
parent 1520c390c4
commit ec8d608f13
2 changed files with 27 additions and 9 deletions

View File

@ -8585,8 +8585,8 @@ def _test_book_link(base_dir: str):
shutil.rmtree(base_dir, ignore_errors=False, onerror=None)
def _test_uninvert():
print('uninvert')
def _test_uninvert2():
print('uninvert2')
inverted_text = 'abcdefghijklmnopqrstuvwxyz'
uninverted_text = uninvert_text(inverted_text)
if uninverted_text != inverted_text:
@ -8601,12 +8601,12 @@ def _test_uninvert():
print('uninverted: ' + uninverted_text)
assert uninverted_text == inverted_text
inverted_text = 'ʍǝɹpuɐ'
inverted_text = '[ʍǝɹpuɐ]'
uninverted_text = uninvert_text(inverted_text)
if uninverted_text != 'andrew':
if uninverted_text != '[andrew]':
print('inverted: ' + inverted_text)
print('uninverted: ' + uninverted_text)
assert uninverted_text == 'andrew'
assert uninverted_text == '[andrew]'
inverted_text = '˙ʇsǝʇ ɐ sı sıɥ⊥'
uninverted_text = uninvert_text(inverted_text)
@ -8633,7 +8633,7 @@ def run_all_tests():
_test_checkbox_names()
_test_thread_functions()
_test_functions()
_test_uninvert()
_test_uninvert2()
_test_book_link(base_dir)
_test_dateformat()
_test_is_right_to_left()

View File

@ -189,7 +189,6 @@ def uninvert_text(text: str) -> str:
'\u0055': '\u2229',
'\u0056': '\u1D27',
'\u0059': '\u2144',
'\u005B': '\u005D',
'\u005F': '\u203E',
'\u0061': '\u0250',
'\u0062': '\u0071',
@ -226,8 +225,25 @@ def uninvert_text(text: str) -> str:
possible_result = ch_result + possible_result
result = text
if matches > len(text)/2:
result = possible_result
if matches > len(text)/3:
result = possible_result.replace('9', '6')
new_result = ''
extra_replace = {
'[': ']',
']': '[',
'(': ')',
')': '(',
'<': '>',
'>': '<'
}
for ch1 in result:
ch_result = ch1
for ch2, rep in extra_replace.items():
if ch1 == ch2:
ch_result = rep
break
new_result += ch_result
result = new_result
return result
@ -4527,6 +4543,8 @@ def remove_inverted_text(text: str, system_language: str) -> str:
if system_language != 'en':
return text
text = uninvert_text(text)
inverted_lower = [*"_ʎ_ʍʌ_ʇ_ɹ____ɯʃʞɾıɥƃɟǝ_ɔ_ɐ"]
inverted_upper = [*"_⅄__ᴧ∩⊥_ᴚΌԀ_ᴎ_⅂⋊ſ__⅁ℲƎ◖Ↄ𐐒∀"]