diff options
author | Rocky Madden <git@rockymadden.com> | 2012-10-26 19:18:39 -0600 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-10-26 19:18:39 -0600 |
commit | b042c8d7210aba5e2a6d8c35f06f2ecfa80c73c9 (patch) | |
tree | 353ebee00afa4b2ea1ad1755a0cd2e723845dc6f /core | |
parent | d1f5fd5438a6867edf873399b4683b935b33a8ef (diff) | |
download | stringmetric-b042c8d7210aba5e2a6d8c35f06f2ecfa80c73c9.tar.gz stringmetric-b042c8d7210aba5e2a6d8c35f06f2ecfa80c73c9.tar.bz2 stringmetric-b042c8d7210aba5e2a6d8c35f06f2ecfa80c73c9.zip |
Changed return type from float to double.
Diffstat (limited to 'core')
6 files changed, 49 insertions, 49 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetric.scala index eed92f1..e7d3dbe 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetric.scala @@ -5,7 +5,7 @@ import scala.annotation.tailrec /** An implementation of the Dice, and Sorensen, [[org.hashtree.stringmetric.StringMetric]]. */ object DiceSorensenMetric extends StringMetric { - override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Float] = { + override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Double] = { val ca1 = stringCleaner.clean(charArray1) val ca2 = stringCleaner.clean(charArray2) @@ -14,12 +14,12 @@ object DiceSorensenMetric extends StringMetric { val b = bigrams(ca1, ca2) val ms = scoreMatches(b) - Some((2f * ms) / (b._1.length + b._2.length)) + Some((2d * ms) / (b._1.length + b._2.length)) } } - override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Float] = { - if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1f) + override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Double] = { + if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1d) else compare( stringCleaner.clean(string1.toCharArray), 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 2f196b4..8cc7b23 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroMetric.scala @@ -9,7 +9,7 @@ import scala.collection.mutable.{ ArrayBuffer, HashSet } * distance in these scenarios. */ object JaroMetric extends StringMetric { - override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Float] = { + override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Double] = { val ca1 = stringCleaner.clean(charArray1) val ca2 = stringCleaner.clean(charArray2) @@ -19,14 +19,14 @@ object JaroMetric extends StringMetric { val ms = scoreMatches((mt._1, mt._2)) val ts = scoreTranspositions((mt._1, mt._2)) - if (ms == 0) Some(0f) + if (ms == 0) Some(0d) else - Some(((ms.toFloat / ca1.length) + (ms.toFloat / ca2.length) + ((ms.toFloat - ts) / ms)) / 3) + Some(((ms.toDouble / ca1.length) + (ms.toDouble / ca2.length) + ((ms.toDouble - ts) / ms)) / 3) } } - override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Float] = { - if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1f) + override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Double] = { + if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1d) else compare( stringCleaner.clean(string1.toCharArray), @@ -35,7 +35,7 @@ object JaroMetric extends StringMetric { } private[this] def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = { - val window = math.abs((math.max(ct._1.length, ct._2.length) / 2f).floor.toInt - 1) + val window = math.abs((math.max(ct._1.length, ct._2.length) / 2d).floor.toInt - 1) val one = ArrayBuffer.empty[Int] val two = HashSet.empty[Int] var i = 0 @@ -74,6 +74,6 @@ object JaroMetric extends StringMetric { 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 / 2f).floor.toInt + (mt._1.zip(mt._2).filter(t => t._1 != t._2).length / 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 bc1adf7..fed4c6b 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetric.scala @@ -8,7 +8,7 @@ import org.hashtree.stringmetric.{ StringCleaner, StringCleanerDelegate, StringM * penalized distance in these scenarios (e.g. comparing henka and henkan distance is 0.9666 versus the typical 0.9722). */ object JaroWinklerMetric extends StringMetric { - override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Float] = { + override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringCleaner: StringCleaner): Option[Double] = { val ca1 = stringCleaner.clean(charArray1) val ca2 = stringCleaner.clean(charArray2) @@ -16,14 +16,14 @@ object JaroWinklerMetric extends StringMetric { case Some(jaro) => { val prefix = ca1.zip(ca2).takeWhile(t => t._1 == t._2).map(_._1) - Some(jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1f * (1 - jaro))) + Some(jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1d * (1 - jaro))) } case None => None } } - override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Float] = { - if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1f) + override def compare(string1: String, string2: String)(implicit stringCleaner: StringCleaner): Option[Double] = { + if (string1.length > 0 && string1.length == string2.length && string1 == string2) Some(1d) else compare( stringCleaner.clean(string1.toCharArray), diff --git a/core/source/test/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetricSpec.scala b/core/source/test/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetricSpec.scala index 1860984..70d2c25 100755 --- a/core/source/test/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetricSpec.scala +++ b/core/source/test/scala/org/hashtree/stringmetric/similarity/DiceSorensenMetricSpec.scala @@ -17,17 +17,17 @@ final class DiceSorensenMetricSpec extends ScalaTest { } "equal arguments" should returns { "1" in { - DiceSorensenMetric.compare("abc", "abc").get should be (1.0f) + DiceSorensenMetric.compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - DiceSorensenMetric.compare("abc", "xyz").get should be (0.0f) + DiceSorensenMetric.compare("abc", "xyz").get should be (0) } } "valid arguments" should returns { - "Float indicating distance" in { - DiceSorensenMetric.compare("night", "nacht").get should be (0.25f) + "Double indicating distance" in { + DiceSorensenMetric.compare("night", "nacht").get should be (0.25) } } } diff --git a/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroMetricSpec.scala b/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroMetricSpec.scala index 31f066c..8fd12b1 100755 --- a/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroMetricSpec.scala +++ b/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroMetricSpec.scala @@ -17,28 +17,28 @@ final class JaroMetricSpec extends ScalaTest { } "equal arguments" should returns { "1" in { - JaroMetric.compare("a", "a").get should be (1.0f) - JaroMetric.compare("abc", "abc").get should be (1.0f) + JaroMetric.compare("a", "a").get should be (1) + JaroMetric.compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - JaroMetric.compare("abc", "xyz").get should be (0.0f) + JaroMetric.compare("abc", "xyz").get should be (0) } } "valid arguments" should returns { - "Float indicating distance" in { - JaroMetric.compare("aa", "a").get should be (0.8333333f) - JaroMetric.compare("a", "aa").get should be (0.8333333f) - JaroMetric.compare("veryveryverylong", "v").get should be (0.6875f) - JaroMetric.compare("v", "veryveryverylong").get should be (0.6875f) - JaroMetric.compare("martha", "marhta").get should be (0.9444444f) - JaroMetric.compare("dwayne", "duane").get should be (0.82222223f) - JaroMetric.compare("dixon", "dicksonx").get should be (0.76666665f) - JaroMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333f) - JaroMetric.compare("jones", "johnson").get should be (0.79047614f) - JaroMetric.compare("henka", "henkan").get should be (0.9444444f) - JaroMetric.compare("fvie", "ten").get should be (0.0f) + "Double indicating distance" in { + JaroWinklerMetric.compare("aa", "a").get should be (0.8500000000000001) + JaroWinklerMetric.compare("a", "aa").get should be (0.8500000000000001) + JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875) + JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875) + JaroWinklerMetric.compare("martha", "marhta").get should be (0.9611111111111111) + JaroWinklerMetric.compare("dwayne", "duane").get should be (0.8400000000000001) + JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.8133333333333332) + JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809523809523) + JaroWinklerMetric.compare("henka", "henkan").get should be (0.9666666666666667) + JaroWinklerMetric.compare("fvie", "ten").get should be (0) JaroMetric.compare("zac ephron", "zac efron").get should be > JaroMetric.compare("zac ephron", "kai ephron").get diff --git a/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetricSpec.scala b/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetricSpec.scala index d118c48..a66e4b9 100755 --- a/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetricSpec.scala +++ b/core/source/test/scala/org/hashtree/stringmetric/similarity/JaroWinklerMetricSpec.scala @@ -17,28 +17,28 @@ final class JaroWinklerMetricSpec extends ScalaTest { } "equal arguments" should returns { "1" in { - JaroWinklerMetric.compare("a", "a").get should be (1.0f) - JaroWinklerMetric.compare("abc", "abc").get should be (1.0f) + JaroWinklerMetric.compare("a", "a").get should be (1) + JaroWinklerMetric.compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - JaroWinklerMetric.compare("abc", "xyz").get should be (0.0f) + JaroWinklerMetric.compare("abc", "xyz").get should be (0) } } "valid arguments" should returns { - "Float indicating distance" in { - JaroWinklerMetric.compare("aa", "a").get should be (0.84999996f) - JaroWinklerMetric.compare("a", "aa").get should be (0.84999996f) - JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875f) - JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875f) - JaroWinklerMetric.compare("martha", "marhta").get should be (0.96111107f) - JaroWinklerMetric.compare("dwayne", "duane").get should be (0.84000003f) - JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.81333333f) - JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333f) - JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809f) - JaroWinklerMetric.compare("henka", "henkan").get should be (0.96666664f) - JaroWinklerMetric.compare("fvie", "ten").get should be (0.0f) + "Double indicating distance" in { + JaroWinklerMetric.compare("aa", "a").get should be (0.8500000000000001) + JaroWinklerMetric.compare("a", "aa").get should be (0.8500000000000001) + JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875) + JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875) + JaroWinklerMetric.compare("martha", "marhta").get should be (0.9611111111111111) + JaroWinklerMetric.compare("dwayne", "duane").get should be (0.8400000000000001) + JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.8133333333333332) + JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809523809523) + JaroWinklerMetric.compare("henka", "henkan").get should be (0.9666666666666667) + JaroWinklerMetric.compare("fvie", "ten").get should be (0) JaroWinklerMetric.compare("zac ephron", "zac efron").get should be > JaroWinklerMetric.compare("zac ephron", "kai ephron").get |