summaryrefslogtreecommitdiff
path: root/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala
diff options
context:
space:
mode:
Diffstat (limited to 'cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala')
-rwxr-xr-xcli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala54
1 files changed, 54 insertions, 0 deletions
diff --git a/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala b/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala
new file mode 100755
index 0000000..58ea028
--- /dev/null
+++ b/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/nGramAlgorithm.scala
@@ -0,0 +1,54 @@
+package com.rockymadden.stringmetric.cli.similarity
+
+import com.rockymadden.stringmetric.cli._
+import com.rockymadden.stringmetric.similarity.NGramAlgorithm
+
+/**
+ * The nGramAlgorithm [[com.rockymadden.stringmetric.cli.Command]]. Returns the N-Gram representation of the passed string.
+ */
+object nGramAlgorithm extends Command {
+ override def main(args: Array[String]): Unit = {
+ val options = OptionMap(args)
+
+ try {
+ // Help.
+ if (options.contains('h) || options.contains('help)) {
+ help()
+ exit(options)
+ // Execute.
+ } else if (options.contains('dashless) && (options('dashless): OptionMapArray).length == 1
+ && options.contains('n) && (options('n): OptionMapInt).isDefined
+ ) {
+ 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 N-Gram representation of the passed string." + ls + ls +
+ "Syntax:" + ls +
+ tab + "nGramAlgorithm [Options] string..." + ls + ls +
+ "Options:" + ls +
+ tab + "-h, --help" + ls +
+ tab + tab + "Outputs description, syntax, and options." +
+ tab + "--n" + ls +
+ tab + tab + "The n."
+ )
+ }
+
+ override def execute(options: OptionMap): Unit = {
+ val n: OptionMapInt = options('n)
+
+ println(
+ NGramAlgorithm.compute(options('dashless))(n).map(_.mkString("|")).getOrElse("not computable")
+ )
+ }
+} \ No newline at end of file