diff options
author | Rocky Madden <git@rockymadden.com> | 2012-10-15 18:17:09 -0600 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-10-15 18:17:09 -0600 |
commit | a2afc6432e3d7410e5468c0a1cfb312e4ad1c273 (patch) | |
tree | bb6fdd5ec5d0b99bc55579051123e0d86ad97b81 /core | |
parent | c569935cb9d69c814551ea95b4c17010e10a41a8 (diff) | |
download | stringmetric-a2afc6432e3d7410e5468c0a1cfb312e4ad1c273.tar.gz stringmetric-a2afc6432e3d7410e5468c0a1cfb312e4ad1c273.tar.bz2 stringmetric-a2afc6432e3d7410e5468c0a1cfb312e4ad1c273.zip |
Format clean up.
Diffstat (limited to 'core')
5 files changed, 24 insertions, 47 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala b/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala index b3663b2..e0a35ed 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala @@ -5,16 +5,10 @@ trait CaseStringCleaner extends StringCleaner { abstract override def clean(charArray: Array[Char]): Array[Char] = { super.clean( charArray.map { c => - if (c >= 65 && c <= 90) { - (c + 32).toChar - } else { - c - } + if (c >= 65 && c <= 90) (c + 32).toChar else c } ) } - abstract override def clean(string: String): String = { - super.clean(string.toLowerCase) - } + abstract override def clean(string: String): String = super.clean(string.toLowerCase) }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/JaroMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/JaroMetric.scala index 0161212..903126a 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/JaroMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/JaroMetric.scala @@ -44,9 +44,8 @@ object JaroMetric extends StringMetric { val start = if (i - window <= 0) 0 else i - window val end = if (i + window >= ct._2.length - 1) ct._2.length - 1 else i + window - if (start > ct._2.length - 1) { - bi = !bi - } else { + if (start > ct._2.length - 1) bi = !bi + else { var ii = start var bii = false diff --git a/core/source/core/scala/org/hashtree/stringmetric/SoundexMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/SoundexMetric.scala index 40de464..322d54e 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/SoundexMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/SoundexMetric.scala @@ -15,7 +15,7 @@ object SoundexMetric extends StringMetric { compare(string1.toCharArray, string2.toCharArray) } - private[this] def soundex(charArray: Array[Char]): Option[String] = { + private[this] def soundex(charArray: Array[Char]) = { require(charArray.length > 0) @tailrec @@ -24,13 +24,7 @@ object SoundexMetric extends StringMetric { val c = ca.head.toLower - if (c >= 97 && c <= 122) { - Some((c, i)) - } else if (ca.length == 1) { - None - } else { - letter(ca.tail, i + 1) - } + if (c >= 97 && c <= 122) Some((c, i)) else if (ca.length == 1) None else letter(ca.tail, i + 1) } @tailrec @@ -58,40 +52,38 @@ object SoundexMetric extends StringMetric { case 'r' if pc != '6' => '6' case _ => '\0' } - val a = - p match { - // Code twice. - case 'a' | 'e' | 'i' | 'o' | 'u' | 'y' => m2(c) - // Code once. - case _ => m1( - c, + val a = p match { + // Code twice. + case 'a' | 'e' | 'i' | 'o' | 'u' | 'y' => m2(c) + // Code once. + case _ => { + m1(c, o.last match { case '1' | '2' | '3' | '4' | '5' | '6' => o.last case _ => m2(o.last) } ) } + } - if (i.length == 1 || (o.length == 3 && a != '\0')) { + if (i.length == 1 || (o.length == 3 && a != '\0')) if (a != '\0') o :+ a else o - } else { + else code(i.tail, c, if (a != '\0') o :+ a else o) - } } letter(charArray, 0) match { - case Some(l) => - if (charArray.length - 1 == l._2) { - Some(l._1 + "000") - } else { + case Some(l) => { + if (charArray.length - 1 == l._2) Some(l._1 + "000") + else { Some( - code( - charArray.takeRight(charArray.length - (l._2 + 1)), + code(charArray.takeRight(charArray.length - (l._2 + 1)), l._1, // Pass first letter. Array(l._1) // Pass array with first letter. ).mkString.padTo(4, '0') ) } + } case None => None } } diff --git a/core/source/core/scala/org/hashtree/stringmetric/SpaceStringCleaner.scala b/core/source/core/scala/org/hashtree/stringmetric/SpaceStringCleaner.scala index 50e2287..4128712 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/SpaceStringCleaner.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/SpaceStringCleaner.scala @@ -2,11 +2,7 @@ package org.hashtree.stringmetric /** A decorator [[org.hashtree.stringmetric.StringCleaner]]. Ensures the input spacing does not matter. */ trait SpaceStringCleaner extends StringCleaner { - abstract override def clean(charArray: Array[Char]): Array[Char] = { - super.clean(charArray.filter(_ != ' ')) - } + abstract override def clean(charArray: Array[Char]): Array[Char] = super.clean(charArray.filter(_ != ' ')) - abstract override def clean(string: String): String = { - super.clean(string.replaceAllLiterally(" ", "")) - } + abstract override def clean(string: String): String = super.clean(string.replaceAllLiterally(" ", "")) }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringCleanerDelegate.scala b/core/source/core/scala/org/hashtree/stringmetric/StringCleanerDelegate.scala index 70d5397..988715f 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringCleanerDelegate.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringCleanerDelegate.scala @@ -1,11 +1,7 @@ package org.hashtree.stringmetric class StringCleanerDelegate extends StringCleaner { - override def clean(charArray: Array[Char]): Array[Char] = { - charArray - } + override def clean(charArray: Array[Char]): Array[Char] = charArray - override def clean(string: String): String = { - string - } + override def clean(string: String): String = string }
\ No newline at end of file |