-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mclp.py
executable file
·45 lines (35 loc) · 960 Bytes
/
test_mclp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import os, sys, re
import operator
import argparse
import hashlib
import operator
cand = [
'foobar',
'long_prefix_with_stuff here',
'long_prefix_with_stuff here 1',
'long_prefix_with_stuff here 2',
'long_prefix_with_stuff here 3',
'zeds dead baby',
]
def most_common_long_prefix(fns):
if len(fns) == 1:
return fns[0]
prefixes = {}
for fn in fns:
prefix = None
for t in fn.split():
new_prefix = ' '.join([prefix, t]) if prefix else t
if new_prefix in prefixes:
prefixes[new_prefix] += 1
else:
prefixes[new_prefix] = 1
prefix = new_prefix
mclp = [ key for key in prefixes.keys() if prefixes[key] == max(prefixes.values()) ]
mclp.sort(key=len, reverse=True)
return mclp[0]
print("candidates:")
for x in cand:
print(x)
print('=============')
print(most_common_long_prefix(cand))