source: trunk/symbol_table/demo_strms.py @ 2103

Last change on this file since 2103 was 2103, checked in by ksherdy, 7 years ago

Updated symbol table to represent group 0 as the arbitrary length group.

File size: 4.4 KB
Line 
1from bitutil import *
2import marker_strms
3import div2_group_strms
4import logbase2_group_strms
5import div2_logbase2_group_strms
6import sys
7
8class Basis_bits():
9        bit_0 = 0
10        bit_1 = 0
11        bit_2 = 0
12        bit_3 = 0
13        bit_4 = 0
14        bit_5 = 0
15        bit_6 = 0
16        bit_7 = 0
17
18def Demo_div2(u8data, basis_bits):
19
20    lgth = len(u8data)
21
22    markers = marker_strms.Markers()
23    marker_strms.Classify_markers(basis_bits, markers)
24    marker_strms.Generate_markers(markers)
25
26    groups = div2_group_strms.Groups()
27    groups.starts = markers.starts
28    groups.follows = markers.follows
29    div2_group_strms.Gen_lgth_groups(groups)
30
31    print_aligned_streams([('Input Data', u8data),
32        ('markers.spans', bitstream2string(markers.spans, lgth)),
33        ('markers.starts', bitstream2string(markers.starts, lgth)),
34        ('markers.follows', bitstream2string(markers.follows, lgth)),
35        ('groups.starts', bitstream2string(groups.starts, lgth)),
36        ('groups.follows', bitstream2string(groups.follows, lgth)),
37        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
38        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
39        ('groups.follows_6', bitstream2string(groups.follows_6, lgth)),
40        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
41        ('groups.follows_10', bitstream2string(groups.follows_10, lgth)),
42        ('groups.follows_12', bitstream2string(groups.follows_12, lgth)),
43        ('groups.follows_14', bitstream2string(groups.follows_14, lgth)),
44        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
45        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
46
47def Demo_logbase2(u8data, basis_bits):
48
49    lgth = len(u8data)
50
51    markers = marker_strms.Markers()
52    marker_strms.Classify_markers(basis_bits, markers)
53    marker_strms.Generate_markers(markers)
54
55    groups = logbase2_group_strms.Groups()
56    groups.starts = markers.starts
57    groups.follows = markers.follows
58    logbase2_group_strms.Gen_lgth_groups(groups)
59
60    print_aligned_streams([('Input Data', u8data),
61        ('markers.spans', bitstream2string(markers.spans, lgth)),
62        ('markers.starts', bitstream2string(markers.starts, lgth)),
63        ('markers.follows', bitstream2string(markers.follows, lgth)),
64        ('groups.starts', bitstream2string(groups.starts, lgth)),
65        ('groups.follows', bitstream2string(groups.follows, lgth)),
66        ('groups.follows_1', bitstream2string(groups.follows_1, lgth)),
67        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
68        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
69        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
70        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
71        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
72
73def Demo_div2_logbase2(u8data, basis_bits):
74
75    lgth = len(u8data)
76
77    markers = marker_strms.Markers()
78    marker_strms.Classify_markers(basis_bits, markers)
79    marker_strms.Generate_markers(markers)
80
81    groups = div2_logbase2_group_strms.Groups()
82    groups.starts = markers.starts
83    groups.follows = markers.follows
84    div2_logbase2_group_strms.Gen_lgth_groups(groups)
85
86    print_aligned_streams([('Input Data', u8data),
87        ('markers.spans', bitstream2string(markers.spans, lgth)),
88        ('markers.starts', bitstream2string(markers.starts, lgth)),
89        ('markers.follows', bitstream2string(markers.follows, lgth)),
90        ('groups.starts', bitstream2string(groups.starts, lgth)),
91        ('groups.follows', bitstream2string(groups.follows, lgth)),
92        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
93        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
94        ('groups.follows_6', bitstream2string(groups.follows_6, lgth)),
95        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
96        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
97        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
98
99if __name__ == "__main__":
100
101    if len(sys.argv) < 2:
102        sys.stderr.write("Usage: python " + filename + " <filename>\n")
103        sys.exit(2)
104
105    u8data = readfile(sys.argv[1])
106
107    basis_bits = Basis_bits()
108    (b, EOF_mask) = transpose_streams(u8data)
109
110    basis_bits.bit_0 = b[0]
111    basis_bits.bit_1 = b[1]
112    basis_bits.bit_2 = b[2]
113    basis_bits.bit_3 = b[3]
114    basis_bits.bit_4 = b[4]
115    basis_bits.bit_5 = b[5]
116    basis_bits.bit_6 = b[6]
117    basis_bits.bit_7 = b[7]
118
119    # Demo_div2(u8data, basis_bits)
120    # Demo_logbase2(u8data, basis_bits)
121    Demo_div2_logbase2(u8data, basis_bits)
122
Note: See TracBrowser for help on using the repository browser.