summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2012-11-19 15:47:56 -0700
committerRocky Madden <git@rockymadden.com>2012-11-19 15:47:56 -0700
commit872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33 (patch)
treeae89eeda7bb0b92afc6b8bdaacedbb2978929681 /core
parente347105de2d80527592533bc060d53de09c7fb78 (diff)
downloadstringmetric-872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33.tar.gz
stringmetric-872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33.tar.bz2
stringmetric-872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33.zip
Condense code.
Diffstat (limited to 'core')
-rwxr-xr-xcore/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala67
-rwxr-xr-xcore/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala18
-rwxr-xr-xcore/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala18
3 files changed, 36 insertions, 67 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 e69cb22..d6ecd51 100755
--- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala
+++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala
@@ -55,69 +55,42 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm
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' =>
- 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')
- shift(3, o :+ 'x')
+ 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') shift(3, o :+ 'x')
else if ((r.length >= 1 && r.head == 'h')
- || (l.length >= 1 && r.length >= 1 && l.last == 's' && r.head == 'h')
- )
- shift(2, o :+ 'x')
+ || (l.length >= 1 && r.length >= 1 && l.last == 's' && r.head == 'h')) shift(2, o :+ 'x')
else if (l.length >= 1 && r.length >= 1 && l.last == 's'
- && (r.head == 'i' || r.head == 'e' || r.head == 'y')
- )
- shift(1, o)
- else if (r.length >= 1 && (r.head == 'i' || r.head == 'e' || r.head == 'y'))
- shift(1, o :+ 's')
- else
- shift(1, o :+ 'k')
+ && (r.head == 'i' || r.head == 'e' || r.head == 'y')) shift(1, o)
+ else if (r.length >= 1 && (r.head == 'i' || r.head == 'e' || r.head == 'y')) shift(1, o :+ 's')
+ else shift(1, o :+ 'k')
case 'd' =>
if (r.length >= 2 && r.head == 'g'
- && (r(1) == 'e' || r(1) == 'y' || r(1) == 'i')
- )
- shift(1, o :+ 'j')
- else
- shift(1, o :+ 't')
+ && (r(1) == 'e' || r(1) == 'y' || r(1) == 'i')) shift(1, o :+ 'j')
+ else shift(1, o :+ 't')
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')
- )
- shift(1, o)
- else if (r.length >= 1 && (r.head == 'i' || r.head == 'e' || r.head == 'y'))
- shift(2, o :+ 'j')
- else
- shift(1, o :+ 'k')
+ || (r.length == 3 && r.head == 'n' && r(1) == 'e' && r(2) == 'd')) shift(1, o)
+ else if (r.length >= 1 && (r.head == 'i' || r.head == 'e' || r.head == 'y')) shift(2, o :+ 'j')
+ else shift(1, o :+ 'k')
case 'h' =>
if ((l.length >= 1 && Alphabet.isVowel(l.last) && (r.length == 0 || !Alphabet.isVowel(r.head)))
|| (l.length >= 2 && l.last == 'h'
&& (l(l.length - 2) == 'c' || l(l.length - 2) == 's' || l(l.length - 2) == 'p'
- || l(l.length - 2) == 't' || l(l.length - 2) == 'g'
- )
- )
- )
- shift(1, o)
- else
- shift(1, o :+ 'h')
+ || l(l.length - 2) == 't' || l(l.length - 2) == 'g'))) 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' =>
- 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')
+ 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' =>
- 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')
- shift(2, o :+ '0')
- else if (r.length >= 2 && r.head == 'c' && r(1) == 'h')
- shift(1, o)
- else
- shift(1, o :+ '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') shift(2, o :+ '0')
+ else if (r.length >= 2 && r.head == 'c' && r(1) == 'h') shift(1, o)
+ else shift(1, o :+ 't')
case 'v' => shift(1, o :+ 'f')
case 'w' | 'y' => if (r.length == 0 || !Alphabet.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/RefinedSoundexAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala
index a0ea389..5391eef 100755
--- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala
+++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/RefinedSoundexAlgorithm.scala
@@ -63,17 +63,15 @@ object RefinedSoundexAlgorithm extends StringAlgorithm with FilterableStringAlgo
}
val a =
// Code twice.
- if (o.length == 1)
- m2(c)
+ if (o.length == 1) m2(c)
// Code once.
- else
- m1(
- c,
- o.last match {
- case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => o.last
- case _ => m2(o.last)
- }
- )
+ else m1(
+ c,
+ o.last match {
+ case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => o.last
+ case _ => m2(o.last)
+ }
+ )
transcode(i.tail, c, if (a != '\0') o :+ a else o)
}
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 c5d099f..b40d83d 100755
--- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala
+++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/SoundexAlgorithm.scala
@@ -57,19 +57,17 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
// 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)
- }
- )
+ case _ => m1(
+ c,
+ o.last match {
+ case '1' | '2' | '3' | '4' | '5' | '6' => o.last
+ case _ => m2(o.last)
+ }
+ )
}
if (o.length == 3 && a != '\0') o :+ a
- else
- transcode(i.tail, c, if (a != '\0') o :+ a else o)
+ else transcode(i.tail, c, if (a != '\0') o :+ a else o)
}
}
} \ No newline at end of file