X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=segment.py;h=712895b6b0d7f1563ee4149fe7d94445a3931233;hb=e6332a16567643e66c2a491b94994f9482384d34;hp=08bc0aa84244bf222655defba7b4a0773f87ebcf;hpb=a5bada5fbdbfa67a1f4c301c5e14897c268bc0a5;p=cipher-tools.git diff --git a/segment.py b/segment.py index 08bc0aa..712895b 100644 --- a/segment.py +++ b/segment.py @@ -4,19 +4,10 @@ import collections from math import log10 import itertools import sys +from functools import lru_cache sys.setrecursionlimit(1000000) -def memo(f): - "Memoize function f." - table = {} - def fmemo(*args): - if args not in table: - table[args] = f(*args) - return table[args] - fmemo.memo = table - return fmemo - -@memo +@lru_cache() def segment(text): """Return a list of words that is the best segmentation of text. """