-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_score.py
45 lines (31 loc) · 927 Bytes
/
compute_score.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
import collections
import numpy as np
import re
import io
path = "samples.txt"
def tokenize_string(sample):
return tuple(sample.lower().split(' '))
def load_dataset(path, max_length=10, tokenize=False, max_vocab_size=2048):
lines = {}
with io.open(path, 'r', encoding="ISO-8859-1") as f:
i = 0
for line in f:
line = line[:-1]
# right pad with ` character
if line not in lines:
lines[line] = i
i+=1
return lines
num_dict = load_dataset(path)
score_dict = {}
with io.open("rockyou.txt", 'r', encoding="ISO-8859-1") as f:
for line in f:
line = line[:-1]
if line in num_dict:
num = num_dict[line]
score_dict[line] = num
import json
json = json.dumps(score_dict)
f = open("results.json","w")
f.write(json)
f.close()