From 9b4a7bf6a2842058f1d0bf14db5c8f2544c4d50d Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Sun, 18 Nov 2012 11:23:43 -0700 Subject: Cleaned up method. --- .../hashtree/stringmetric/phonetic/NysiisAlgorithm.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core') 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 0ea3177..d40ebba 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/NysiisAlgorithm.scala @@ -40,11 +40,16 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm { } private[this] def cleanRight(ca: Array[Char]) = - if (ca.length >= 1 && (ca.last == 'a' || ca.last == 's')) - ca.dropRight(ca.reverseIterator.takeWhile(c => c == 'a' || c == 's').length) - else if (ca.length >= 2 && ca.last == 'y' && ca(ca.length - 2) == 'a') - ca.dropRight(2) :+ 'y' - else ca + if (ca.length == 0) ca + else + ca.last match { + // All vowels will be encoded as 'a' at the point this is called. + case 'a' | 's' => + ca.dropRight(ca.reverseIterator.takeWhile(c => c == 'a' || c == 's').length) + case 'y' if (ca.length >= 2 && ca(ca.length - 2) == 'a') => + ca.dropRight(2) :+ 'y' + case _ => ca + } private[this] def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca -- cgit v1.2.3