diff options
Diffstat (limited to 'cli/source')
8 files changed, 364 insertions, 0 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphone.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphone.scala new file mode 100755 index 0000000..c915a84 --- /dev/null +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphone.scala @@ -0,0 +1,52 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.StringFilterDelegate +import org.hashtree.stringmetric.cli._ +import org.hashtree.stringmetric.cli.command._ +import org.hashtree.stringmetric.phonetic.Metaphone + +/** + * The Metaphone [[org.hashtree.stringmetric.cli.command.Command]]. Returns the phonetic representation of the + * passed string, per the Metaphone algorithm. + */ +object metaphone extends Command { + override def main(args: Array[String]): Unit = { + val options = OptionMapUtility.toOptionMap(args) + + try { + // Help. + if (options.contains('h) || options.contains('help)) { + help() + exit(options) + // Execute. + } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + execute(options) + exit(options) + // Invalid syntax. + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") + } catch { + case e => error(e)(options) + } + } + + override def help(): Unit = { + val ls = sys.props("line.separator") + val tab = " " + + println( + "Returns the phonetic representation of the passed string, per the Metaphone algorithm." + ls + ls + + "Syntax:" + ls + + tab + "metaphone [Options] string..." + ls + ls + + "Options:" + ls + + tab + "-h, --help" + ls + + tab + tab + "Outputs description, syntax, and options." + ) + } + + override def execute(options: OptionMap): Unit = + println( + Metaphone.compute( + options('dashless) + )(new StringFilterDelegate).getOrElse("not computable").toString + ) +}
\ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiis.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiis.scala new file mode 100755 index 0000000..f9f624e --- /dev/null +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiis.scala @@ -0,0 +1,52 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.StringFilterDelegate +import org.hashtree.stringmetric.cli._ +import org.hashtree.stringmetric.cli.command._ +import org.hashtree.stringmetric.phonetic.Nysiis + +/** + * The NYSIIS [[org.hashtree.stringmetric.cli.command.Command]]. Returns the phonetic representation of the + * passed string, per the NYSIIS algorithm. + */ +object nysiis extends Command { + override def main(args: Array[String]): Unit = { + val options = OptionMapUtility.toOptionMap(args) + + try { + // Help. + if (options.contains('h) || options.contains('help)) { + help() + exit(options) + // Execute. + } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + execute(options) + exit(options) + // Invalid syntax. + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") + } catch { + case e => error(e)(options) + } + } + + override def help(): Unit = { + val ls = sys.props("line.separator") + val tab = " " + + println( + "Returns the phonetic representation of the passed string, per the NYSIIS algorithm." + ls + ls + + "Syntax:" + ls + + tab + "nysiis [Options] string..." + ls + ls + + "Options:" + ls + + tab + "-h, --help" + ls + + tab + tab + "Outputs description, syntax, and options." + ) + } + + override def execute(options: OptionMap): Unit = + println( + Nysiis.compute( + options('dashless) + )(new StringFilterDelegate).getOrElse("not computable").toString + ) +}
\ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/refinedSoundex.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/refinedSoundex.scala new file mode 100755 index 0000000..f1b4123 --- /dev/null +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/refinedSoundex.scala @@ -0,0 +1,52 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.StringFilterDelegate +import org.hashtree.stringmetric.cli._ +import org.hashtree.stringmetric.cli.command._ +import org.hashtree.stringmetric.phonetic.RefinedSoundex + +/** + * The refined Soundex [[org.hashtree.stringmetric.cli.command.Command]]. Returns the phonetic representation of the + * passed string, per the refined Soundex algorithm. + */ +object refinedSoundex extends Command { + override def main(args: Array[String]): Unit = { + val options = OptionMapUtility.toOptionMap(args) + + try { + // Help. + if (options.contains('h) || options.contains('help)) { + help() + exit(options) + // Execute. + } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + execute(options) + exit(options) + // Invalid syntax. + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") + } catch { + case e => error(e)(options) + } + } + + override def help(): Unit = { + val ls = sys.props("line.separator") + val tab = " " + + println( + "Returns the phonetic representation of the passed string, per the refined Soundex algorithm." + ls + ls + + "Syntax:" + ls + + tab + "refinedSoundex [Options] string..." + ls + ls + + "Options:" + ls + + tab + "-h, --help" + ls + + tab + tab + "Outputs description, syntax, and options." + ) + } + + override def execute(options: OptionMap): Unit = + println( + RefinedSoundex.compute( + options('dashless) + )(new StringFilterDelegate).getOrElse("not computable").toString + ) +}
\ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundex.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundex.scala new file mode 100755 index 0000000..0a2ed0b --- /dev/null +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundex.scala @@ -0,0 +1,52 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.StringFilterDelegate +import org.hashtree.stringmetric.cli._ +import org.hashtree.stringmetric.cli.command._ +import org.hashtree.stringmetric.phonetic.Soundex + +/** + * The Soundex [[org.hashtree.stringmetric.cli.command.Command]]. Returns the phonetic representation of the + * passed string, per the Soundex algorithm. + */ +object soundex extends Command { + override def main(args: Array[String]): Unit = { + val options = OptionMapUtility.toOptionMap(args) + + try { + // Help. + if (options.contains('h) || options.contains('help)) { + help() + exit(options) + // Execute. + } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + execute(options) + exit(options) + // Invalid syntax. + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") + } catch { + case e => error(e)(options) + } + } + + override def help(): Unit = { + val ls = sys.props("line.separator") + val tab = " " + + println( + "Returns the phonetic representation of the passed string, per the Soundex algorithm." + ls + ls + + "Syntax:" + ls + + tab + "soundex [Options] string..." + ls + ls + + "Options:" + ls + + tab + "-h, --help" + ls + + tab + tab + "Outputs description, syntax, and options." + ) + } + + override def execute(options: OptionMap): Unit = + println( + Soundex.compute( + options('dashless) + )(new StringFilterDelegate).getOrElse("not computable").toString + ) +}
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/metaphoneSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/metaphoneSpec.scala new file mode 100755 index 0000000..38b07fb --- /dev/null +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/metaphoneSpec.scala @@ -0,0 +1,39 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class metaphoneSpec extends ScalaTest { + "metaphone" should provide { + "main method" when passed { + "valid dashless argument" should executes { + "print phonetic representation" in { + val out = new java.io.ByteArrayOutputStream() + + Console.withOut(out)( + metaphone.main(Array("--unitTest", "--debug", "aBc")) + ) + + out.toString should equal ("abk\n") + out.reset() + + Console.withOut(out)( + metaphone.main(Array("--unitTest", "--debug", "1")) + ) + + out.toString should equal ("not computable\n") + out.reset() + } + } + "no dashless argument" should throws { + "IllegalArgumentException" in { + evaluating { + metaphone.main(Array("--unitTest", "--debug")) + } should produce [IllegalArgumentException] + } + } + } + } +}
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/nysiisSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/nysiisSpec.scala new file mode 100755 index 0000000..eddf3da --- /dev/null +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/nysiisSpec.scala @@ -0,0 +1,39 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class nysiisSpec extends ScalaTest { + "nysiis" should provide { + "main method" when passed { + "valid dashless argument" should executes { + "print phonetic representation" in { + val out = new java.io.ByteArrayOutputStream() + + Console.withOut(out)( + nysiis.main(Array("--unitTest", "--debug", "aBc")) + ) + + out.toString should equal ("abc\n") + out.reset() + + Console.withOut(out)( + nysiis.main(Array("--unitTest", "--debug", "1")) + ) + + out.toString should equal ("not computable\n") + out.reset() + } + } + "no dashless argument" should throws { + "IllegalArgumentException" in { + evaluating { + nysiis.main(Array("--unitTest", "--debug")) + } should produce [IllegalArgumentException] + } + } + } + } +}
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/refinedSoundexSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/refinedSoundexSpec.scala new file mode 100755 index 0000000..ae338d1 --- /dev/null +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/refinedSoundexSpec.scala @@ -0,0 +1,39 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class refinedSoundexSpec extends ScalaTest { + "refinedSoundex" should provide { + "main method" when passed { + "valid dashless argument" should executes { + "print phonetic representation" in { + val out = new java.io.ByteArrayOutputStream() + + Console.withOut(out)( + refinedSoundex.main(Array("--unitTest", "--debug", "aBc")) + ) + + out.toString should equal ("a013\n") + out.reset() + + Console.withOut(out)( + refinedSoundex.main(Array("--unitTest", "--debug", "1")) + ) + + out.toString should equal ("not computable\n") + out.reset() + } + } + "no dashless argument" should throws { + "IllegalArgumentException" in { + evaluating { + refinedSoundex.main(Array("--unitTest", "--debug")) + } should produce [IllegalArgumentException] + } + } + } + } +}
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexSpec.scala new file mode 100755 index 0000000..c25191a --- /dev/null +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexSpec.scala @@ -0,0 +1,39 @@ +package org.hashtree.stringmetric.cli.command + +import org.hashtree.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class soundexSpec extends ScalaTest { + "soundex" should provide { + "main method" when passed { + "valid dashless argument" should executes { + "print phonetic representation" in { + val out = new java.io.ByteArrayOutputStream() + + Console.withOut(out)( + soundex.main(Array("--unitTest", "--debug", "aBc")) + ) + + out.toString should equal ("a120\n") + out.reset() + + Console.withOut(out)( + soundex.main(Array("--unitTest", "--debug", "1")) + ) + + out.toString should equal ("not computable\n") + out.reset() + } + } + "no dashless argument" should throws { + "IllegalArgumentException" in { + evaluating { + soundex.main(Array("--unitTest", "--debug")) + } should produce [IllegalArgumentException] + } + } + } + } +}
\ No newline at end of file |