Included Python 3.4's Enum for keyword alphabets, added Pwords_wrong and friends...
[cipher-training.git] / segment.py
index ba3ddd7405a91a40c025fcd34b5eadfa7f8d0b11..1af1b62fc8eb3270c35c4bb39a773804faf8da47 100644 (file)
@@ -11,6 +11,15 @@ def segment(text):
     candidates = ([first]+segment(rest) for first,rest in splits(text))
     return max(candidates, key=language_models.Pwords)
 
+@lru_cache()
+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))
+    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.
     """