diff options
author | Rocky Madden <git@rockymadden.com> | 2013-03-12 08:43:33 -0600 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-03-12 08:43:33 -0600 |
commit | 1d46bfe9879bb8de710835d1371489120289f251 (patch) | |
tree | 91ae592688f150ad134a86844543ae126a3257c5 /core/source | |
parent | b5885ff2aaa3a0509a03c08e790f7e2299ea6bf6 (diff) | |
download | stringmetric-1d46bfe9879bb8de710835d1371489120289f251.tar.gz stringmetric-1d46bfe9879bb8de710835d1371489120289f251.tar.bz2 stringmetric-1d46bfe9879bb8de710835d1371489120289f251.zip |
Fixed performance bug where filters were being called twice when strings were used.
Diffstat (limited to 'core/source')
20 files changed, 20 insertions, 20 deletions
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 61d7d60..6da2dbc 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -20,7 +20,7 @@ class MetaphoneAlgorithm extends StringAlgorithm[String] { } } - final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString) + final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) private[this] def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca 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 eb959dd..85f48d7 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala @@ -21,7 +21,7 @@ class MetaphoneMetric extends StringMetric[Boolean] { } final override def compare(string1: String, string2: String): Option[Boolean] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object MetaphoneMetric { 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 0beb2df..633dd23 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala @@ -29,7 +29,7 @@ class NysiisAlgorithm extends StringAlgorithm[String] { } } - final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString) + final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) private[this] def cleanLast(ca: Array[Char]) = if (ca.length == 0) ca 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 cddf91b..7483abd 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala @@ -29,7 +29,7 @@ class NysiisMetric extends StringMetric[Boolean] { } final override def compare(string1: String, string2: String): Option[Boolean] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object NysiisMetric { 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 5e88aae..a490b53 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala @@ -22,7 +22,7 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[String] { } } - final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString) + final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) private[this] def cleanLast(ca: Array[Char], s: Set[Char]) = if (ca.length == 0) ca 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 593cda4..f25a0a3 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala @@ -29,7 +29,7 @@ class RefinedNysiisMetric extends StringMetric[Boolean] { } final override def compare(string1: String, string2: String): Option[Boolean] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object RefinedNysiisMetric { 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 31d7980..d45431c 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala @@ -15,7 +15,7 @@ class RefinedSoundexAlgorithm extends StringAlgorithm[String] { else Some(transcode(fca, Array(fca.head.toLower))) } - final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString) + final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) @tailrec private[this] def transcode(i: Array[Char], o: Array[Char]): Array[Char] = { 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 b099564..c55dc5b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala @@ -22,7 +22,7 @@ class RefinedSoundexMetric extends StringMetric[Boolean] { } final override def compare(string1: String, string2: String): Option[Boolean] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object RefinedSoundexMetric { 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 6e1150a..aef70c6 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala @@ -19,7 +19,7 @@ class SoundexAlgorithm extends StringAlgorithm[String] { } } - final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString) + final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) @tailrec private[this] def transcode(i: Array[Char], pc: Char, o: Array[Char]): Array[Char] = { 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 d1f3c9b..6c760d7 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala @@ -22,7 +22,7 @@ class SoundexMetric extends StringMetric[Boolean] { } final override def compare(string1: String, string2: String): Option[Boolean] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object SoundexMetric { 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 6ab8662..9846aa5 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala @@ -31,7 +31,7 @@ class DiceSorensenMetric extends ConfigurableStringMetric[Double, Int] { } final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray))(n: Int) + compare(string1.toCharArray, string2.toCharArray)(n: Int) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } 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 61d3acd..038905d 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala @@ -16,7 +16,7 @@ class HammingMetric extends StringMetric[Int] { } final override def compare(string1: String, string2: String): Option[Int] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) private[this] def hamming(ct: CompareTuple[Char]) = { require(ct._1.length == ct._2.length) diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala index ccf5f29..178aecb 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala @@ -28,7 +28,7 @@ class JaccardMetric extends ConfigurableStringMetric[Double, Int] { } final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray))(n: Int) + compare(string1.toCharArray, string2.toCharArray)(n: Int) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } 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 706b0ed..2befe16 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala @@ -30,7 +30,7 @@ class JaroMetric extends StringMetric[Double] { } final override def compare(string1: String, string2: String): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) private[this] def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = { lazy val window = math.abs((math.max(ct._1.length, ct._2.length) / 2d).floor.toInt - 1) 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 273d69b..a6fbd78 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala @@ -26,7 +26,7 @@ class JaroWinklerMetric extends StringMetric[Double] { } final override def compare(string1: String, string2: String): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) } object JaroWinklerMetric { 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 ed4c71e..287d4e8 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala @@ -16,7 +16,7 @@ class LevenshteinMetric extends StringMetric[Int] { } final override def compare(string1: String, string2: String): Option[Int] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) private[this] def levenshtein(ct: CompareTuple[Char]) = { val m = Array.fill[Int](ct._1.length + 1, ct._2.length + 1)(-1) 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 e903ec6..e9b78ce 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala @@ -17,7 +17,7 @@ class NGramAlgorithm extends ConfigurableStringAlgorithm[Array[String], Int] { } final override def compute(string: String)(implicit n: Int): Option[Array[String]] = - compute(filter(string.toCharArray))(n).map(_.map(_.mkString)) + compute(string.toCharArray)(n).map(_.map(_.mkString)) @tailrec private[this] def sequence(i: Array[Char], o: Array[Array[Char]], n: Int): Array[Array[Char]] = { 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 c821f33..c4db257 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala @@ -29,7 +29,7 @@ class NGramMetric extends ConfigurableStringMetric[Double, Int] { } final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray))(n) + compare(string1.toCharArray, string2.toCharArray)(n) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } 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 3ae39a4..3a969d7 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala @@ -16,7 +16,7 @@ class RatcliffObershelpMetric extends StringMetric[Double] { } final override def compare(string1: String, string2: String): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray)) + compare(string1.toCharArray, string2.toCharArray) private[this] def longestCommonSubsequence(ct: CompareTuple[Char]) = { val m = Array.ofDim[Int](ct._1.length + 1, ct._2.length + 1) 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 b53a7ab..07c0d25 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala @@ -28,7 +28,7 @@ class WeightedLevenshteinMetric final override def compare(string1: String, string2: String) (implicit options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = - compare(filter(string1.toCharArray), filter(string2.toCharArray))(options) + compare(string1.toCharArray, string2.toCharArray)(options) private[this] def weightedLevenshtein(ct: CompareTuple[Char], w: (BigDecimal, BigDecimal, BigDecimal)) = { val m = Array.ofDim[BigDecimal](ct._1.length + 1, ct._2.length + 1) |