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

commonMain.com.darkrockstudios.symspellkt.common.SuggestionItemUtils.kt Maven / Gradle / Ivy

Go to download

A Kotlin Multiplatform implementation of the SymSpell Spell Checking algorithm.

There is a newer version: 3.1.0
Show newest version
package com.darkrockstudios.symspellkt.common

/**
 * Some utilities for checking if a word is spelled correctly already.
 * Using a Lookup method on an already correct word will return a List
 * containing exactly 1 item, who's term is the original word.
 *
 * Checking that is not very expressive, so these provide a more
 * expressive way to do the check.
 */

/**
 * Check if a given suggestion list implies that the original word was spelled
 * correctly.
 *
 * {@snippet :
 *      val suggestions = spellChecker.lookup(word)
 *      if (suggestions.spellingIsCorrect(word)) println("Word is spell correctly!")
 * }
 */
fun List.spellingIsCorrect(word: String): Boolean =
    (size == 1 && get(0).term.equals(word, ignoreCase = true))

/**
 * Check if a given suggestion list implies that the original word was spelled
 * correctly.
 *
 * {@snippet :
 *      val suggestions = spellChecker.lookup(word)
 *      if (word.isSpelledCorrectly(suggestions)) println("Word is spell correctly!")
 * }
 */
fun String.isSpelledCorrectly(suggestions: List): Boolean =
    (suggestions.size == 1 && suggestions[0].term.equals(this, ignoreCase = true))




© 2015 - 2025 Weber Informatics LLC | Privacy Policy