mirror of
https://github.com/jfilter/clean-text.git
synced 2021-09-19 22:32:58 +03:00
Fix accidental removal of accents (close #17)
This commit is contained in:
@@ -54,9 +54,9 @@ def fix_bad_unicode(text, normalization="NFC"):
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
# fix if the unicode is fucked up
|
||||
# trying to fix backslash-replaced strings (via https://stackoverflow.com/a/57192592/4028896)
|
||||
try:
|
||||
text = text.encode().decode("unicode-escape")
|
||||
text = text.encode("latin", "backslashreplace").decode("unicode-escape")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import pytest
|
||||
|
||||
import cleantext
|
||||
|
||||
|
||||
@@ -139,6 +137,9 @@ def test_fix_bad_unicode():
|
||||
text = "and install a \\u2018new\\u2019 society in their" # and install a ‘new’ society in their
|
||||
assert cleantext.fix_bad_unicode(text) == "and install a 'new' society in their"
|
||||
|
||||
assert "všetko" == cleantext.fix_bad_unicode("všetko")
|
||||
assert "Všetko" == cleantext.fix_bad_unicode("Všetko")
|
||||
|
||||
|
||||
def test_zero_digits():
|
||||
text = "in the 1970s there was 12.3 and 111 11 33 $23 03 wins"
|
||||
@@ -252,9 +253,10 @@ Johannes dfdfd"""
|
||||
keep_two_line_breaks=True,
|
||||
)
|
||||
|
||||
|
||||
def test_remove_trail_leading_whitespace():
|
||||
text_input = b'Sehr geehrte Damen und Herren,\\r\\n\\r\\nich m\\xf6chte Sie bitten, zu folgendem Fall Stellung zu nehmen. Ich habe einen Fotoautomaten f\\xfcr biometrische Passfotos benutzt, der mein Gesicht nicht erkannt hat. Es besteht die Vermutung, dass dieser Fotoautomat vom BSI zertifiziert ist (Zertifikat BSI-DSZ-CC-0985-2018).\\r\\n\\r\\nDer Fotoautomat steht in .\\r\\n\\r\\n\\r\\n\\t\\r\\n\\t\\tOrt des Automats: \\r\\n\\t\\r\\n\\r\\n\\r\\n\\r\\n \\r\\n\\t\\r\\n\\t\\tMarke: \\r\\n\\t\\r\\n\\r\\n\\r\\n\\r\\n\\r\\nHier noch Text von Anna Lena.\\r\\n\\r\\nMit freundlichen Gr\\xfc\\xdfen'
|
||||
text_input = text_input.decode('unicode_escape')
|
||||
text_input = b"Sehr geehrte Damen und Herren,\\r\\n\\r\\nich m\\xf6chte Sie bitten, zu folgendem Fall Stellung zu nehmen. Ich habe einen Fotoautomaten f\\xfcr biometrische Passfotos benutzt, der mein Gesicht nicht erkannt hat. Es besteht die Vermutung, dass dieser Fotoautomat vom BSI zertifiziert ist (Zertifikat BSI-DSZ-CC-0985-2018).\\r\\n\\r\\nDer Fotoautomat steht in .\\r\\n\\r\\n\\r\\n\\t\\r\\n\\t\\tOrt des Automats: \\r\\n\\t\\r\\n\\r\\n\\r\\n\\r\\n \\r\\n\\t\\r\\n\\t\\tMarke: \\r\\n\\t\\r\\n\\r\\n\\r\\n\\r\\n\\r\\nHier noch Text von Anna Lena.\\r\\n\\r\\nMit freundlichen Gr\\xfc\\xdfen"
|
||||
text_input = text_input.decode("unicode_escape")
|
||||
text_output = """Sehr geehrte Damen und Herren,
|
||||
|
||||
ich möchte Sie bitten, zu folgendem Fall Stellung zu nehmen. Ich habe einen Fotoautomaten für biometrische Passfotos benutzt, der mein Gesicht nicht erkannt hat. Es besteht die Vermutung, dass dieser Fotoautomat vom BSI zertifiziert ist (Zertifikat BSI-DSZ-CC-0985-2018).
|
||||
|
||||
Reference in New Issue
Block a user