from algorithms.BurrowsWheelerTransform import BurrowsWheelerTransform from algorithms.MoveToFront import MoveToFront from algorithms.Utils import Utils burrowsWheelerTransform = BurrowsWheelerTransform() moveToFront = MoveToFront() utils = Utils() arithmetic_encoded_file_name = "output/arithmetic_encoded.txt" bwt_decoded_file_name = "output/bwt_decoded.txt" mtf_decoded_file_name = "output/mtf_decoded.txt" arithmetic_decoded_file_name = "output/arithmetic_decoded.txt" utils.arithmetic_decode(arithmetic_encoded_file_name, arithmetic_decoded_file_name) utils.replace_file_endings(arithmetic_decoded_file_name) mtf_encoded_file = open(arithmetic_decoded_file_name, "r") code_list = [int(i) for i in mtf_encoded_file.read().split(" ")] mtf_decoded_file = open(mtf_decoded_file_name, "w+") decode = moveToFront.decode(code_list) mtf_decoded_file.write(decode) mtf_decoded_file.close() # decode bwt_encoded_file = open(mtf_decoded_file_name, "r") bwt_decoded_file = open(bwt_decoded_file_name, "w+") for byte_string in bwt_encoded_file.read().split("]"): text = byte_string.split('[') if len(text) > 1:
from algorithms.BurrowsWheelerTransform import BurrowsWheelerTransform from algorithms.Utils import Utils burrowsWheelerTransform = BurrowsWheelerTransform() utils = Utils() block_size = 8192 raw_file_name = "samples/dickens.txt" bwt_encoded_file_name = "output/bwt_encoded.txt" bwt_decoded_file_name = "output/bwt_decoded.txt" utils.replace_file_endings(raw_file_name) # encode bwt_encoded_file = open(bwt_encoded_file_name, "w+") with open(raw_file_name, mode='rb') as f: while True: byte = f.read(block_size) if len(byte.decode()) > 0: index, encoded = burrowsWheelerTransform.code(byte.decode()) bwt_encoded_file.write(str(index)) bwt_encoded_file.write('[') bwt_encoded_file.write(encoded) bwt_encoded_file.write("]") if not byte: break bwt_encoded_file.close() # decode bwt_encoded_file = open(bwt_encoded_file_name, "r") bwt_decoded_file = open(bwt_decoded_file_name, "w+")
from algorithms.BurrowsWheelerTransform import BurrowsWheelerTransform from algorithms.MoveToFront import MoveToFront from algorithms.Utils import Utils import time t1 = time.time() burrowsWheelerTransform = BurrowsWheelerTransform() moveToFront = MoveToFront() utils = Utils() block_size = 8192 raw_file_name = "samples/mobydick.txt" bwt_encoded_file_name = "output/bwt_encoded.txt" mtf_encoded_file_name = "output/mtf_encoded.txt" arithmetic_encoded_file_name = "output/arithmetic_encoded.bin" utils.replace_file_endings(raw_file_name) # encode bwt bwt_encoded_file = open(bwt_encoded_file_name, mode='w+') with open(raw_file_name, "rb") as f: while True: byte = f.read(block_size) if len(byte.decode()) > 0: index, encoded = burrowsWheelerTransform.code(byte.decode()) bwt_encoded_file.write(str(index)) bwt_encoded_file.write('[') bwt_encoded_file.write(encoded) bwt_encoded_file.write("]") if not byte: break bwt_encoded_file.close()
from algorithms.MoveToFront import MoveToFront from algorithms.Utils import Utils moveToFront = MoveToFront() utils = Utils() bwt_encoded_file_name = "output/bwt_encoded.txt" mtf_encoded_file_name = "output/mtf_encoded.txt" mtf_decoded_file_name = "output/mtf_decoded.txt" utils.replace_file_endings(bwt_encoded_file_name) # encode bwt_encoded_file = open(bwt_encoded_file_name, "r") encode = moveToFront.code(bwt_encoded_file.read()) mtf_encoded_file = open(mtf_encoded_file_name, "w+") mtf_encoded_file.write(' '.join(map(str, encode))) mtf_encoded_file.close() # decode mtf_encoded_file = open(mtf_encoded_file_name, "r") code_list = [int(i) for i in mtf_encoded_file.read().split(" ")] mtf_decoded_file = open(mtf_decoded_file_name, "w+") decode = moveToFront.decode(code_list) mtf_decoded_file.write(decode) mtf_decoded_file.close()