diff options
author | Rocky Madden <git@rockymadden.com> | 2013-03-07 11:45:36 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-03-07 11:45:36 -0700 |
commit | 55a9d5626285c833f2adb53da254ddcc51d66f21 (patch) | |
tree | 8140a0bff9648adf4cb242a621046817eaeebfca /core/source | |
parent | 315422887d00e333a9f113fc16089c4e8468ca61 (diff) | |
download | stringmetric-55a9d5626285c833f2adb53da254ddcc51d66f21.tar.gz stringmetric-55a9d5626285c833f2adb53da254ddcc51d66f21.tar.bz2 stringmetric-55a9d5626285c833f2adb53da254ddcc51d66f21.zip |
Convenience objects backed by lazy vals.
Diffstat (limited to 'core/source')
5 files changed, 75 insertions, 94 deletions
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala index 33fd61e..33f9e80 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala @@ -7,10 +7,9 @@ trait ConfigurableStringAlgorithm[R, O] extends ConfigurableAlgorithm[String, R, } object ConfigurableStringAlgorithm { - def computeWithNGram(charArray: Array[Char])(n: Int): Option[Array[Array[Char]]] = - NGramAlgorithm().compute(charArray)(n) + lazy val nGram = NGramAlgorithm() - def computeWithNGram(string: String)(n: Int): Option[Array[String]] = NGramAlgorithm().compute(string)(n) + def computeWithNGram(charArray: Array[Char])(n: Int): Option[Array[Array[Char]]] = nGram.compute(charArray)(n) - def nGram: NGramAlgorithm.type = NGramAlgorithm + def computeWithNGram(string: String)(n: Int): Option[Array[String]] = nGram.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 80f3e49..ae04a9f 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala @@ -7,31 +7,28 @@ trait ConfigurableStringMetric[R, O] extends ConfigurableMetric[String, R, O] { } object ConfigurableStringMetric { + lazy val diceSorensen = DiceSorensenMetric() + lazy val nGram = NGramMetric() + lazy val weightedLevenshtein = WeightedLevenshteinMetric() + def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] = - DiceSorensenMetric().compare(charArray1, charArray2)(n) + diceSorensen.compare(charArray1, charArray2)(n) def compareWithDiceSorensen(string1: String, string2: String)(n: Int): Option[Double] = - DiceSorensenMetric().compare(string1, string2)(n) + diceSorensen.compare(string1, string2)(n) def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] = - NGramMetric().compare(charArray1, charArray2)(n) + nGram.compare(charArray1, charArray2)(n) - def compareWithNGram(string1: String, string2: String)(n: Int): Option[Double] = - NGramMetric().compare(string1, string2)(n) + def compareWithNGram(string1: String, string2: String)(n: Int): Option[Double] = nGram.compare(string1, string2)(n) def compareWithWeightedLevenshtein(charArray1: Array[Char], charArray2: Array[Char]) (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = - WeightedLevenshteinMetric().compare(charArray1, charArray2)(options) + weightedLevenshtein.compare(charArray1, charArray2)(options) def compareWithWeightedLevenshtein(string1: String, string2: String) (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = - WeightedLevenshteinMetric().compare(string1, string2)(options) - - def diceSorensen: DiceSorensenMetric.type = DiceSorensenMetric - - def nGram: NGramMetric.type = NGramMetric - - def weightedLevenshtein: WeightedLevenshteinMetric.type = WeightedLevenshteinMetric + weightedLevenshtein.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 2d72e60..96edd78 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala @@ -1,34 +1,35 @@ package com.rockymadden.stringmetric -import com.rockymadden.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm } +import com.rockymadden.stringmetric.phonetic._ trait StringAlgorithm[R] extends Algorithm[String, R] { def compute(charArray: Array[Char]): Option[Array[_]] } object StringAlgorithm { - def computeWithMetaphone(charArray: Array[Char]): Option[Array[Char]] = MetaphoneAlgorithm().compute(charArray) + lazy val metaphone = MetaphoneAlgorithm() + lazy val nysiis = NysiisAlgorithm() + lazy val refinedNysiis = RefinedNysiisAlgorithm() + lazy val refinedSoundex = RefinedSoundexAlgorithm() + lazy val soundex = SoundexAlgorithm() - def computeWithMetaphone(string: String): Option[String] = MetaphoneAlgorithm().compute(string) + def computeWithMetaphone(charArray: Array[Char]): Option[Array[Char]] = metaphone.compute(charArray) - def computeWithNysiis(charArray: Array[Char]): Option[Array[Char]] = NysiisAlgorithm().compute(charArray) + def computeWithMetaphone(string: String): Option[String] = metaphone.compute(string) - def computeWithNysiis(string: String): Option[String] = NysiisAlgorithm().compute(string) + def computeWithNysiis(charArray: Array[Char]): Option[Array[Char]] = nysiis.compute(charArray) - def computeWithRefinedSoundex(charArray: Array[Char]): Option[Array[Char]] = - RefinedSoundexAlgorithm().compute(charArray) + def computeWithNysiis(string: String): Option[String] = nysiis.compute(string) - def computeWithRefinedSoundex(string: String): Option[String] = RefinedSoundexAlgorithm().compute(string) + def computeWithRefinedNysiis(charArray: Array[Char]): Option[Array[Char]] = refinedNysiis.compute(charArray) - def computeWithSoundex(charArray: Array[Char]): Option[Array[Char]] = SoundexAlgorithm().compute(charArray) + def computeWithRefinedNysiis(string: String): Option[String] = refinedNysiis.compute(string) - def computeWithSoundex(string: String): Option[String] = SoundexAlgorithm().compute(string) + def computeWithRefinedSoundex(charArray: Array[Char]): Option[Array[Char]] = refinedSoundex.compute(charArray) - def metaphone: MetaphoneAlgorithm.type = MetaphoneAlgorithm + def computeWithRefinedSoundex(string: String): Option[String] = refinedSoundex.compute(string) - def nysiis: NysiisAlgorithm.type = NysiisAlgorithm + def computeWithSoundex(charArray: Array[Char]): Option[Array[Char]] = soundex.compute(charArray) - def refinedSoundex: RefinedSoundexAlgorithm.type = RefinedSoundexAlgorithm - - def soundex: SoundexAlgorithm.type = SoundexAlgorithm + def computeWithSoundex(string: String): Option[String] = soundex.compute(string) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala index 88c58c2..c3fa3ad 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala @@ -7,29 +7,17 @@ trait StringFilter extends Filter[String] with StringFilterable { } object StringFilter { - def asciiControl = new StringFilterDelegate with AsciiControlStringFilter - - def asciiControlOnly = new StringFilterDelegate with AsciiControlOnlyStringFilter - - def asciiLetterCase = new StringFilterDelegate with AsciiLetterCaseStringFilter - - def asciiLetterNumber = new StringFilterDelegate with AsciiLetterNumberStringFilter - - def asciiLetterNumberOnly = new StringFilterDelegate with AsciiLetterNumberOnlyStringFilter - - def asciiLetter = new StringFilterDelegate with AsciiLetterStringFilter - - def asciiLetterOnly = new StringFilterDelegate with AsciiLetterOnlyStringFilter - - def asciiNumber = new StringFilterDelegate with AsciiNumberStringFilter - - def asciiNumberOnly = new StringFilterDelegate with AsciiNumberOnlyStringFilter - - def asciiSpace = new StringFilterDelegate with AsciiSpaceStringFilter - - def asciiSymbol = new StringFilterDelegate with AsciiSymbolStringFilter - - def asciiSymbolOnly = new StringFilterDelegate with AsciiSymbolOnlyStringFilter - - def delegate = new StringFilterDelegate + lazy val asciiControl = new StringFilterDelegate with AsciiControlStringFilter + lazy val asciiControlOnly = new StringFilterDelegate with AsciiControlOnlyStringFilter + lazy val asciiLetterCase = new StringFilterDelegate with AsciiLetterCaseStringFilter + lazy val asciiLetterNumber = new StringFilterDelegate with AsciiLetterNumberStringFilter + lazy val asciiLetterNumberOnly = new StringFilterDelegate with AsciiLetterNumberOnlyStringFilter + lazy val asciiLetter = new StringFilterDelegate with AsciiLetterStringFilter + lazy val asciiLetterOnly = new StringFilterDelegate with AsciiLetterOnlyStringFilter + lazy val asciiNumber = new StringFilterDelegate with AsciiNumberStringFilter + lazy val asciiNumberOnly = new StringFilterDelegate with AsciiNumberOnlyStringFilter + lazy val asciiSpace = new StringFilterDelegate with AsciiSpaceStringFilter + lazy val asciiSymbol = new StringFilterDelegate with AsciiSymbolStringFilter + lazy val asciiSymbolOnly = new StringFilterDelegate with AsciiSymbolOnlyStringFilter + lazy val delegate = new StringFilterDelegate } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala index 418ec8b..f9b072b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala @@ -1,6 +1,6 @@ package com.rockymadden.stringmetric -import com.rockymadden.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric } +import com.rockymadden.stringmetric.phonetic._ import com.rockymadden.stringmetric.similarity._ trait StringMetric[R] extends Metric[String, R] { @@ -8,64 +8,60 @@ trait StringMetric[R] extends Metric[String, R] { } object StringMetric { + lazy val hamming = HammingMetric() + lazy val jaro = JaroMetric() + lazy val jaroWinkler = JaroWinklerMetric() + lazy val levenshtein = LevenshteinMetric() + lazy val metaphone = MetaphoneMetric() + lazy val nysiis = NysiisMetric() + lazy val refinedNysiis = RefinedNysiisMetric() + lazy val refinedSoundex = RefinedSoundexMetric() + lazy val soundex = SoundexMetric() + def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = - HammingMetric().compare(charArray1, charArray2) + hamming.compare(charArray1, charArray2) - def compareWithHamming(string1: String, string2: String): Option[Int] = HammingMetric().compare(string1, string2) + def compareWithHamming(string1: String, string2: String): Option[Int] = hamming.compare(string1, string2) def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = - JaroMetric().compare(charArray1, charArray2) + jaro.compare(charArray1, charArray2) - def compareWithJaro(string1: String, string2: String): Option[Double] = JaroMetric().compare(string1, string2) + def compareWithJaro(string1: String, string2: String): Option[Double] = jaro.compare(string1, string2) def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = - JaroWinklerMetric().compare(charArray1, charArray2) + jaroWinkler.compare(charArray1, charArray2) - def compareWithJaroWinkler(string1: String, string2: String): Option[Double] = - JaroWinklerMetric().compare(string1, string2) + def compareWithJaroWinkler(string1: String, string2: String): Option[Double] = jaroWinkler.compare(string1, string2) def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = - LevenshteinMetric().compare(charArray1, charArray2) + levenshtein.compare(charArray1, charArray2) - def compareWithLevenshtein(string1: String, string2: String): Option[Int] = - LevenshteinMetric().compare(string1, string2) + def compareWithLevenshtein(string1: String, string2: String): Option[Int] = levenshtein.compare(string1, string2) def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - MetaphoneMetric().compare(charArray1, charArray2) + metaphone.compare(charArray1, charArray2) - def compareWithMetaphone(string1: String, string2: String): Option[Boolean] = - MetaphoneMetric().compare(string1, string2) + def compareWithMetaphone(string1: String, string2: String): Option[Boolean] = metaphone.compare(string1, string2) def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - NysiisMetric().compare(charArray1, charArray2) + nysiis.compare(charArray1, charArray2) + + def compareWithNysiis(string1: String, string2: String): Option[Boolean] = nysiis.compare(string1, string2) + + def compareWithRefinedNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = + refinedNysiis.compare(charArray1, charArray2) - def compareWithNysiis(string1: String, string2: String): Option[Boolean] = NysiisMetric().compare(string1, string2) + def compareWithRefinedNysiis(string1: String, string2: String): Option[Boolean] = + refinedNysiis.compare(string1, string2) def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - RefinedSoundexMetric().compare(charArray1, charArray2) + refinedSoundex.compare(charArray1, charArray2) def compareWithRefinedSoundex(string1: String, string2: String): Option[Boolean] = - RefinedSoundexMetric().compare(string1, string2) + refinedSoundex.compare(string1, string2) def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = - SoundexMetric().compare(charArray1, charArray2) - - def compareWithSoundex(string1: String, string2: String): Option[Boolean] = - SoundexMetric().compare(string1, string2) - - def hamming: HammingMetric.type = HammingMetric - - def jaro: JaroMetric.type = JaroMetric - - def jaroWinkler: JaroWinklerMetric.type = JaroWinklerMetric - - def levenshtein: LevenshteinMetric.type = LevenshteinMetric - - def metaphone: MetaphoneMetric.type = MetaphoneMetric - - def nysiis: NysiisMetric.type = NysiisMetric - - def refinedSoundex: RefinedSoundexMetric.type = RefinedSoundexMetric + soundex.compare(charArray1, charArray2) - def soundex: SoundexMetric.type = SoundexMetric + def compareWithSoundex(string1: String, string2: String): Option[Boolean] = soundex.compare(string1, string2) } |