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

commonMain.com.darkrockstudios.symspellkt.api.DictionaryUtils.kt Maven / Gradle / Ivy

package com.darkrockstudios.symspellkt.api

import com.darkrockstudios.symspellkt.impl.loadBiGramLine
import com.darkrockstudios.symspellkt.impl.loadUniGramLine

suspend fun DictionaryHolder.loadUnigramTxtFile(dictionaryContents: String) {
	dictionaryContents
		.lineSequence()
		.forEachAsync { line ->
			loadUniGramLine(line)
		}
}

suspend fun DictionaryHolder.loadUnigramTxtFile(byteArray: ByteArray) {
	loadUnigramTxtFile(byteArray.decodeToString())
}

suspend fun DictionaryHolder.loadBigramTxtFile(dictionaryContents: String) {
	dictionaryContents
		.lineSequence()
		.forEachAsync { line ->
			loadBiGramLine(line)
		}
}

suspend fun DictionaryHolder.loadBigramTxtFile(byteArray: ByteArray) {
	loadBigramTxtFile(byteArray.decodeToString())
}

/**
 * This is here so we can yield, without this
 * WASM builds were deadlocking the UI thread.
 */
suspend fun  Sequence.forEachAsync(
	action: suspend (T) -> Unit
) {
	for (item in this) {
		action(item)
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy