diff options
Diffstat (limited to 'cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/jaroMetric.scala')
-rwxr-xr-x | cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/jaroMetric.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/jaroMetric.scala b/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/jaroMetric.scala new file mode 100755 index 0000000..27f1e8c --- /dev/null +++ b/cli/source/core/scala/com/rockymadden/stringmetric/cli/similarity/jaroMetric.scala @@ -0,0 +1,51 @@ +package com.rockymadden.stringmetric.cli.similarity + +import com.rockymadden.stringmetric.cli._ +import com.rockymadden.stringmetric.similarity.JaroMetric + +/** The jaroMetric [[com.rockymadden.stringmetric.cli.Command]]. Compares two strings to calculate the Jaro distance. */ +object jaroMetric 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 == 2) { + 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 calculate the Jaro distance." + ls + ls + + "Syntax:" + ls + + tab + "jaroMetric [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: OptionMapArray = options('dashless) + + println( + JaroMetric.compare( + strings(0), + strings(1) + ).getOrElse("not comparable") + ) + } +}
\ No newline at end of file |