Started 2015 challenges
[cipher-training.git] / language_models.py
index 62219efe54ab2ad20e07c1838d5ade29e6511d7d..f1877b70d8169ee12372cf028e284f4d14f6183b 100644 (file)
@@ -10,6 +10,8 @@ import unicodedata
 import itertools
 from math import log10
 
+unaccent_specials = ''.maketrans({"’": "'"})
+
 def letters(text):
     """Remove all non-alphabetic characters from a text
     >>> letters('The Quick')
@@ -35,7 +37,8 @@ def unaccent(text):
     >>> unaccent('HÉLLÖ')
     'HELLO'
     """
-    return unicodedata.normalize('NFKD', text).\
+    translated_text = text.translate(unaccent_specials)
+    return unicodedata.normalize('NFKD', translated_text).\
         encode('ascii', 'ignore').\
         decode('utf-8')