Fdic
A compact binary frequency-dictionary file format (.fdic) for the plain-text frequency dictionaries that SymSpell-style spell checkers use. Compared to plain text (or gzipped text), .fdic is both smaller on disk and faster to load and parse — roughly 40% smaller and 70% faster to load in typical cases.
This module is the format itself: the in-memory model, validation, and multiplatform read/write. To load a .fdic straight into a SymSpellKt dictionary, use the SymSpellKtFdic add-on. To convert an existing plain-text dictionary into .fdic, use the FdicCli tool.
Read and write
FrequencyDictionaryIO is the entry point; its functions are suspend:
// Read a .fdic file (validates magic word, version, and contents).
val dict: FrequencyDictionary = FrequencyDictionaryIO.readFdic("en.fdic")
// Inspect it.
println("${dict.locale} ${dict.getNgramName()} ${dict.termCount} terms")
val freq: Long? = dict.terms["the"]
// Build one and write it out.
val custom = FrequencyDictionary(
formatVersion = FrequencyDictionaryFileFormat.FORMAT_VERSION.toInt(),
ngrams = 1,
locale = "en",
termCount = 2,
terms = mutableMapOf("hello" to 100L, "world" to 80L),
)
FrequencyDictionaryIO.writeFdic(custom, "custom.fdic")Reading a malformed file throws FdicFormatException (bad magic word or version) or FdicValidationException (inconsistent contents).
A compact binary frequency-dictionary file format (.fdic) for the plain-text frequency dictionaries that SymSpell-style spell checkers use. Compared to plain text (or gzipped text), .fdic is both smaller on disk and faster to load and parse — roughly 40% smaller and 70% faster to load in typical cases.
This module is the format itself: the in-memory model, validation, and multiplatform read/write. To load a .fdic straight into a SymSpellKt dictionary, use the SymSpellKtFdic add-on. To convert an existing plain-text dictionary into .fdic, use the FdicCli tool.
Read and write
FrequencyDictionaryIO is the entry point; its functions are suspend:
// Read a .fdic file (validates magic word, version, and contents).
val dict: FrequencyDictionary = FrequencyDictionaryIO.readFdic("en.fdic")
// Inspect it.
println("${dict.locale} ${dict.getNgramName()} ${dict.termCount} terms")
val freq: Long? = dict.terms["the"]
// Build one and write it out.
val custom = FrequencyDictionary(
formatVersion = FrequencyDictionaryFileFormat.FORMAT_VERSION.toInt(),
ngrams = 1,
locale = "en",
termCount = 2,
terms = mutableMapOf("hello" to 100L, "world" to 80L),
)
FrequencyDictionaryIO.writeFdic(custom, "custom.fdic")Reading a malformed file throws FdicFormatException (bad magic word or version) or FdicValidationException (inconsistent contents).
A compact binary frequency-dictionary file format (.fdic) for the plain-text frequency dictionaries that SymSpell-style spell checkers use. Compared to plain text (or gzipped text), .fdic is both smaller on disk and faster to load and parse — roughly 40% smaller and 70% faster to load in typical cases.
This module is the format itself: the in-memory model, validation, and multiplatform read/write. To load a .fdic straight into a SymSpellKt dictionary, use the SymSpellKtFdic add-on. To convert an existing plain-text dictionary into .fdic, use the FdicCli tool.
Read and write
FrequencyDictionaryIO is the entry point; its functions are suspend:
// Read a .fdic file (validates magic word, version, and contents).
val dict: FrequencyDictionary = FrequencyDictionaryIO.readFdic("en.fdic")
// Inspect it.
println("${dict.locale} ${dict.getNgramName()} ${dict.termCount} terms")
val freq: Long? = dict.terms["the"]
// Build one and write it out.
val custom = FrequencyDictionary(
formatVersion = FrequencyDictionaryFileFormat.FORMAT_VERSION.toInt(),
ngrams = 1,
locale = "en",
termCount = 2,
terms = mutableMapOf("hello" to 100L, "world" to 80L),
)
FrequencyDictionaryIO.writeFdic(custom, "custom.fdic")Reading a malformed file throws FdicFormatException (bad magic word or version) or FdicValidationException (inconsistent contents).