From a5933ea0602c129c7806338527d66d43ee7e0048 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Sat, 20 Oct 2012 16:00:06 -0600 Subject: Added ascii prefix to name to more accurately describe purpose. --- .../cli/command/diceSorensenMetric.scala | 4 +-- .../stringmetric/cli/command/hammingMetric.scala | 4 +-- .../stringmetric/cli/command/jaroMetric.scala | 4 +-- .../cli/command/jaroWinklerMetric.scala | 4 +-- .../cli/command/levenshteinMetric.scala | 4 +-- .../stringmetric/AsciiCaseStringCleaner.scala | 14 +++++++++ .../hashtree/stringmetric/CaseStringCleaner.scala | 14 --------- .../stringmetric/AsciiCaseStringCleanerSpec.scala | 36 ++++++++++++++++++++++ .../stringmetric/CaseStringCleanerSpec.scala | 36 ---------------------- 9 files changed, 60 insertions(+), 60 deletions(-) create mode 100755 core/source/core/scala/org/hashtree/stringmetric/AsciiCaseStringCleaner.scala delete mode 100755 core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala create mode 100755 core/source/test/scala/org/hashtree/stringmetric/AsciiCaseStringCleanerSpec.scala delete mode 100755 core/source/test/scala/org/hashtree/stringmetric/CaseStringCleanerSpec.scala diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala index 1e21a2d..3cb40a5 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala @@ -1,6 +1,6 @@ package org.hashtree.stringmetric.cli.command -import org.hashtree.stringmetric.{ CaseStringCleaner, StringCleanerDelegate } +import org.hashtree.stringmetric.{ AsciiCaseStringCleaner, StringCleanerDelegate } import org.hashtree.stringmetric.cli._ import org.hashtree.stringmetric.cli.command._ import org.hashtree.stringmetric.distance.DiceSorensenMetric @@ -52,7 +52,7 @@ object diceSorensenMetric extends Command { DiceSorensenMetric.compare( strings(0), strings(1) - )(new StringCleanerDelegate with CaseStringCleaner).getOrElse("not comparable").toString + )(new StringCleanerDelegate with AsciiCaseStringCleaner).getOrElse("not comparable").toString ) } } \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala index d0e121a..2de9e8e 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala @@ -1,6 +1,6 @@ package org.hashtree.stringmetric.cli.command -import org.hashtree.stringmetric.{ CaseStringCleaner, StringCleanerDelegate } +import org.hashtree.stringmetric.{ AsciiCaseStringCleaner, StringCleanerDelegate } import org.hashtree.stringmetric.cli._ import org.hashtree.stringmetric.cli.command._ import org.hashtree.stringmetric.distance.HammingMetric @@ -52,7 +52,7 @@ object hammingMetric extends Command { HammingMetric.compare( strings(0), strings(1) - )(new StringCleanerDelegate with CaseStringCleaner).getOrElse("not comparable").toString + )(new StringCleanerDelegate with AsciiCaseStringCleaner).getOrElse("not comparable").toString ) } } \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala index 86abdd5..a784214 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala @@ -1,6 +1,6 @@ package org.hashtree.stringmetric.cli.command -import org.hashtree.stringmetric.{ CaseStringCleaner, StringCleanerDelegate } +import org.hashtree.stringmetric.{ AsciiCaseStringCleaner, StringCleanerDelegate } import org.hashtree.stringmetric.cli._ import org.hashtree.stringmetric.cli.command._ import org.hashtree.stringmetric.distance.JaroMetric @@ -52,7 +52,7 @@ object jaroMetric extends Command { JaroMetric.compare( strings(0), strings(1) - )(new StringCleanerDelegate with CaseStringCleaner).getOrElse("not comparable").toString + )(new StringCleanerDelegate with AsciiCaseStringCleaner).getOrElse("not comparable").toString ) } } \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala index 564024d..d6b225e 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala @@ -1,6 +1,6 @@ package org.hashtree.stringmetric.cli.command -import org.hashtree.stringmetric.{ CaseStringCleaner, StringCleanerDelegate } +import org.hashtree.stringmetric.{ AsciiCaseStringCleaner, StringCleanerDelegate } import org.hashtree.stringmetric.cli._ import org.hashtree.stringmetric.cli.command._ import org.hashtree.stringmetric.distance.JaroWinklerMetric @@ -52,7 +52,7 @@ object jaroWinklerMetric extends Command { JaroWinklerMetric.compare( strings(0), strings(1) - )(new StringCleanerDelegate with CaseStringCleaner).getOrElse("not comparable").toString + )(new StringCleanerDelegate with AsciiCaseStringCleaner).getOrElse("not comparable").toString ) } } \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala index 3c7682a..6f963f1 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala @@ -1,6 +1,6 @@ package org.hashtree.stringmetric.cli.command -import org.hashtree.stringmetric.{ CaseStringCleaner, StringCleanerDelegate } +import org.hashtree.stringmetric.{ AsciiCaseStringCleaner, StringCleanerDelegate } import org.hashtree.stringmetric.cli._ import org.hashtree.stringmetric.cli.command._ import org.hashtree.stringmetric.distance.LevenshteinMetric @@ -53,7 +53,7 @@ object levenshteinMetric extends Command { LevenshteinMetric.compare( strings(0), strings(1) - )(new StringCleanerDelegate with CaseStringCleaner).getOrElse("not comparable").toString + )(new StringCleanerDelegate with AsciiCaseStringCleaner).getOrElse("not comparable").toString ) } } \ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/AsciiCaseStringCleaner.scala b/core/source/core/scala/org/hashtree/stringmetric/AsciiCaseStringCleaner.scala new file mode 100755 index 0000000..b70f15c --- /dev/null +++ b/core/source/core/scala/org/hashtree/stringmetric/AsciiCaseStringCleaner.scala @@ -0,0 +1,14 @@ +package org.hashtree.stringmetric + +/** A decorator [[org.hashtree.stringmetric.StringCleaner]]. Ensures the input case-sensitivity does not matter. */ +trait AsciiCaseStringCleaner extends StringCleaner { + abstract override def clean(charArray: Array[Char]): Array[Char] = { + super.clean( + charArray.map { c => + if (c >= 65 && c <= 90) (c + 32).toChar else c + } + ) + } + + abstract override def clean(string: String): String = super.clean(string.toLowerCase) +} \ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala b/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala deleted file mode 100755 index e0a35ed..0000000 --- a/core/source/core/scala/org/hashtree/stringmetric/CaseStringCleaner.scala +++ /dev/null @@ -1,14 +0,0 @@ -package org.hashtree.stringmetric - -/** A decorator [[org.hashtree.stringmetric.StringCleaner]]. Ensures the input case-sensitivity does not matter. */ -trait CaseStringCleaner extends StringCleaner { - abstract override def clean(charArray: Array[Char]): Array[Char] = { - super.clean( - charArray.map { c => - if (c >= 65 && c <= 90) (c + 32).toChar else c - } - ) - } - - abstract override def clean(string: String): String = super.clean(string.toLowerCase) -} \ No newline at end of file diff --git a/core/source/test/scala/org/hashtree/stringmetric/AsciiCaseStringCleanerSpec.scala b/core/source/test/scala/org/hashtree/stringmetric/AsciiCaseStringCleanerSpec.scala new file mode 100755 index 0000000..52239ba --- /dev/null +++ b/core/source/test/scala/org/hashtree/stringmetric/AsciiCaseStringCleanerSpec.scala @@ -0,0 +1,36 @@ +package org.hashtree.stringmetric + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiCaseStringCleanerSpec extends ScalaTest { + private final val Cleaner = new StringCleanerDelegate with AsciiCaseStringCleaner + + "AsciiCaseStringCleaner" should provide { + "overloaded clean method" when passed { + "String with mixed case" should returns { + "String with the same case" in { + Cleaner.clean("HelloWorld") should (equal ("helloworld") or equal ("HELLOWORLD")) + Cleaner.clean("Hello World") should (equal ("hello world") or equal ("HELLO WORLD")) + Cleaner.clean("H e l l o W o r l d") should + (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) + Cleaner.clean("H e l l o W o r l d") should + (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) + } + } + "character array with mixed case" should returns { + "character array with the same case" in { + Cleaner.clean("HelloWorld".toCharArray) should + (equal ("helloworld".toCharArray) or equal ("HELLOWORLD".toCharArray)) + Cleaner.clean("Hello World".toCharArray) should + (equal ("hello world".toCharArray) or equal ("HELLO WORLD".toCharArray)) + Cleaner.clean("H e l l o W o r l d".toCharArray) should + (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) + Cleaner.clean("H e l l o W o r l d".toCharArray) should + (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) + } + } + } + } +} \ No newline at end of file diff --git a/core/source/test/scala/org/hashtree/stringmetric/CaseStringCleanerSpec.scala b/core/source/test/scala/org/hashtree/stringmetric/CaseStringCleanerSpec.scala deleted file mode 100755 index a628700..0000000 --- a/core/source/test/scala/org/hashtree/stringmetric/CaseStringCleanerSpec.scala +++ /dev/null @@ -1,36 +0,0 @@ -package org.hashtree.stringmetric - -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class CaseStringCleanerSpec extends ScalaTest { - private final val Cleaner = new StringCleanerDelegate with CaseStringCleaner - - "CaseStringCleaner" should provide { - "overloaded clean method" when passed { - "String with mixed case" should returns { - "String with the same case" in { - Cleaner.clean("HelloWorld") should (equal ("helloworld") or equal ("HELLOWORLD")) - Cleaner.clean("Hello World") should (equal ("hello world") or equal ("HELLO WORLD")) - Cleaner.clean("H e l l o W o r l d") should - (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) - Cleaner.clean("H e l l o W o r l d") should - (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) - } - } - "character array with mixed case" should returns { - "character array with the same case" in { - Cleaner.clean("HelloWorld".toCharArray) should - (equal ("helloworld".toCharArray) or equal ("HELLOWORLD".toCharArray)) - Cleaner.clean("Hello World".toCharArray) should - (equal ("hello world".toCharArray) or equal ("HELLO WORLD".toCharArray)) - Cleaner.clean("H e l l o W o r l d".toCharArray) should - (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) - Cleaner.clean("H e l l o W o r l d".toCharArray) should - (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) - } - } - } - } -} \ No newline at end of file -- cgit v1.2.3