summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2012-11-19 15:48:57 -0700
committerRocky Madden <git@rockymadden.com>2012-11-19 15:48:57 -0700
commit2df22ead075c51e36a4df8a65ecd6a5282a85460 (patch)
tree5b4b22263be040bc8c453ef4d4f1ae47c71316b3
parent872935ffc2bd1f7dd6f5f4d0806e3de56f9b7f33 (diff)
downloadstringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.tar.gz
stringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.tar.bz2
stringmetric-2df22ead075c51e36a4df8a65ecd6a5282a85460.zip
Refactored method.
-rwxr-xr-xcore/source/core/scala/org/hashtree/stringmetric/phonetic/MetaphoneAlgorithm.scala25
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