All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.darkrockstudios.fdic.FrequencyDictionary.kt Maven / Gradle / Ivy

Go to download

A Kotlin Multiplatform implementation of the SymSpell Spell Checking algorithm.

The newest version!
package com.darkrockstudios.fdic

import com.darkrockstudios.fdic.FrequencyDictionaryFileFormat.FORMAT_VERSION

data class FrequencyDictionary(
	val formatVersion: Int = FORMAT_VERSION.toInt(),
	val ngrams: Int,
	val locale: String,
	val termCount: Int,
	val terms: MutableMap = mutableMapOf()
) {
	fun getNgramName(): String {
		return when (ngrams) {
			1 -> "Unigram"
			2 -> "Bigram"
			else -> error("Illegal ngram count: $ngrams")
		}
	}

	fun validate() {
		when {
			(ngrams != 1 && ngrams != 2) -> throw FdicValidationException("Invalid ngram size: $ngrams")
			(locale.isBlank() || locale.length > 32) -> throw FdicValidationException("Invalid locale length: $locale")
			termCount < 1 -> throw FdicValidationException("Invalid term count: $termCount")
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy