-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassify.py
More file actions
29 lines (24 loc) · 807 Bytes
/
classify.py
File metadata and controls
29 lines (24 loc) · 807 Bytes
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
import argparse, sys
from test import eval_list
from itertools import islice
from pprint import pprint
def split_every(n, iterable):
i = iter(iterable)
piece = list(islice(i, n))
while piece:
yield piece
piece = list(islice(i, n))
def options():
parser = argparse.ArgumentParser(description='Classifies strings '
'as random/non-random.')
parser.add_argument('strings',
nargs='?',
type=argparse.FileType('r'),
default=sys.stdin)
return parser.parse_args()
if __name__ == '__main__':
opts = options()
strings = opts.strings
for batch in split_every(1000, (s.rstrip() for s in strings)):
for string, label in eval_list(batch, ignore_invalid=True, warnings=True):
print("{}\t{}".format(string, label))