diff options
author | Rocky Madden <git@rockymadden.com> | 2013-03-09 12:53:42 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-03-09 12:53:42 -0700 |
commit | 85bba3b386d7a38859ba8c0bfcf04623dec2d9ba (patch) | |
tree | ce13102d525e4ba9d676643480863e97c9f9ea00 /core/source | |
parent | 396bf0129dda0cac792eeae5ef057fcedfcdeb72 (diff) | |
download | stringmetric-85bba3b386d7a38859ba8c0bfcf04623dec2d9ba.tar.gz stringmetric-85bba3b386d7a38859ba8c0bfcf04623dec2d9ba.tar.bz2 stringmetric-85bba3b386d7a38859ba8c0bfcf04623dec2d9ba.zip |
Algorithm and metric companion objects now have pass-through compute/compare methods, which are backed by lazy vals.
Diffstat (limited to 'core/source')
42 files changed, 303 insertions, 70 deletions
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala index 17c46d1..4c8958b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala @@ -7,9 +7,8 @@ trait ConfigurableStringAlgorithm[R, O] extends ConfigurableAlgorithm[String, R, object ConfigurableStringAlgorithm { type NGramAlgorithm = com.rockymadden.stringmetric.similarity.NGramAlgorithm val NGramAlgorithm = com.rockymadden.stringmetric.similarity.NGramAlgorithm - lazy val nGram = NGramAlgorithm() - def computeWithNGram(charArray: Array[Char])(n: Int): Option[Array[Array[Char]]] = nGram.compute(charArray)(n) + def computeWithNGram(charArray: Array[Char])(n: Int) = NGramAlgorithm.compute(charArray)(n) - def computeWithNGram(string: String)(n: Int): Option[Array[String]] = nGram.compute(string)(n) + def computeWithNGram(string: String)(n: Int) = NGramAlgorithm.compute(string)(n) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala index 9afc102..2ccce55 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala @@ -7,34 +7,31 @@ trait ConfigurableStringMetric[R, O] extends ConfigurableMetric[String, R, O] { object ConfigurableStringMetric { type DiceSorensenMetric = com.rockymadden.stringmetric.similarity.DiceSorensenMetric val DiceSorensenMetric = com.rockymadden.stringmetric.similarity.DiceSorensenMetric - lazy val diceSorensen = DiceSorensenMetric() type NGramMetric = com.rockymadden.stringmetric.similarity.NGramMetric val NGramMetric = com.rockymadden.stringmetric.similarity.NGramMetric - lazy val nGram = NGramMetric() type WeightedLevenshteinMetric = com.rockymadden.stringmetric.similarity.WeightedLevenshteinMetric val WeightedLevenshteinMetric = com.rockymadden.stringmetric.similarity.WeightedLevenshteinMetric - lazy val weightedLevenshtein = WeightedLevenshteinMetric() - def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] = - diceSorensen.compare(charArray1, charArray2)(n) + def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = + DiceSorensenMetric.compare(charArray1, charArray2)(n) - def compareWithDiceSorensen(string1: String, string2: String)(n: Int): Option[Double] = - diceSorensen.compare(string1, string2)(n) + def compareWithDiceSorensen(string1: String, string2: String)(n: Int) = + DiceSorensenMetric.compare(string1, string2)(n) - def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] = - nGram.compare(charArray1, charArray2)(n) + def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = + NGramMetric.compare(charArray1, charArray2)(n) - def compareWithNGram(string1: String, string2: String)(n: Int): Option[Double] = nGram.compare(string1, string2)(n) + def compareWithNGram(string1: String, string2: String)(n: Int) = NGramMetric.compare(string1, string2)(n) def compareWithWeightedLevenshtein(charArray1: Array[Char], charArray2: Array[Char]) - (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = + (options: (BigDecimal, BigDecimal, BigDecimal)) = - weightedLevenshtein.compare(charArray1, charArray2)(options) + WeightedLevenshteinMetric.compare(charArray1, charArray2)(options) def compareWithWeightedLevenshtein(string1: String, string2: String) - (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = + (options: (BigDecimal, BigDecimal, BigDecimal)) = - weightedLevenshtein.compare(string1, string2)(options) + WeightedLevenshteinMetric.compare(string1, string2)(options) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala index 1cd43f1..d89a626 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala @@ -7,41 +7,36 @@ trait StringAlgorithm[R] extends Algorithm[String, R] { object StringAlgorithm { type MetaphoneAlgorithm = com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm val MetaphoneAlgorithm = com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm - lazy val metaphone = MetaphoneAlgorithm() type NysiisAlgorithm = com.rockymadden.stringmetric.phonetic.NysiisAlgorithm val NysiisAlgorithm = com.rockymadden.stringmetric.phonetic.NysiisAlgorithm - lazy val nysiis = NysiisAlgorithm() type RefinedNysiisAlgorithm = com.rockymadden.stringmetric.phonetic.RefinedNysiisAlgorithm val RefinedNysiisAlgorithm = com.rockymadden.stringmetric.phonetic.RefinedNysiisAlgorithm - lazy val refinedNysiis = RefinedNysiisAlgorithm() type RefinedSoundexAlgorithm = com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm val RefinedSoundexAlgorithm = com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm - lazy val refinedSoundex = RefinedSoundexAlgorithm() type SoundexAlgorithm = com.rockymadden.stringmetric.phonetic.SoundexAlgorithm val SoundexAlgorithm = com.rockymadden.stringmetric.phonetic.SoundexAlgorithm - lazy val soundex = SoundexAlgorithm() - def computeWithMetaphone(charArray: Array[Char]): Option[Array[Char]] = metaphone.compute(charArray) + def computeWithMetaphone(charArray: Array[Char]) = MetaphoneAlgorithm.compute(charArray) - def computeWithMetaphone(string: String): Option[String] = metaphone.compute(string) + def computeWithMetaphone(string: String) = MetaphoneAlgorithm.compute(string) - def computeWithNysiis(charArray: Array[Char]): Option[Array[Char]] = nysiis.compute(charArray) + def computeWithNysiis(charArray: Array[Char]) = NysiisAlgorithm.compute(charArray) - def computeWithNysiis(string: String): Option[String] = nysiis.compute(string) + def computeWithNysiis(string: String) = NysiisAlgorithm.compute(string) - def computeWithRefinedNysiis(charArray: Array[Char]): Option[Array[Char]] = refinedNysiis.compute(charArray) + def computeWithRefinedNysiis(charArray: Array[Char]) = RefinedNysiisAlgorithm.compute(charArray) - def computeWithRefinedNysiis(string: String): Option[String] = refinedNysiis.compute(string) + def computeWithRefinedNysiis(string: String) = RefinedNysiisAlgorithm.compute(string) - def computeWithRefinedSoundex(charArray: Array[Char]): Option[Array[Char]] = refinedSoundex.compute(charArray) + def computeWithRefinedSoundex(charArray: Array[Char]) = RefinedSoundexAlgorithm.compute(charArray) - def computeWithRefinedSoundex(string: String): Option[String] = refinedSoundex.compute(string) + def computeWithRefinedSoundex(string: String) = RefinedSoundexAlgorithm.compute(string) - def computeWithSoundex(charArray: Array[Char]): Option[Array[Char]] = soundex.compute(charArray) + def computeWithSoundex(charArray: Array[Char]) = SoundexAlgorithm.compute(charArray) - def computeWithSoundex(string: String): Option[String] = soundex.compute(string) + def computeWithSoundex(string: String) = SoundexAlgorithm.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala index 4e90f8c..b66b218 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala @@ -7,84 +7,72 @@ trait StringMetric[R] extends Metric[String, R] { object StringMetric { type HammingMetric = com.rockymadden.stringmetric.similarity.HammingMetric val HammingMetric = com.rockymadden.stringmetric.similarity.HammingMetric - lazy val hamming = HammingMetric() type JaroMetric = com.rockymadden.stringmetric.similarity.JaroMetric val JaroMetric = com.rockymadden.stringmetric.similarity.JaroMetric - lazy val jaro = JaroMetric() type JaroWinklerMetric = com.rockymadden.stringmetric.similarity.JaroWinklerMetric val JaroWinklerMetric = com.rockymadden.stringmetric.similarity.JaroWinklerMetric - lazy val jaroWinkler = JaroWinklerMetric() type LevenshteinMetric = com.rockymadden.stringmetric.similarity.LevenshteinMetric val LevenshteinMetric = com.rockymadden.stringmetric.similarity.LevenshteinMetric - lazy val levenshtein = LevenshteinMetric() type MetaphoneMetric = com.rockymadden.stringmetric.phonetic.MetaphoneMetric val MetaphoneMetric = com.rockymadden.stringmetric.phonetic.MetaphoneMetric - lazy val metaphone = MetaphoneMetric() type NysiisMetric = com.rockymadden.stringmetric.phonetic.NysiisMetric val NysiisMetric = com.rockymadden.stringmetric.phonetic.NysiisMetric - lazy val nysiis = NysiisMetric() type RefinedNysiisMetric = com.rockymadden.stringmetric.phonetic.RefinedNysiisMetric val RefinedNysiisMetric = com.rockymadden.stringmetric.phonetic.RefinedNysiisMetric - lazy val refinedNysiis = RefinedNysiisMetric() type RefinedSoundexMetric = com.rockymadden.stringmetric.phonetic.RefinedSoundexMetric val RefinedSoundexMetric = com.rockymadden.stringmetric.phonetic.RefinedSoundexMetric - lazy val refinedSoundex = RefinedSoundexMetric() type SoundexMetric = com.rockymadden.stringmetric.phonetic.SoundexMetric val SoundexMetric = com.rockymadden.stringmetric.phonetic.SoundexMetric - lazy val soundex = SoundexMetric() - def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = - hamming.compare(charArray1, charArray2) + def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char]) = + HammingMetric.compare(charArray1, charArray2) - def compareWithHamming(string1: String, string2: String): Option[Int] = hamming.compare(string1, string2) + def compareWithHamming(string1: String, string2: String)= HammingMetric.compare(string1, string2) - def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = - jaro.compare(charArray1, charArray2) + def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char]) = JaroMetric.compare(charArray1, charArray2) - def compareWithJaro(string1: String, string2: String): Option[Double] = jaro.compare(string1, string2) + def compareWithJaro(string1: String, string2: String) = JaroMetric.compare(string1, string2) - def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = - jaroWinkler.compare(charArray1, charArray2) + def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]) = + JaroWinklerMetric.compare(charArray1, charArray2) - def compareWithJaroWinkler(string1: String, string2: String): Option[Double] = jaroWinkler.compare(string1, string2) + def compareWithJaroWinkler(string1: String, string2: String) = JaroWinklerMetric.compare(string1, string2) - def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = - levenshtein.compare(charArray1, charArray2) + def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char]) = + LevenshteinMetric.compare(charArray1, charArray2) - def compareWithLevenshtein(string1: String, string2: String): Option[Int] = levenshtein.compare(string1, string2) + def compareWithLevenshtein(string1: String, string2: String) = LevenshteinMetric.compare(string1, string2) - def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - metaphone.compare(charArray1, charArray2) + def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char]) = + MetaphoneMetric.compare(charArray1, charArray2) - def compareWithMetaphone(string1: String, string2: String): Option[Boolean] = metaphone.compare(string1, string2) + def compareWithMetaphone(string1: String, string2: String) = MetaphoneMetric.compare(string1, string2) - def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - nysiis.compare(charArray1, charArray2) + def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char]) = + NysiisMetric.compare(charArray1, charArray2) - def compareWithNysiis(string1: String, string2: String): Option[Boolean] = nysiis.compare(string1, string2) + def compareWithNysiis(string1: String, string2: String) = NysiisMetric.compare(string1, string2) - def compareWithRefinedNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - refinedNysiis.compare(charArray1, charArray2) + def compareWithRefinedNysiis(charArray1: Array[Char], charArray2: Array[Char]) = + RefinedNysiisMetric.compare(charArray1, charArray2) - def compareWithRefinedNysiis(string1: String, string2: String): Option[Boolean] = - refinedNysiis.compare(string1, string2) + def compareWithRefinedNysiis(string1: String, string2: String) = RefinedNysiisMetric.compare(string1, string2) - def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - refinedSoundex.compare(charArray1, charArray2) + def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]) = + RefinedSoundexMetric.compare(charArray1, charArray2) - def compareWithRefinedSoundex(string1: String, string2: String): Option[Boolean] = - refinedSoundex.compare(string1, string2) + def compareWithRefinedSoundex(string1: String, string2: String) = RefinedSoundexMetric.compare(string1, string2) - def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - soundex.compare(charArray1, charArray2) + def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char]) = + SoundexMetric.compare(charArray1, charArray2) - def compareWithSoundex(string1: String, string2: String): Option[Boolean] = soundex.compare(string1, string2) + def compareWithSoundex(string1: String, string2: String) = SoundexMetric.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala index 518213b..61d7d60 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -115,5 +115,11 @@ class MetaphoneAlgorithm extends StringAlgorithm[String] { } object MetaphoneAlgorithm { + private lazy val self = apply() + def apply(): MetaphoneAlgorithm = new MetaphoneAlgorithm with StringFilter + + def compute(charArray: Array[Char]) = self.compute(charArray) + + def compute(string: String) = self.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala index cce3df9..eb959dd 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala @@ -25,5 +25,11 @@ class MetaphoneMetric extends StringMetric[Boolean] { } object MetaphoneMetric { + private lazy val self = apply() + def apply(): MetaphoneMetric = new MetaphoneMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala index cd07a71..0beb2df 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala @@ -122,5 +122,11 @@ class NysiisAlgorithm extends StringAlgorithm[String] { } object NysiisAlgorithm { + private lazy val self = apply() + def apply(): NysiisAlgorithm = new NysiisAlgorithm with StringFilter + + def compute(charArray: Array[Char]) = self.compute(charArray) + + def compute(string: String) = self.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala index 9df9b16..cddf91b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala @@ -33,5 +33,11 @@ class NysiisMetric extends StringMetric[Boolean] { } object NysiisMetric { + private lazy val self = apply() + def apply(): NysiisMetric = new NysiisMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala index ef8a134..5e88aae 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala @@ -126,5 +126,11 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[String] { } object RefinedNysiisAlgorithm { + private lazy val self = apply() + def apply(): RefinedNysiisAlgorithm = new RefinedNysiisAlgorithm with StringFilter + + def compute(charArray: Array[Char]) = self.compute(charArray) + + def compute(string: String) = self.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala index 7be84af..593cda4 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala @@ -33,5 +33,11 @@ class RefinedNysiisMetric extends StringMetric[Boolean] { } object RefinedNysiisMetric { + private lazy val self = apply() + def apply(): RefinedNysiisMetric = new RefinedNysiisMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala index 1f460fb..31d7980 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala @@ -66,5 +66,11 @@ class RefinedSoundexAlgorithm extends StringAlgorithm[String] { } object RefinedSoundexAlgorithm { + private lazy val self = apply() + def apply(): RefinedSoundexAlgorithm = new RefinedSoundexAlgorithm with StringFilter + + def compute(charArray: Array[Char]) = self.compute(charArray) + + def compute(string: String) = self.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala index d1bd6bb..b099564 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala @@ -26,5 +26,11 @@ class RefinedSoundexMetric extends StringMetric[Boolean] { } object RefinedSoundexMetric { + private lazy val self = apply() + def apply(): RefinedSoundexMetric = new RefinedSoundexMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala index c7adb18..6e1150a 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala @@ -64,5 +64,11 @@ class SoundexAlgorithm extends StringAlgorithm[String] { } object SoundexAlgorithm { + private lazy val self = apply() + def apply(): SoundexAlgorithm = new SoundexAlgorithm with StringFilter + + def compute(charArray: Array[Char]) = self.compute(charArray) + + def compute(string: String) = self.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala index 928066b..d1f3c9b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala @@ -26,5 +26,11 @@ class SoundexMetric extends StringMetric[Boolean] { } object SoundexMetric { + private lazy val self = apply() + def apply(): SoundexMetric = new SoundexMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala index 8250cf3..6ab8662 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala @@ -37,5 +37,11 @@ class DiceSorensenMetric extends ConfigurableStringMetric[Double, Int] { } object DiceSorensenMetric { + private lazy val self = apply() + def apply(): DiceSorensenMetric = new DiceSorensenMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) + + def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala index 37cc6a1..61d3acd 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala @@ -27,5 +27,11 @@ class HammingMetric extends StringMetric[Int] { } object HammingMetric { + private lazy val self = apply() + def apply(): HammingMetric = new HammingMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala index 8e3d5d7..706b0ed 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala @@ -77,5 +77,11 @@ class JaroMetric extends StringMetric[Double] { } object JaroMetric { + private lazy val self = apply() + def apply(): JaroMetric = new JaroMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala index 70ffa17..273d69b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala @@ -30,5 +30,11 @@ class JaroWinklerMetric extends StringMetric[Double] { } object JaroWinklerMetric { + private lazy val self = apply() + def apply(): JaroWinklerMetric = new JaroWinklerMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala index 440ca48..ed4c71e 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala @@ -49,5 +49,11 @@ class LevenshteinMetric extends StringMetric[Int] { } object LevenshteinMetric { + private lazy val self = apply() + def apply(): LevenshteinMetric = new LevenshteinMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala index 0b95c75..e903ec6 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala @@ -29,5 +29,11 @@ class NGramAlgorithm extends ConfigurableStringAlgorithm[Array[String], Int] { } object NGramAlgorithm { + private lazy val self = apply() + def apply(): NGramAlgorithm = new NGramAlgorithm with StringFilter + + def compute(charArray: Array[Char])(n: Int) = self.compute(charArray)(n) + + def compute(string: String)(n: Int) = self.compute(string)(n) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala index 56c9c88..c821f33 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala @@ -35,5 +35,11 @@ class NGramMetric extends ConfigurableStringMetric[Double, Int] { } object NGramMetric { + private lazy val self = apply() + def apply(): NGramMetric = new NGramMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) + + def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala index 415641d..3ae39a4 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala @@ -47,5 +47,11 @@ class RatcliffObershelpMetric extends StringMetric[Double] { } object RatcliffObershelpMetric { + private lazy val self = apply() + def apply(): RatcliffObershelpMetric = new RatcliffObershelpMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + + def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala index 6aafbcd..b53a7ab 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala @@ -52,5 +52,13 @@ class WeightedLevenshteinMetric } object WeightedLevenshteinMetric { + private lazy val self = apply() + def apply(): WeightedLevenshteinMetric = new WeightedLevenshteinMetric with StringFilter + + def compare(charArray1: Array[Char], charArray2: Array[Char])(options: (BigDecimal, BigDecimal, BigDecimal)) = + self.compare(charArray1, charArray2)(options) + + def compare(string1: String, string2: String)(options: (BigDecimal, BigDecimal, BigDecimal)) = + self.compare(string1, string2)(options) } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala index 6698358..1f904d5 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala @@ -212,6 +212,13 @@ final class MetaphoneAlgorithmSpec extends ScalaTest { } } } + "MetaphoneAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + MetaphoneAlgorithm.compute("dumb").get should equal ("tm") + } + } + } } object MetaphoneAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala index 867e49b..9a029d8 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala @@ -40,6 +40,13 @@ final class MetaphoneMetricSpec extends ScalaTest { } } } + "MetaphoneMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + MetaphoneMetric.compare("dumb", "gum").get should be (false) + } + } + } } object MetaphoneMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala index 69c23d9..6a0f113 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala @@ -190,6 +190,13 @@ final class NysiisAlgorithmSpec extends ScalaTest { } } } + "NysiisAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + NysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + } + } + } } object NysiisAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala index 92748e6..c6929a2 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala @@ -36,6 +36,13 @@ final class NysiisMetricSpec extends ScalaTest { } } } + "NysiisMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + NysiisMetric.compare("dumb", "gum").get should be (false) + } + } + } } object NysiisMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala index bb5d99d..1298d2d 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala @@ -207,6 +207,13 @@ final class RefinedNysiisAlgorithmSpec extends ScalaTest { } } } + "RefinedNysiisAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + RefinedNysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + } + } + } } object RefinedNysiisAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala index 14ea64b..ca9d2ec 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala @@ -36,6 +36,13 @@ final class RefinedNysiisMetricSpec extends ScalaTest { } } } + "RefinedNysiisMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + RefinedNysiisMetric.compare("dumb", "gum").get should be (false) + } + } + } } object RefinedNysiisMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala index 0c78fe7..254bf06 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala @@ -161,6 +161,13 @@ final class RefinedSoundexAlgorithmSpec extends ScalaTest { } } } + "RefinedSoundexAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + RefinedSoundexAlgorithm.compute("braz").get should equal ("b1905") + } + } + } } object RefinedSoundexAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala index 0f3a244..cb6a222 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala @@ -36,6 +36,13 @@ final class RefinedSoundexMetricSpec extends ScalaTest { } } } + "RefinedSoundexMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + RefinedSoundexMetric.compare("robert", "rubin").get should be (false) + } + } + } } object RefinedSoundexMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala index 8f1be8d..5b7deaa 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala @@ -160,6 +160,13 @@ final class SoundexAlgorithmSpec extends ScalaTest { } } } + "SoundexAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + SoundexAlgorithm.compute("abc").get should equal ("a120") + } + } + } } object SoundexAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala index 98bb28b..9fc47d8 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala @@ -36,6 +36,13 @@ final class SoundexMetricSpec extends ScalaTest { } } } + "SoundexMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + SoundexMetric.compare("robert", "rubin").get should be (false) + } + } + } } object SoundexMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala index fd03889..5ddfc06 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala @@ -61,6 +61,13 @@ final class DiceSorensenMetricSpec extends ScalaTest { } } } + "DiceSorensenMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + DiceSorensenMetric.compare("context", "contact")(3).get should be (0.4) + } + } + } } object DiceSorensenMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala index f363d73..c69d860 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala @@ -38,6 +38,13 @@ final class HammingMetricSpec extends ScalaTest { } } } + "HammingMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + HammingMetric.compare("2173896", "2233796").get should be (3) + } + } + } } object HammingMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala index 692ec9d..00f4daf 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala @@ -52,6 +52,13 @@ final class JaroMetricSpec extends ScalaTest { } } } + "JaroMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + JaroMetric.compare("fvie", "ten").get should be (0) + } + } + } } object JaroMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala index 6ee44d1..06421a8 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala @@ -52,6 +52,13 @@ final class JaroWinklerMetricSpec extends ScalaTest { } } } + "JaroWinklerMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + JaroWinklerMetric.compare("fvie", "ten").get should be (0) + } + } + } } object JaroWinklerMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala index c0a183e..51de2ca 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala @@ -51,6 +51,13 @@ final class LevenshteinMetricSpec extends ScalaTest { } } } + "LevenshteinMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + LevenshteinMetric.compare("fvg", "fog").get should be (1) + } + } + } } object LevenshteinMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala index 87d2a3d..82a0c69 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala @@ -50,6 +50,18 @@ final class NGramAlgorithmSpec extends ScalaTest { } } } + "NGramAlgorithm companion object" should provide { + "pass-through compute method" should returns { + "same value as class" in { + NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(1).get should equal ( + Array( + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", + "s", "t", "u", "v", "w", "x", "y", "z" + ) + ) + } + } + } } object NGramAlgorithmSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala index 20a17c4..39d97e5 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala @@ -61,6 +61,13 @@ final class NGramMetricSpec extends ScalaTest { } } } + "NGramMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + NGramMetric.compare("context", "contact")(3).get should be (0.4) + } + } + } } object NGramMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala index 445c2b6..638536f 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala @@ -41,6 +41,13 @@ final class RatcliffObershelpMetricSpec extends ScalaTest { } } } + "RatcliffObershelpMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + RatcliffObershelpMetric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058) + } + } + } } object RatcliffObershelpMetricSpec { diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala index c93e652..0d4e246 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala @@ -49,6 +49,13 @@ final class WeightedLevenshteinMetricSpec extends ScalaTest { } } } + "WeightedLevenshteinMetric companion object" should provide { + "pass-through compare method" should returns { + "same value as class" in { + WeightedLevenshteinMetric.compare("hospital", "hosp")(Options).get should be (40) + } + } + } } object WeightedLevenshteinMetricSpec { |