diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-12 10:51:13 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-12 10:51:13 -0700 |
commit | 8efa9ddd03ed45849ee189639833a2a142fd4448 (patch) | |
tree | 7679743fc4b35359a17e41a7f1761bf02ac51c8d /core | |
parent | 7d26908063bca251471a8e66420cc486b853ac67 (diff) | |
download | stringmetric-8efa9ddd03ed45849ee189639833a2a142fd4448.tar.gz stringmetric-8efa9ddd03ed45849ee189639833a2a142fd4448.tar.bz2 stringmetric-8efa9ddd03ed45849ee189639833a2a142fd4448.zip |
Code formatting tweaks.
Diffstat (limited to 'core')
6 files changed, 15 insertions, 30 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala index 20e752d..0387c86 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -56,7 +56,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm case 'a' | 'e' | 'i' | 'o' | 'u' => if (l.length == 0) shift(1, o:+ c) else shift(1, o) case 'f' | 'j' | 'l' | 'm' | 'n' | 'r' => shift(1, o :+ c) case 'b' => if (l.length >= 1 && l.last == 'm' && r.length == 0) shift(1, o) else shift(1, o :+ 'b') - case 'c' => { + case 'c' => if (r.length >= 1 && r.head == 'h' && l.length >= 1 && l.last == 's') shift(1, o :+ 'k') else if (r.length >= 2 && r.head == 'i' && r(1) == 'a') @@ -75,8 +75,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm shift(1, o :+ 's') else shift(1, o :+ 'k') - } - case 'd' => { + case 'd' => if (r.length >= 2 && r.head == 'g' && ( r(1) == 'e' || r(1) == 'y' || r(1) == 'i' ) @@ -84,8 +83,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm shift(1, o :+ 'j') else shift(1, o :+ 't') - } - case 'g' => { + case 'g' => if ((r.length > 1 && r.head == 'h') || (r.length == 1 && r.head == 'n') || (r.length == 3 && r.head == 'n' && r(1) == 'e' && r(2) == 'd') @@ -95,8 +93,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm shift(2, o :+ 'j') else shift(1, o :+ 'k') - } - case 'h' => { + case 'h' => if ((l.length >= 1 && isVowel(l.last) && (r.length == 0 || !isVowel(r.head))) || (l.length >= 2 && l.last == 'h' && ( l(l.length - 2) == 'c' || l(l.length - 2) == 's' || l(l.length - 2) == 'p' || @@ -107,19 +104,17 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm shift(1, o) else shift(1, o :+ 'h') - } case 'k' => if (l.length >= 1 && l.last == 'c') shift(1, o) else shift(1, o :+ 'k') case 'p' => if (r.length >= 1 && r.head == 'h') shift(2, o :+ 'f') else shift(1, o :+ 'p') case 'q' => shift(1, o :+ 'k') - case 's' => { + case 's' => if (r.length >= 2 && r.head == 'i' && (r(1) == 'o' || r(1) == 'a')) shift(3, o :+ 'x') else if (r.length >= 1 && r.head == 'h') shift(2, o :+ 'x') else shift(1, o :+ 's') - } - case 't' => { + case 't' => if (r.length >= 2 && r.head == 'i' && (r(1) == 'a' || r(1) == 'o')) shift(3, o :+ 'x') else if (r.length >= 1 && r.head == 'h') @@ -128,7 +123,6 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm shift(1, o) else shift(1, o :+ 't') - } case 'v' => shift(1, o :+ 'f') case 'w' | 'y' => if (r.length == 0 || !isVowel(r.head)) shift(1, o) else shift(1, o :+ c) case 'x' => shift(1, (o :+ 'k') :+ 's') 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 307f716..1dcdf8c 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala @@ -59,34 +59,30 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { c match { case 'a' | 'i' | 'o' | 'u' => shift(1, o :+ 'a') case 'b' | 'c' | 'd' | 'f' | 'g' | 'j' | 'l' | 'n' | 'r' | 't' | 'v' | 'x' | 'y' => shift(1, o :+ c) - case 'e' => { + case 'e' => if (r.length >= 1 && r.head == 'v') shift(2, o ++ Array('a', 'f')) else shift(1, o :+ 'a') - } - case 'h' => { + case 'h' => if (l.length >= 1 && (!isVowel(l.last) || (r.length >= 1 && !isVowel(r.head)))) shift(1, o :+ l.last) else shift(1, o :+ c) - } case 'k' => if (r.length >= 1 && r.head == 'n') shift(2, o :+ 'n') else shift(1, o :+ 'c') case 'm' => shift(1, o :+ 'n') case 'p' => if (r.length >= 1 && r.head == 'h') shift(2, o ++ Array('f', 'f')) else shift(1, o :+ 'p') case 'q' => shift(1, o :+ 'g') - case 's' => { + case 's' => if (r.length >= 2 && r.head == 'c' && r(1) == 'h') shift(3, o ++ Array('s', 's', 's')) else shift(1, o :+ c) - } - case 'w' => { + case 'w' => if (l.length >= 1 && !isVowel(l.last)) shift(1, o :+ l.last) else shift(1, o :+ c) - } case 'z' => shift(1, o :+ 's') case _ => shift(1, o) } diff --git a/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala index 7d0a367..1eec7ed 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala @@ -15,7 +15,7 @@ object RefinedSoundexAlgorithm extends StringAlgorithm with FilterableStringAlgo val fc = ca.head.toLower if (fc < 97 || fc > 122) None - else { + else Some( transcode( ca, @@ -23,7 +23,6 @@ object RefinedSoundexAlgorithm extends StringAlgorithm with FilterableStringAlgo Array(fc) // Pass array with first letter. ) ) - } } } diff --git a/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala index acd492c..57477cf 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala @@ -15,7 +15,7 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { val fc = ca.head.toLower if (fc < 97 || fc > 122) None - else { + else Some( transcode( ca.tail, @@ -23,7 +23,6 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { Array(fc) // Pass array with first letter. ).padTo(4, '0') ) - } } } @@ -62,7 +61,7 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { // Code twice. case 'a' | 'e' | 'i' | 'o' | 'u' | 'y' => m2(c) // Code once. - case _ => { + case _ => m1( c, o.last match { @@ -70,7 +69,6 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { case _ => m2(o.last) } ) - } } if (o.length == 3 && a != '\0') o :+ a diff --git a/core/source/core/scala/org/hashtree/stringmetric/similarity/LevenshteinMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/similarity/LevenshteinMetric.scala index a4dadd8..5a90ada 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/LevenshteinMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/LevenshteinMetric.scala @@ -34,7 +34,7 @@ object LevenshteinMetric extends StringMetric with FilterableStringMetric { val min = { if (ct._1(r - 1) == ct._2(c - 1)) distance(r - 1, c - 1) - else { + else math.min( math.min( distance(r - 1, c) + 1, // Delete (left). @@ -42,7 +42,6 @@ object LevenshteinMetric extends StringMetric with FilterableStringMetric { ), distance(r - 1, c - 1) + 1 // Substitute (left-up). ) - } } m(r)(c) = min diff --git a/core/source/core/scala/org/hashtree/stringmetric/similarity/WeightedLevenshteinMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/similarity/WeightedLevenshteinMetric.scala index 09f6d0f..47fb125 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/similarity/WeightedLevenshteinMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/similarity/WeightedLevenshteinMetric.scala @@ -39,13 +39,12 @@ object WeightedLevenshteinMetric extends StringMetric with FilterableConfigurabl m(r)(c) = { if (ct._1(r - 1) == ct._2(c - 1)) m(r - 1)(c - 1) - else { + else (m(r - 1)(c) + w._1).min( // Delete (left). (m(r)(c - 1) + w._2).min( // Insert (up). m(r - 1)(c - 1) + w._3 // Substitute (left-up). ) ) - } } } |