6 lm = sphinxbase.NGramModel("../test/unit/test_ngram/100.arpa.DMP")
7 for ng in lm.mgrams(0):
8 print ng.log_prob, ng.log_bowt
9 lm.write("100.arpa.DMP")
10 lm.casefold(sphinxbase.UPPER)
13 hc = sphinxbase.HuffCode((("foo", 42), ("bar", 4), ("baz", 5), ("quux", 6), ("argh", 225), ("hurf", 15001), ("burf", 3), ("blatz", 2), ("unf", 87), ("woof", 1003)))
15 data, bits = hc.encode(("hurf", "burf", "blatz", "unf", "woof"))
16 dstr = "".join([("%02x" % ord(b)) for b in data])
17 print "encoding", ("hurf", "burf", "blatz", "unf", "woof"), "=>", (dstr, bits)
18 print "decoded to", hc.decode(data)
21 hc = sphinxbase.HuffCode(infile="foo.huff")
22 data, bits = hc.encode(("hurf", "burf", "blatz", "unf", "woof"))
23 dstr = "".join([("%02x" % ord(b)) for b in data])
24 print "encoding", ("hurf", "burf", "blatz", "unf", "woof"), "=>", (dstr, bits)
25 print "decoded to", hc.decode(data)
27 hc.attach("foo.bin", "wb")
28 hc.encode_to_file(("hurf", "burf", "blatz", "unf", "woof"))
29 hc.encode_to_file(("burf", "blatz", "woof", "unf", "woof"))
32 hc.attach("foo.bin", "rb")
35 sym = hc.decode_from_file()