diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-12 12:14:32 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-12 12:14:32 -0700 |
commit | 3a69da3f7fb33b67643fa5d696b302303d829e4a (patch) | |
tree | 7cf70ec92b63d7a229266b1aa07911c4ca8933c7 /core | |
parent | 8efa9ddd03ed45849ee189639833a2a142fd4448 (diff) | |
download | stringmetric-3a69da3f7fb33b67643fa5d696b302303d829e4a.tar.gz stringmetric-3a69da3f7fb33b67643fa5d696b302303d829e4a.tar.bz2 stringmetric-3a69da3f7fb33b67643fa5d696b302303d829e4a.zip |
Minor performance enhancements.
Diffstat (limited to 'core')
3 files changed, 6 insertions, 6 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala index 1dcdf8c..fb51024 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala @@ -94,7 +94,7 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { private[this] def transcodeClean(ca: Array[Char]) = if (ca.length >= 1 && (ca.last == 'a' || ca.last == 's')) - ca.reverse.dropWhile(c => c == 'a' || c == 's').reverse + ca.dropRight(ca.reverseIterator.takeWhile(c => c == 'a' || c == 's').length) else if (ca.length >= 2 && ca.last == 'y' && ca(ca.length - 2) == 'a') ca.dropRight(2) :+ 'y' else ca @@ -111,7 +111,7 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { else if (h.head == 'k' && h(1) == 'n') Array('n', 'n') ++ ca.takeRight(ca.length - 2) else if (h.head == 'k') - Array('c') ++ ca.takeRight(ca.length - 1) + 'c' +: ca.takeRight(ca.length - 1) else ca } @@ -121,9 +121,9 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { if ((h.last == 't' && (h.head == 'd' || h.head == 'r' || h.head == 'n')) || (h.last == 'd' && (h.head == 'r' || h.head == 'n')) ) - Array('d') ++ ca.takeRight(ca.length - 2) + 'd' +: ca.takeRight(ca.length - 2) else if (h.last == 'e' && (h.head == 'i' || h.head == 'e')) - Array('y') ++ ca.takeRight(ca.length - 2) + 'y' +: ca.takeRight(ca.length - 2) else ca } }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala index 76ce822..e692641 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala @@ -74,6 +74,6 @@ object JaroMetric extends StringMetric with FilterableStringMetric { private[this] def scoreTranspositions(mt: MatchTuple[Char]) = { require(mt._1.length == mt._2.length) - (mt._1.zip(mt._2).filter(t => t._1 != t._2).length / 2d).floor.toInt + (mt._1.zip(mt._2).count(t => t._1 != t._2) / 2d).floor.toInt } }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala index e5f2c8e..a483897 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala @@ -18,7 +18,7 @@ object JaroWinklerMetric extends StringMetric with FilterableStringMetric { case Some(0d) => Some(0d) case Some(1d) => Some(1d) case Some(jaro) => { - val prefix = ca1.zip(ca2).takeWhile(t => t._1 == t._2).map(_._1) + val prefix = ca1.zip(ca2).takeWhile(t => t._1 == t._2) Some(jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1d * (1 - jaro))) } |