blob: e09208ef341fe3e3670fd302a9bd123b7ddebe1e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 = OptionMap(args)
try {
// Help.
if (options.contains('h) || options.contains('help)) {
help()
exit(options)
// Execute.
} else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).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 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 = OptionMapArray(options('dashless))
println(
RefinedNysiisMetric.compare(
strings(0),
strings(1)
).getOrElse("not comparable")
)
}
}
|