diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-09 15:36:59 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-09 15:36:59 -0700 |
commit | 60cbc08776285e5bef6aae41b7a323cb556406ff (patch) | |
tree | ec65a429d0271a8b3a51684d9cbfab8ac590a803 /cli/source | |
parent | 9f8194dc286ee89275cf37b87910dca240945b3e (diff) | |
download | stringmetric-60cbc08776285e5bef6aae41b7a323cb556406ff.tar.gz stringmetric-60cbc08776285e5bef6aae41b7a323cb556406ff.tar.bz2 stringmetric-60cbc08776285e5bef6aae41b7a323cb556406ff.zip |
Changed compare implemention. It is now required to specify the size of the n-gram. Typically, this was 2.
Diffstat (limited to 'cli/source')
2 files changed, 10 insertions, 5 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala index 229e989..de0b302 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala @@ -19,7 +19,9 @@ object diceSorensenMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1 && + options.contains('n) && ParseUtility.parseInt(options('n)).isDefined + ) { execute(options) exit(options) // Invalid syntax. @@ -39,18 +41,21 @@ object diceSorensenMetric extends Command { tab + "diceSorensenMetric [Options] string1 string2..." + ls + ls + "Options:" + ls + tab + "-h, --help" + ls + - tab + tab + "Outputs description, syntax, and options." + tab + tab + "Outputs description, syntax, and options." + + tab + "--n" + ls + + tab + tab + "The n, traditionally 2." ) } override def execute(options: OptionMap): Unit = { val strings = options('dashless).split(" ") + val n = ParseUtility.parseInt(options('n)).get println( DiceSorensenMetric.compare( strings(0), strings(1) - )(new StringFilterDelegate with AsciiLetterCaseStringFilter).getOrElse("not comparable").toString + )(n)(new StringFilterDelegate with AsciiLetterCaseStringFilter).getOrElse("not comparable").toString ) } }
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetricSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetricSpec.scala index d9e2cb0..1e2c286 100755 --- a/cli/source/test/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetricSpec.scala +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetricSpec.scala @@ -13,14 +13,14 @@ final class diceSorensenMetricSpec extends ScalaTest { val out = new java.io.ByteArrayOutputStream() Console.withOut(out)( - diceSorensenMetric.main(Array("--unitTest", "--debug", "aBc", "abc")) + diceSorensenMetric.main(Array("--unitTest", "--debug", "--n=2", "aBc", "abc")) ) out.toString should equal ("1.0\n") out.reset() Console.withOut(out)( - diceSorensenMetric.main(Array("--unitTest", "--debug", "aBc", "xyz")) + diceSorensenMetric.main(Array("--unitTest", "--debug", "--n=2", "aBc", "xyz")) ) out.toString should equal ("0.0\n") |