projects
/
cipher-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Done challenge 5
[cipher-tools.git]
/
language_models.py
diff --git
a/language_models.py
b/language_models.py
index 1b90ac2ca425c1a246b410ac2f7a588931105f00..19f886fcefcb4384184e0bbad108e6925f029bbf 100644
(file)
--- a/
language_models.py
+++ b/
language_models.py
@@
-6,6
+6,8
@@
import unicodedata
import itertools
from math import log10
import itertools
from math import log10
+unaccent_specials = ''.maketrans({"’": "'"})
+
def letters(text):
"""Remove all non-alphabetic characters from a text
>>> letters('The Quick')
def letters(text):
"""Remove all non-alphabetic characters from a text
>>> letters('The Quick')
@@
-31,7
+33,8
@@
def unaccent(text):
>>> unaccent('HÉLLÖ')
'HELLO'
"""
>>> 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')
encode('ascii', 'ignore').\
decode('utf-8')
@@
-121,7
+124,7
@@
def log_probability_of_unknown_word(key, N):
Pw = Pdist(datafile('count_1w.txt'), log_probability_of_unknown_word)
Pl = Pdist(datafile('count_1l.txt'), lambda _k, _N: 0)
Pw = Pdist(datafile('count_1w.txt'), log_probability_of_unknown_word)
Pl = Pdist(datafile('count_1l.txt'), lambda _k, _N: 0)
-P
l2
= Pdist(datafile('count_2l.txt'), lambda _k, _N: 0)
+P
2l
= Pdist(datafile('count_2l.txt'), lambda _k, _N: 0)
def Pwords(words):
"""The Naive Bayes log probability of a sequence of words.
def Pwords(words):
"""The Naive Bayes log probability of a sequence of words.