diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-19 15:48:57 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-19 15:48:57 -0700 |
commit | 2df22ead075c51e36a4df8a65ecd6a5282a85460 (patch) | |
tree | 5b4b22263be040bc8c453ef4d4f1ae47c71316b3 | |
parent | 872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33 (diff) | |
download | stringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.tar.gz stringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.tar.bz2 stringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.zip |
Refactored method.
-rwxr-xr-x | core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala | 25 |
1 files changed, 13 insertions, 12 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 d6ecd51..55632b6 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -104,17 +104,18 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm } private[this] def transcodeHead(ca: Array[Char]) = { - val h = ca.take(2).padTo(2, '\0') - - if ((h.head == 'a' && h.last == 'e') - || (h.last == 'n' && (h.head == 'g' || h.head == 'k' || h.head == 'p')) - || (h.head == 'w' && h.last == 'r') - ) - ca.tail - else if (h.head == 'w' && h.last == 'h') - 'w' +: ca.drop(2) - else if (h.head == 'x') - 's' +: ca.tail - else ca + if (ca.length == 0) ca + else if (ca.length == 1) if (ca.head == 'x') Array('s') else ca + else + ca.head match { + case 'a' if (ca(1) == 'e') => ca.tail + case 'g' if (ca(1) == 'n') => ca.tail + case 'k' if (ca(1) == 'n') => ca.tail + case 'p' if (ca(1) == 'n') => ca.tail + case 'w' if (ca(1) == 'r') => ca.tail + case 'w' if (ca(1) == 'h') => 'w' +: ca.drop(2) + case 'x' => 's' +: ca.tail + case _ => ca + } } }
\ No newline at end of file |