commonMain.com.dshatz.fuzzykat.diffutils.ratio.SimpleRatio.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fuzzyKat-jvm Show documentation
Show all versions of fuzzyKat-jvm Show documentation
Fuzzy search for Kotlin Multiplatform
The newest version!
package com.dshatz.fuzzykat.diffutils.ratio
import com.dshatz.fuzzykat.Ratio
import com.dshatz.fuzzykat.ToStringFunction
import com.dshatz.fuzzykat.diffutils.DiffUtils
import kotlin.math.round
class SimpleRatio : Ratio {
/**
* Computes a simple Levenshtein distance ratio between the strings
*
* @param s1 Input string
* @param s2 Input string
* @return The resulting ratio of similarity
*/
override fun apply(s1: String, s2: String): Int {
return round(100 * DiffUtils.getRatio(s1, s2)).toInt()
}
override fun apply(s1: String, s2: String, sp: ToStringFunction): Int {
return apply(sp.apply(s1), sp.apply(s2))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy