class

TextCompressor::DictionaryEncoder

Inherits TextCompressor::Encoder < Reference < Object

The Dictionary Encoder uses a mapping algorithm to generate a unique encoding for each word selected for compression. Words are grouped by starting char and length. For examples, the word "apple" would be encoded to "a4" If another 5-letter a-word was added it would look like this: {"apple" => "a3e", "artsy" => "a3y"}, and so on.

Instance methods

conflict_words

set of all words that caused a conflict during encoding needs to be saved for reference when decoding as well

Source
counter
Source
decode(tokens : Array(String), encoding_keys : Array(Array(String))) : Array(String)
Source
encode(tokens : Array(String), threshold = 40) : Array(String)

Returns the encoded list of tokens

Source
encoding_keys

Returns a list of mappings to be appended to the compressed file. The mappings are required to decode the compressed file.

Source
encodings

map of words to their encodings

Source
input_tokens
Source
remainder
Source
reverse_encodings

map of encodings to their words

Source