summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2012-11-18 19:31:32 -0700
committerRocky Madden <git@rockymadden.com>2012-11-18 19:31:32 -0700
commit72dfa5ebe75b707f192cbe65c23393d08dbd8f8a (patch)
treed14db05d2a671f9e6cf9c0cb4c139003f36a8e50 /cli
parenta40947a8554332e97d05db8850ab1b6cd0540d9a (diff)
downloadstringmetric-72dfa5ebe75b707f192cbe65c23393d08dbd8f8a.tar.gz
stringmetric-72dfa5ebe75b707f192cbe65c23393d08dbd8f8a.tar.bz2
stringmetric-72dfa5ebe75b707f192cbe65c23393d08dbd8f8a.zip
Created refined NYSIIS algorithm, metric, commands, and specs.
Diffstat (limited to 'cli')
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala50
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala54
-rwxr-xr-xcli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithmSpec.scala39
-rwxr-xr-xcli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetricSpec.scala46
4 files changed, 189 insertions, 0 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala
new file mode 100755
index 0000000..9953116
--- /dev/null
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala
@@ -0,0 +1,50 @@
+package org.hashtree.stringmetric.cli.phonetic
+
+import org.hashtree.stringmetric.cli._
+import org.hashtree.stringmetric.phonetic.RefinedNysiisAlgorithm
+
+/**
+ * The refinedNysiisAlgorithm [[org.hashtree.stringmetric.cli.Command]]. Returns the phonetic representation of the
+ * passed string, per the refined NYSIIS algorithm.
+ */
+object refinedNysiisAlgorithm 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 NYSIIS algorithm." + ls + ls +
+ "Syntax:" + ls +
+ tab + "refinedNysiisAlgorithm [Options] string..." + ls + ls +
+ "Options:" + ls +
+ tab + "-h, --help" + ls +
+ tab + tab + "Outputs description, syntax, and options."
+ )
+ }
+
+ override def execute(options: OptionMap): Unit =
+ println(
+ RefinedNysiisAlgorithm.compute(
+ options('dashless)
+ ).getOrElse("not computable").toString
+ )
+} \ No newline at end of file
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala
new file mode 100755
index 0000000..b09075a
--- /dev/null
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala
@@ -0,0 +1,54 @@
+package org.hashtree.stringmetric.cli.phonetic
+
+import org.hashtree.stringmetric.cli._
+import org.hashtree.stringmetric.phonetic.RefinedNysiisMetric
+
+/**
+ * The refinedNysiisMetric [[org.hashtree.stringmetric.cli.Command]]. Compares two strings to determine if they are
+ * phonetically similarly, per the refined NYSIIS algorithm.
+ */
+object refinedNysiisMetric 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(_ == ' ') == 1) {
+ 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(
+ "Compares two strings to determine if they are phonetically similarly, per the refined NYSIIS algorithm." + ls + ls +
+ "Syntax:" + ls +
+ tab + "refinedNysiisMetric [Options] string1 string2..." + ls + ls +
+ "Options:" + ls +
+ tab + "-h, --help" + ls +
+ tab + tab + "Outputs description, syntax, and options."
+ )
+ }
+
+ override def execute(options: OptionMap): Unit = {
+ val strings = options('dashless).split(" ")
+
+ println(
+ RefinedNysiisMetric.compare(
+ strings(0),
+ strings(1)
+ ).getOrElse("not comparable").toString
+ )
+ }
+} \ No newline at end of file
diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithmSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithmSpec.scala
new file mode 100755
index 0000000..2567221
--- /dev/null
+++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithmSpec.scala
@@ -0,0 +1,39 @@
+package org.hashtree.stringmetric.cli.phonetic
+
+import org.hashtree.stringmetric.ScalaTest
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+final class refinedNysiisAlgorithmSpec extends ScalaTest {
+ "refinedNysiisAlgorithm" should provide {
+ "main method" when passed {
+ "valid dashless argument" should executes {
+ "print phonetic representation" in {
+ val out = new java.io.ByteArrayOutputStream()
+
+ Console.withOut(out)(
+ refinedNysiisAlgorithm.main(Array("--unitTest", "--debug", "abc"))
+ )
+
+ out.toString should equal ("abc\n")
+ out.reset()
+
+ Console.withOut(out)(
+ refinedNysiisAlgorithm.main(Array("--unitTest", "--debug", "1"))
+ )
+
+ out.toString should equal ("not computable\n")
+ out.reset()
+ }
+ }
+ "no dashless argument" should throws {
+ "IllegalArgumentException" in {
+ evaluating {
+ refinedNysiisAlgorithm.main(Array("--unitTest", "--debug"))
+ } should produce [IllegalArgumentException]
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetricSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetricSpec.scala
new file mode 100755
index 0000000..eddee0a
--- /dev/null
+++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetricSpec.scala
@@ -0,0 +1,46 @@
+package org.hashtree.stringmetric.cli.phonetic
+
+import org.hashtree.stringmetric.ScalaTest
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+final class refinedNysiisMetricSpec extends ScalaTest {
+ "refinedNysiisMetric" should provide {
+ "main method" when passed {
+ "valid dashless arguments" should executes {
+ "print if they are a match" in {
+ val out = new java.io.ByteArrayOutputStream()
+
+ Console.withOut(out)(
+ refinedNysiisMetric.main(Array("--unitTest", "--debug", "abc", "abc"))
+ )
+
+ out.toString should equal ("true\n")
+ out.reset()
+
+ Console.withOut(out)(
+ refinedNysiisMetric.main(Array("--unitTest", "--debug", "abc", "xyz"))
+ )
+
+ out.toString should equal ("false\n")
+ out.reset()
+
+ Console.withOut(out)(
+ refinedNysiisMetric.main(Array("--unitTest", "--debug", "1", "1"))
+ )
+
+ out.toString should equal ("not comparable\n")
+ out.reset()
+ }
+ }
+ "no dashless arguments" should throws {
+ "IllegalArgumentException" in {
+ evaluating {
+ refinedNysiisMetric.main(Array("--unitTest", "--debug"))
+ } should produce [IllegalArgumentException]
+ }
+ }
+ }
+ }
+} \ No newline at end of file