33
44from bisect import bisect_right
55from dataclasses import dataclass
6- from itertools import accumulate , chain , combinations , repeat
6+ from itertools import accumulate , chain , combinations , repeat , starmap
77from re import escape
88from string import ascii_letters , ascii_lowercase
99
@@ -23,19 +23,23 @@ class _TermStrategies:
2323 term_pairs : st .SearchStrategy [list [tuple [str , str ]]]
2424
2525
26+ def _not_substring (a : str , b : str ) -> bool :
27+ a , b = a .lower (), b .lower ()
28+ return a not in b and b not in a
29+
30+
2631def _build_term_strategies (
2732 alphabet : str ,
2833) -> _TermStrategies :
2934 item : st .SearchStrategy [str ] = st .text (min_size = 1 , alphabet = alphabet )
3035 pair : st .SearchStrategy [tuple [str , str ]] = st .tuples (item , item ).filter (
31- lambda x : x [ 0 ] not in x [ 1 ] and x [ 1 ] not in x [ 0 ]
36+ lambda x : _not_substring ( * x )
3237 )
3338 pairs : st .SearchStrategy [list [tuple [str , str ]]] = st .lists (
3439 pair , min_size = 1 , max_size = BATCH_COUNT
3540 ).filter (
36- lambda x : all (
37- item [0 ] not in item [1 ] and item [1 ] not in item [0 ]
38- for item in combinations (chain (* x ), 2 )
41+ lambda xs : all (
42+ starmap (_not_substring , combinations (chain (* xs ), 2 ))
3943 )
4044 )
4145
0 commit comments