1af1b62fc8eb3270c35c4bb39a773804faf8da47
3 from functools
import lru_cache
4 sys
.setrecursionlimit(1000000)
8 """Return a list of words that is the best segmentation of text.
10 if not text
: return []
11 candidates
= ([first
]+segment(rest
) for first
,rest
in splits(text
))
12 return max(candidates
, key
=language_models
.Pwords
)
15 def segment_wrong(text
):
16 """Return a list of words that is the best segmentation of text.
18 if not text
: return []
19 candidates
= ([first
]+segment(rest
) for first
,rest
in splits(text
))
20 return max(candidates
, key
=language_models
.Pwords_wrong
)
23 def splits(text
, L
=20):
24 """Return a list of all possible (first, rest) pairs, len(first)<=L.
26 return [(text
[:i
+1], text
[i
+1:])
27 for i
in range(min(len(text
), L
))]