-
Notifications
You must be signed in to change notification settings - Fork 0
Python use guide
Martsim edited this page Jan 26, 2018
·
3 revisions
The code was tested with Python 2.7
File: huffman.py
- hc_encode(text) - encodes the text and returns the codeword.
- demo_dickens() - encodes the first 200 characters from a text file 'dickens', that must be in the same directory as the codefile. Prints the resulting code and the number of bytes it takes.
Either import the prementioned functions or comment in one of the tests. Then run from command line (or terminal) with command python huffman.py
File: rANS.py
Note: When encoding symbols, the code migh fail to decode with more than 50 encoded symbols. This makes this implementation a bit unreliable. Using the Java implementation is recommended.
- encode(symbol, x) - encodes the symbol to the given x and returns the new x.
- decode(x) - decodes a symbol and returns the new x.
- encode_text_with_dict(text, possible x value) - calculates probabilities of symbols in given text and then encodes the text based on this. Returns the variable into which the text is encoded. Default starting x is 0.
- demo_dickens() - requires text file 'dickens' to exist at the same directory. Encodes the first 200 characters of the file and presents the resulting code, and the number of bytes it takes to store.
Either import the prementioned functions or comment in one of the tests. Then run from command line (or terminal) with command python rANS.py
File: compare.py
- run_tests() - used for running tests. Additional possible parameters - block size for tests, file name for text source.
Run from command line (or terminal) with command python compare.py
Requires text file 'dickens' in running directory. Can modify and use other files.