-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
45 lines (36 loc) · 1.12 KB
/
demo.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
from os import listdir
from os.path import isfile, join
from fp import fp
import pickle
def test():
f = fp()
with open('sample.txt', 'r', encoding='utf-8') as file:
text = file.read()
f.processDoc(text)
print('length %d density %5.4f bits set %d' %
(f.length, f.density(), f.countbits()) )
g = fp()
g.processDoc(text)
for i in range(20):
g.fp_add( 'a'*i)
print('length %d density %5.4f bits set %d' %
(g.length, g.density(), g.countbits()) )
print('tanimoto %5.4f' % (f.tanimoto(g) ))
def test2():
mypath='.'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
fprints = []
count = 0
for fe in onlyfiles:
if not fe.endswith('txt'):
continue
with open(fe, mode='r', encoding='utf-8', errors='ignore') as f:
count += 1
text = f.read()
fprint = fp()
fprint.processDoc(text)
fprints.append((fe, fprint))
print(count, f.name, 'density', fprint.density())
pickle.dump(fprints, open('pickles.pik', 'wb'))
print('end')
test2()