-
Notifications
You must be signed in to change notification settings - Fork 13
/
_prepare_dev_data.py
executable file
·77 lines (61 loc) · 2.35 KB
/
_prepare_dev_data.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Script for building test DAWGs.
"""
from __future__ import absolute_import, unicode_literals
import dawg
import os
import sys
import struct
sys.path.insert(0, os.path.dirname(__file__))
from bench.utils import words100k
from tests.test_prediction import TestPrediction
def create_dawg():
words = words100k()
return dawg.DAWG(words)
def create_bytes_dawg():
words = words100k()
values = [struct.pack(str('<H'), len(word)) for word in words]
return dawg.BytesDAWG(zip(words, values))
def create_record_dawg():
words = words100k()
values = [ [len(word)] for word in words]
return dawg.RecordDAWG(str('<H'), zip(words, values))
def create_int_dawg():
words = words100k()
values = [len(word) for word in words]
return dawg.IntDAWG(zip(words, values))
def create_int_completion_dawg():
words = words100k()
values = [len(word) for word in words]
return dawg.IntCompletionDAWG(zip(words, values))
def build_test_data():
dawg.CompletionDAWG(['f', 'bar', 'foo', 'foobar']).save('dev_data/small/completion.dawg')
dawg.CompletionDAWG([]).save('dev_data/small/completion-empty.dawg')
bytes_data = (
('foo', b'data1'),
('bar', b'data2'),
('foo', b'data3'),
('foobar', b'data4')
)
dawg.BytesDAWG(bytes_data).save('dev_data/small/bytes.dawg')
record_data = (
('foo', (3, 2, 256)),
('bar', (3, 1, 0)),
('foo', (3, 2, 1)),
('foobar', (6, 3, 0))
)
dawg.RecordDAWG(str(">3H"), record_data).save('dev_data/small/record.dawg')
int_data = {'foo': 1, 'bar': 5, 'foobar': 3}
dawg.IntDAWG(int_data).save('dev_data/small/int_dawg.dawg')
dawg.IntCompletionDAWG(int_data).save('dev_data/small/int_completion_dawg.dawg')
dawg.DAWG(TestPrediction.DATA).save('dev_data/small/prediction.dawg')
dawg.RecordDAWG(str("=H"), [(k, (len(k),)) for k in TestPrediction.DATA]).save('dev_data/small/prediction-record.dawg')
create_dawg().save('dev_data/large/dawg.dawg')
create_bytes_dawg().save('dev_data/large/bytes_dawg.dawg')
create_record_dawg().save('dev_data/large/record_dawg.dawg')
create_int_dawg().save('dev_data/large/int_dawg.dawg')
#create_int_completion_dawg().save('dev_data/large/int_completion_dawg.dawg')
if __name__ == '__main__':
build_test_data()