Removed cipher challenge files
[cipher-training.git] / segment.py
index 1af1b62fc8eb3270c35c4bb39a773804faf8da47..a64ea5d4eb4248edaaff12c791df088f8109e21c 100644 (file)
@@ -1,3 +1,5 @@
+"""Segment a collection of letters into words"""
+
 import language_models
 import sys
 from functools import lru_cache
@@ -8,7 +10,7 @@ def segment(text):
     """Return a list of words that is the best segmentation of text.
     """
     if not text: return []
-    candidates = ([first]+segment(rest) for first,rest in splits(text))
+    candidates = ([first]+segment(rest) for first, rest in splits(text))
     return max(candidates, key=language_models.Pwords)
 
 @lru_cache()
@@ -16,13 +18,13 @@ def segment_wrong(text):
     """Return a list of words that is the best segmentation of text.
     """
     if not text: return []
-    candidates = ([first]+segment(rest) for first,rest in splits(text))
+    candidates = ([first]+segment(rest) for first, rest in splits(text))
     return max(candidates, key=language_models.Pwords_wrong)
 
 
 def splits(text, L=20):
     """Return a list of all possible (first, rest) pairs, len(first)<=L.
     """
-    return [(text[:i+1], text[i+1:]) 
+    return [(text[:i+1], text[i+1:])
             for i in range(min(len(text), L))]