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

commonMain.com.dshatz.fuzzykat.diffutils.ratio.SimpleRatio.kt Maven / Gradle / Ivy

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