Skip to content

Commit

Permalink
Remove default measure instances
Browse files Browse the repository at this point in the history
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
  • Loading branch information
solonovamax committed Sep 29, 2023
1 parent da9bb56 commit 44a8e4e
Show file tree
Hide file tree
Showing 17 changed files with 14 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ public class Cosine(k: Int = DEFAULT_K) : ShingleBased(k), NormalizedStringDista
return 1.0 - similarity(profile1, profile2)
}

/**
* Default Cosine instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = Cosine()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
private companion object {

/**
* Computes the \(L^2\) norm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,4 @@ public class Jaccard(k: Int = DEFAULT_K) : ShingleBased(k), MetricStringDistance
public fun distance(profile1: Map<String, Int>, profile2: Map<String, Int>): Double {
return 1.0 - similarity(profile1, profile2)
}

/**
* Default Jaccard instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity, MetricStringDistance {
private val defaultMeasure = Jaccard()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,8 @@ public class JaroWinkler(
val longestLength: Int,
)

/**
* Default Jaro-Winkler instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = JaroWinkler()

private companion object {
private const val DEFAULT_THRESHOLD = 0.7
private const val JW_COEFFICIENT = 0.1

override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,7 @@ public class NGram(public val n: Int = DEFAULT_N) : NormalizedStringDistance, No
return 1.0 - distance(s1, s2)
}

/**
* Default NGram instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = NGram()

private companion object {
private const val DEFAULT_N = 2

override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,4 @@ public class QGram(q: Int = DEFAULT_K) : ShingleBased(q), StringDistance {
}
return agg.toDouble()
}

/**
* Default QGram instance
*/
public companion object : StringDistance {
private val defaultMeasure = QGram()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,7 @@ public class RatcliffObershelp : NormalizedStringSimilarity, NormalizedStringDis
return 1.0 - similarity(s1, s2)
}

/**
* Default Ratcliff-Obershelp instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = RatcliffObershelp()

override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)

private companion object {
private fun getMatchCount(s1: String, s2: String): Int {
val anchor = findAnchor(s1, s2)
return when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,7 @@ public class Sift4(
return (max(s1.length, s2.length) - largestCommonSubstringLength + transpositionCount).toDouble()
}

/**
* Default Sift4 dice instance
*/
@ExperimentalStringMeasure
public companion object : StringDistance {
private val defaultMeasure = Sift4()

private companion object {
private const val DEFAULT_MAX_OFFSET = 10

override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,4 @@ public class SorensenDice(k: Int = DEFAULT_K) : ShingleBased(k), NormalizedStrin
public fun distance(profile1: Map<String, Int>, profile2: Map<String, Int>): Double {
return 1.0 - similarity(profile1, profile2)
}

/**
* Default Sorensen Dice instance
*/
public companion object : NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = SorensenDice()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ import ca.solostudios.stringsimilarity.interfaces.StringEditMeasure
*/
public abstract class AbstractNormalizedStringEditMeasure(
public val editMeasure: StringEditMeasure,
public final override val insertionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
public final override val deletionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
public final override val substitutionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
public final override val transpositionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
) : NormalizedStringEditMeasure {
public final override val insertionWeight: Double by editMeasure::insertionWeight
public final override val deletionWeight: Double by editMeasure::deletionWeight
public final override val substitutionWeight: Double by editMeasure::substitutionWeight
public final override val transpositionWeight: Double by editMeasure::transpositionWeight

final override fun distance(s1: String, s2: String): Double {
if (s1 == s2)
return 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,4 @@ public class DamerauLevenshtein(
lastRowId[c1] = i + 1
}
}

/**
* Default Damerau-Levenshtein instance
*/
public companion object : MetricStringDistance, StringDistance, StringSimilarity {
private val defaultMeasure = DamerauLevenshtein()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,4 @@ public class LCS(
}
}
}

/**
* Default LCS instance
*/
public companion object : MetricStringDistance, StringDistance, StringSimilarity {
private val defaultMeasure = LCS()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,4 @@ public class Levenshtein(
}
}
}

/**
* Default Levenshtein instance
*/
public companion object : MetricStringDistance, StringDistance, StringSimilarity {
private val defaultMeasure = Levenshtein()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,4 @@ public class NormalizedDamerauLevenshtein(
deletionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
substitutionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
transpositionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
) : AbstractNormalizedStringEditMeasure(
DamerauLevenshtein(insertionWeight, deletionWeight, substitutionWeight, transpositionWeight),
insertionWeight,
deletionWeight,
substitutionWeight,
transpositionWeight
) {
/**
* Default Normalized Damerau-Levenshtein instance
*/
public companion object : MetricStringDistance, NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = NormalizedDamerauLevenshtein()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
) : AbstractNormalizedStringEditMeasure(DamerauLevenshtein(insertionWeight, deletionWeight, substitutionWeight, transpositionWeight))
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,4 @@ import ca.solostudios.stringsimilarity.interfaces.StringSimilarity
public class NormalizedLCS(
insertionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
deletionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
) : AbstractNormalizedStringEditMeasure(
editMeasure = LCS(),
insertionWeight = insertionWeight,
deletionWeight = deletionWeight,
) {
/**
* Default Normalized LCS instance
*/
public companion object : MetricStringDistance, NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = NormalizedLCS()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
) : AbstractNormalizedStringEditMeasure(LCS(insertionWeight, deletionWeight))
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,4 @@ public class NormalizedLevenshtein(
insertionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
deletionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
substitutionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
) : AbstractNormalizedStringEditMeasure(
editMeasure = Levenshtein(),
insertionWeight = insertionWeight,
deletionWeight = deletionWeight,
substitutionWeight = substitutionWeight,
) {
/**
* Default Normalized Levenshtein instance
*/
public companion object : MetricStringDistance, NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = NormalizedLevenshtein()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
) : AbstractNormalizedStringEditMeasure(Levenshtein(insertionWeight, deletionWeight, substitutionWeight))
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,4 @@ public class NormalizedOptimalStringAlignment(
deletionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
substitutionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
transpositionWeight: Double = StringEditMeasure.DEFAULT_WEIGHT,
) : AbstractNormalizedStringEditMeasure(
OptimalStringAlignment(insertionWeight, deletionWeight, substitutionWeight, transpositionWeight),
insertionWeight,
deletionWeight,
substitutionWeight,
transpositionWeight
) {
/**
* Default Normalized Optimal String Alignment instance
*/
public companion object : MetricStringDistance, NormalizedStringDistance, NormalizedStringSimilarity {
private val defaultMeasure = NormalizedOptimalStringAlignment()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}
) : AbstractNormalizedStringEditMeasure(OptimalStringAlignment(insertionWeight, deletionWeight, substitutionWeight, transpositionWeight))
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,4 @@ public class OptimalStringAlignment(
}
}
}

/**
* Default Optimal String Alignment instance
*/
public companion object : MetricStringDistance, StringDistance, StringSimilarity {
private val defaultMeasure = OptimalStringAlignment()
override fun distance(s1: String, s2: String): Double = defaultMeasure.distance(s1, s2)
override fun similarity(s1: String, s2: String): Double = defaultMeasure.similarity(s1, s2)
}
}

0 comments on commit 44a8e4e

Please sign in to comment.