From ef997c15f2ac152b53f05669f1d6bb9aa00aded7 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Sat, 28 Dec 2013 11:49:33 -0700 Subject: A more functional structure. --- .../rockymadden/stringmetric/cli/OptionMap.scala | 36 --- .../stringmetric/cli/OptionString.scala | 30 --- .../com/rockymadden/stringmetric/cli/package.scala | 61 ++++- .../cli/similarity/dicesorensenmetric.scala | 2 +- .../cli/similarity/jaccardmetric.scala | 2 +- .../stringmetric/cli/similarity/ngrammetric.scala | 2 +- .../cli/similarity/overlapmetric.scala | 2 +- .../cli/similarity/weightedlevenshteinmetric.scala | 9 +- .../cli/tokenization/ngramtokenizer.scala | 2 +- .../com/rockymadden/stringmetric/Algorithm.scala | 11 +- .../com/rockymadden/stringmetric/Alphabet.scala | 77 +++--- .../com/rockymadden/stringmetric/Filter.scala | 5 - .../com/rockymadden/stringmetric/Filterable.scala | 5 - .../com/rockymadden/stringmetric/Metric.scala | 11 +- .../rockymadden/stringmetric/StringAlgorithm.scala | 42 --- .../rockymadden/stringmetric/StringFilter.scala | 45 ---- .../stringmetric/StringFilterable.scala | 5 - .../rockymadden/stringmetric/StringMetric.scala | 120 --------- .../rockymadden/stringmetric/StringTokenizer.scala | 14 - .../com/rockymadden/stringmetric/Tokenizer.scala | 11 +- .../stringmetric/filter/AsciiControlFilter.scala | 11 - .../filter/AsciiControlOnlyFilter.scala | 11 - .../stringmetric/filter/AsciiLetterFilter.scala | 11 - .../filter/AsciiLetterNumberFilter.scala | 15 -- .../filter/AsciiLetterNumberOnlyFilter.scala | 15 -- .../filter/AsciiLetterOnlyFilter.scala | 11 - .../stringmetric/filter/AsciiNumberFilter.scala | 11 - .../filter/AsciiNumberOnlyFilter.scala | 11 - .../stringmetric/filter/AsciiSpaceFilter.scala | 10 - .../stringmetric/filter/AsciiSymbolFilter.scala | 15 -- .../filter/AsciiSymbolOnlyFilter.scala | 15 -- .../filter/IgnoreAsciiLetterCaseFilter.scala | 11 - .../stringmetric/filter/StringFilterDelegate.scala | 9 - .../stringmetric/phonetic/MetaphoneAlgorithm.scala | 34 +-- .../stringmetric/phonetic/MetaphoneMetric.scala | 33 +-- .../stringmetric/phonetic/NysiisAlgorithm.scala | 40 +-- .../stringmetric/phonetic/NysiisMetric.scala | 34 +-- .../phonetic/RefinedNysiisAlgorithm.scala | 44 +--- .../phonetic/RefinedNysiisMetric.scala | 34 +-- .../phonetic/RefinedSoundexAlgorithm.scala | 31 +-- .../phonetic/RefinedSoundexMetric.scala | 35 +-- .../stringmetric/phonetic/SoundexAlgorithm.scala | 33 +-- .../stringmetric/phonetic/SoundexMetric.scala | 35 +-- .../similarity/DiceSorensenMetric.scala | 34 +-- .../stringmetric/similarity/HammingMetric.scala | 37 +-- .../stringmetric/similarity/JaccardMetric.scala | 34 +-- .../stringmetric/similarity/JaroMetric.scala | 49 +--- .../similarity/JaroWinklerMetric.scala | 29 +-- .../similarity/LevenshteinMetric.scala | 34 +-- .../stringmetric/similarity/NGramMetric.scala | 37 +-- .../stringmetric/similarity/OverlapMetric.scala | 39 +-- .../similarity/RatcliffObershelpMetric.scala | 36 +-- .../similarity/WeightedLevenshteinMetric.scala | 44 +--- .../stringmetric/tokenization/NGramTokenizer.scala | 28 +- .../stringmetric/FilterDecoratedSpec.scala | 38 --- .../stringmetric/StringAlgorithmSpec.scala | 59 ----- .../stringmetric/StringMetricSpec.scala | 141 ---------- .../stringmetric/StringTokenizerSpec.scala | 23 -- .../filter/AsciiControlFilterSpec.scala | 33 --- .../filter/AsciiControlOnlyFilterSpec.scala | 33 --- .../filter/AsciiLetterFilterSpec.scala | 29 --- .../filter/AsciiLetterNumberFilterSpec.scala | 33 --- .../filter/AsciiLetterNumberOnlyFilterSpec.scala | 35 --- .../filter/AsciiLetterOnlyFilterSpec.scala | 33 --- .../filter/AsciiNumberFilterSpec.scala | 33 --- .../filter/AsciiNumberOnlyFilterSpec.scala | 33 --- .../stringmetric/filter/AsciiSpaceFilterSpec.scala | 37 --- .../filter/AsciiSymbolFilterSpec.scala | 31 --- .../filter/AsciiSymbolOnlyFilterSpec.scala | 33 --- .../filter/IgnoreAsciiLetterCaseFilterSpec.scala | 41 --- .../filter/StringFilterDelegateSpec.scala | 31 --- .../phonetic/MetaphoneAlgorithmSpec.scala | 283 ++++++++++----------- .../phonetic/MetaphoneMetricSpec.scala | 37 +-- .../phonetic/NysiisAlgorithmSpec.scala | 223 ++++++++-------- .../stringmetric/phonetic/NysiisMetricSpec.scala | 29 +-- .../phonetic/RefinedNysiisAlgorithmSpec.scala | 253 +++++++++--------- .../phonetic/RefinedNysiisMetricSpec.scala | 29 +-- .../phonetic/RefinedSoundexAlgorithmSpec.scala | 177 ++++++------- .../phonetic/RefinedSoundexMetricSpec.scala | 29 +-- .../phonetic/SoundexAlgorithmSpec.scala | 175 ++++++------- .../stringmetric/phonetic/SoundexMetricSpec.scala | 29 +-- .../similarity/DiceSorensenMetricSpec.scala | 67 ++--- .../similarity/HammingMetricSpec.scala | 33 +-- .../similarity/JaccardMetricSpec.scala | 73 +++--- .../stringmetric/similarity/JaroMetricSpec.scala | 59 ++--- .../similarity/JaroWinklerMetricSpec.scala | 59 ++--- .../similarity/LevenshteinMetricSpec.scala | 59 ++--- .../stringmetric/similarity/NGramMetricSpec.scala | 67 ++--- .../similarity/OverlapMetricSpec.scala | 71 +++--- .../similarity/RatcliffObershelpMetricSpec.scala | 40 +-- .../similarity/WeightedLevenshteinMetricSpec.scala | 56 ++-- .../tokenization/NGramTokenizerSpec.scala | 77 ++---- 92 files changed, 1150 insertions(+), 2873 deletions(-) delete mode 100755 cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionMap.scala delete mode 100755 cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionString.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/Filter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/Filterable.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/StringAlgorithm.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/StringFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/StringFilterable.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/StringMetric.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/StringTokenizer.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilter.scala delete mode 100755 core/source/main/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/StringAlgorithmSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/StringTokenizerSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilterSpec.scala delete mode 100755 core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionMap.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionMap.scala deleted file mode 100755 index 8f9da13..0000000 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionMap.scala +++ /dev/null @@ -1,36 +0,0 @@ -package com.rockymadden.stringmetric.cli - -object OptionMap { - def apply(args: Array[String]): OptionMap = apply(args: _*) - - def apply(varargs: String*): OptionMap = { - @annotation.tailrec - def next(om: OptionMap, a: List[String]): OptionMap = { - val double = """^(--[a-zA-Z0-9]+)(=[a-zA-Z0-9\.\-_]+)?""".r - val single = """^(-[a-zA-Z0-9]+)(=[a-zA-Z0-9\.\-_]+)?""".r - val less = """([a-zA-Z0-9/\-_\$\.]+)""".r - - a match { - // Empty, return. - case Nil => om - // Double dash options without value. - case double(k, null) :: t => next(om + (Symbol(k.tail.tail) -> ""), t) - // Double dash options with value. - case double(k, v) :: t => next(om + (Symbol(k.tail.tail) -> v.tail), t) - // Single dash options without value. - case single(k, null) :: t => next(om + (Symbol(k.tail) -> ""), t) - // Single dash options with value. Value is discarded. - case single(k, v) :: t => next(om + (Symbol(k.tail) -> ""), t) - // Dashless options. - case less(v) :: t if v.head != '-' => - if (om.contains('dashless)) - next((om - 'dashless) + ('dashless -> (om('dashless).self + " " + v.trim)), t) - else next(om + ('dashless -> v.trim), t) - // Invalid option, ignore. - case _ :: t => next(om, t) - } - } - - next(Map.empty[Symbol, OptionString], varargs.toList) - } -} diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionString.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionString.scala deleted file mode 100755 index 7a1350d..0000000 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/OptionString.scala +++ /dev/null @@ -1,30 +0,0 @@ -package com.rockymadden.stringmetric.cli - -import scala.language.implicitConversions - -class OptionString(val self: String) - -object OptionString { - implicit def OptionStringToArray(optionString: OptionString): Array[String] = - if (optionString.self.length == 0) Array.empty[String] else optionString.self.split(" ") - - implicit def OptionStringToBigDecimal(optionString: OptionString): BigDecimal = BigDecimal(optionString.self) - - implicit def OptionStringToBigInt(optionString: OptionString): BigInt = BigInt(optionString.self) - - implicit def OptionStringToDouble(optionString: OptionString): Double = optionString.self.toDouble - - implicit def OptionStringToFloat(optionString: OptionString): Float = optionString.self.toFloat - - implicit def OptionStringToInt(optionString: OptionString): Int = optionString.self.toInt - - implicit def OptionStringToLong(optionString: OptionString): Long = optionString.self.toLong - - implicit def OptionStringToShort(optionString: OptionString): Short = optionString.self.toShort - - implicit def OptionStringToString(optionString: OptionString): String = optionString.self - - implicit def StringToOptionString(string: String): OptionString = apply(string) - - def apply(string: String): OptionString = new OptionString(string) -} diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/package.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/package.scala index cbaba97..0b049bb 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/package.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/package.scala @@ -1,13 +1,68 @@ package com.rockymadden.stringmetric -import scala.language.implicitConversions - /** * Provides core CLI functionality. Note that some things might look sloppy (e.g. access modifiers, broad imports, * repetitive imports, etc), but are required because of the way scalascript is ultimately compiled. */ package object cli { + import scala.language.implicitConversions + + + implicit def optionStringToArray(os: OptionString): Array[String] = + if (os.get.length == 0) Array.empty[String] else os.get.split(" ") + implicit def optionStringToBigDecimal(os: OptionString): BigDecimal = BigDecimal(os.get) + implicit def optionStringToBigInt(os: OptionString): BigInt = BigInt(os.get) + implicit def optionStringToDouble(os: OptionString): Double = os.get.toDouble + implicit def optionStringToFloat(os: OptionString): Float = os.get.toFloat + implicit def optionStringToInt(os: OptionString): Int = os.get.toInt + implicit def optionStringToLong(os: OptionString): Long = os.get.toLong + implicit def optionStringToShort(os: OptionString): Short = os.get.toShort + implicit def optionStringToString(os: OptionString): String = os.get + implicit def stringToOptionString(s: String): OptionString = OptionString(s) + implicit def arrayOfStringToOptionMap(stringArray: Array[String]): OptionMap = OptionMap(stringArray) + + + class OptionString(val get: String) + + object OptionString { + def apply(s: String): OptionString = new OptionString(s) + } + + type OptionMap = Map[Symbol, OptionString] - implicit def StringArrayToOptionMap(stringArray: Array[String]): OptionMap = OptionMap(stringArray) + object OptionMap { + def apply(args: Array[String]): OptionMap = apply(args: _*) + + def apply(varargs: String*): OptionMap = { + @annotation.tailrec + def next(om: OptionMap, a: List[String]): OptionMap = { + val double = """^(--[a-zA-Z0-9]+)(=[a-zA-Z0-9\.\-_]+)?""".r + val single = """^(-[a-zA-Z0-9]+)(=[a-zA-Z0-9\.\-_]+)?""".r + val less = """([a-zA-Z0-9/\-_\$\.]+)""".r + + a match { + // Empty, return. + case Nil => om + // Double dash options without value. + case double(k, null) :: t => next(om + (Symbol(k.tail.tail) -> ""), t) + // Double dash options with value. + case double(k, v) :: t => next(om + (Symbol(k.tail.tail) -> v.tail), t) + // Single dash options without value. + case single(k, null) :: t => next(om + (Symbol(k.tail) -> ""), t) + // Single dash options with value. Value is discarded. + case single(k, v) :: t => next(om + (Symbol(k.tail) -> ""), t) + // Dashless options. + case less(v) :: t if v.head != '-' => + if (om.contains('dashless)) + next((om - 'dashless) + ('dashless -> (om('dashless).get + " " + v.trim)), t) + else next(om + ('dashless -> v.trim), t) + // Invalid option, ignore. + case _ :: t => next(om, t) + } + } + + next(Map.empty[Symbol, OptionString], varargs.toList) + } + } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/dicesorensenmetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/dicesorensenmetric.scala index 5d0e234..a166f4f 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/dicesorensenmetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/dicesorensenmetric.scala @@ -44,6 +44,6 @@ object dicesorensenmetric extends Command { val strings: Array[String] = opts('dashless) val n: Int = opts('n) - println(DiceSorensenMetric.compare(strings(0), strings(1))(n).getOrElse("not comparable")) + println(DiceSorensenMetric(n).compare(strings(0), strings(1)).getOrElse("not comparable")) } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/jaccardmetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/jaccardmetric.scala index 1f1e123..5dee606 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/jaccardmetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/jaccardmetric.scala @@ -44,6 +44,6 @@ object jaccardmetric extends Command { val strings: Array[String] = opts('dashless) val n: Int = opts('n) - println(JaccardMetric.compare(strings(0), strings(1))(n).getOrElse("not comparable")) + println(JaccardMetric(n).compare(strings(0), strings(1)).getOrElse("not comparable")) } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/ngrammetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/ngrammetric.scala index af0634f..1e54ec6 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/ngrammetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/ngrammetric.scala @@ -44,6 +44,6 @@ object ngrammetric extends Command { val strings: Array[String] = options('dashless) val n: Int = options('n) - println(NGramMetric.compare(strings(0), strings(1))(n).getOrElse("not comparable")) + println(NGramMetric(n).compare(strings(0), strings(1)).getOrElse("not comparable")) } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/overlapmetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/overlapmetric.scala index 2c670c5..81d3e04 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/overlapmetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/overlapmetric.scala @@ -44,6 +44,6 @@ object overlapmetric extends Command { val strings: Array[String] = opts('dashless) val n: Int = opts('n) - println(OverlapMetric.compare(strings(0), strings(1))(n).getOrElse("not comparable")) + println(OverlapMetric(n).compare(strings(0), strings(1)).getOrElse("not comparable")) } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/weightedlevenshteinmetric.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/weightedlevenshteinmetric.scala index d675db1..a9ad9b7 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/weightedlevenshteinmetric.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/similarity/weightedlevenshteinmetric.scala @@ -51,12 +51,9 @@ object weightedlevenshteinmetric extends Command { override def execute(opts: OptionMap): Unit = { val strings: Array[String] = opts('dashless) - val weights = Tuple3[BigDecimal, BigDecimal, BigDecimal]( - opts('deleteWeight), - opts('insertWeight), - opts('substituteWeight) - ) - println(WeightedLevenshteinMetric.compare(strings(0), strings(1))(weights).getOrElse("not comparable")) + println(WeightedLevenshteinMetric( + opts('deleteWeight), opts('insertWeight), opts('substituteWeight) + ).compare(strings(0), strings(1)).getOrElse("not comparable")) } } diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/tokenization/ngramtokenizer.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/tokenization/ngramtokenizer.scala index 99fdbe5..9139e3a 100755 --- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/tokenization/ngramtokenizer.scala +++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/tokenization/ngramtokenizer.scala @@ -41,7 +41,7 @@ object ngramtokenizer extends Command { } override def execute(opts: OptionMap): Unit = - NGramTokenizer.tokenize(opts('dashless))(opts('n)) match { + NGramTokenizer(opts('n)).tokenize(opts('dashless)) match { // Implicits are a pain here. case Some(c) => { val sb = new StringBuilder diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala index 10bc2cd..bb823aa 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala @@ -1,5 +1,12 @@ package com.rockymadden.stringmetric -trait Algorithm[A, B, C] { - def compute(a: A)(implicit b: B): Option[C] +object Algorithm { + trait AlgorithmLike[A] { + def compute(a: A): Option[A] + } + + + trait StringAlgorithmLike extends AlgorithmLike[Array[Char]] { + def compute(a: String): Option[String] + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Alphabet.scala b/core/source/main/scala/com/rockymadden/stringmetric/Alphabet.scala index d2ede81..6d12dd4 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Alphabet.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Alphabet.scala @@ -3,53 +3,40 @@ package com.rockymadden.stringmetric import scala.collection.immutable.Set object Alphabet { - protected sealed abstract class AlphabetSet { - protected[Alphabet] val Chars: Set[Char] + sealed abstract class AlphabetLike(protected[Alphabet] val chars: Set[Char]) { + def isSuperset(a: Char): Boolean = chars.contains(a) - def isSuperset(char: Char): Boolean = Chars.contains(char) + def isSuperset(a: Array[Char]): Boolean = a.length > 0 && a.takeWhile(chars.contains).length == a.length - def isSuperset(charArray: Array[Char]): Boolean = - charArray.length > 0 && charArray.takeWhile(Chars.contains(_)).length == charArray.length - - def isSuperset(string: String): Boolean = isSuperset(string.toCharArray) + def isSuperset(a: String): Boolean = isSuperset(a.toCharArray) } - case object LowercaseConsonant extends AlphabetSet { - override protected[Alphabet] final val Chars = - Set('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x' ,'z') - } - case object UppercaseConsonant extends AlphabetSet { - override protected[Alphabet] final val Chars = - Set('B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X' ,'Z') - } - case object Consonant extends AlphabetSet { - override protected[Alphabet] final val Chars = LowercaseConsonant.Chars ++ UppercaseConsonant.Chars - } - case object LowercaseVowel extends AlphabetSet { - override protected[Alphabet] final val Chars = Set('a', 'e', 'i', 'o', 'u') - } - case object UppercaseVowel extends AlphabetSet { - override protected[Alphabet] final val Chars = Set('A', 'E', 'I', 'O', 'U') - } - case object Vowel extends AlphabetSet { - override protected[Alphabet] final val Chars = LowercaseVowel.Chars ++ UppercaseVowel.Chars - } - case object LowercaseY extends AlphabetSet { - override protected[Alphabet] final val Chars = Set('y') - } - case object UppercaseY extends AlphabetSet { - override protected[Alphabet] final val Chars = Set('Y') - } - case object Y extends AlphabetSet { - override protected[Alphabet] final val Chars = LowercaseY.Chars ++ UppercaseY.Chars - } - case object LowercaseAlpha extends AlphabetSet { - override protected[Alphabet] final val Chars = LowercaseConsonant.Chars ++ LowercaseVowel.Chars ++ LowercaseY.Chars - } - case object UppercaseAlpha extends AlphabetSet { - override protected[Alphabet] final val Chars = UppercaseConsonant.Chars ++ UppercaseVowel.Chars ++ UppercaseY.Chars - } - case object Alpha extends AlphabetSet { - override protected[Alphabet] final val Chars = LowercaseAlpha.Chars ++ UppercaseAlpha.Chars - } + + case object LowercaseConsonant extends AlphabetLike( + Set('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x' ,'z') + ) + + case object UppercaseConsonant extends AlphabetLike( + Set('B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X' ,'Z') + ) + + case object Consonant extends AlphabetLike(LowercaseConsonant.chars ++ UppercaseConsonant.chars) + + case object LowercaseVowel extends AlphabetLike(Set('a', 'e', 'i', 'o', 'u')) + + case object UppercaseVowel extends AlphabetLike(Set('A', 'E', 'I', 'O', 'U')) + + case object Vowel extends AlphabetLike(LowercaseVowel.chars ++ UppercaseVowel.chars) + + case object LowercaseY extends AlphabetLike(Set('y')) + + case object UppercaseY extends AlphabetLike(Set('Y')) + + case object Y extends AlphabetLike(LowercaseY.chars ++ UppercaseY.chars) + + case object LowercaseAlpha extends AlphabetLike(LowercaseConsonant.chars ++ LowercaseVowel.chars ++ LowercaseY.chars) + + case object UppercaseAlpha extends AlphabetLike(UppercaseConsonant.chars ++ UppercaseVowel.chars ++ UppercaseY.chars) + + case object Alpha extends AlphabetLike(LowercaseAlpha.chars ++ UppercaseAlpha.chars) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Filter.scala b/core/source/main/scala/com/rockymadden/stringmetric/Filter.scala deleted file mode 100755 index 2a02f6b..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/Filter.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait Filter[A] extends Filterable[A] { - override def filter(a: A): A = a -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Filterable.scala b/core/source/main/scala/com/rockymadden/stringmetric/Filterable.scala deleted file mode 100755 index 77dc0bf..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/Filterable.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait Filterable[A] { - def filter(a: A): A -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala b/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala index 6862321..3bbed88 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala @@ -1,5 +1,12 @@ package com.rockymadden.stringmetric -trait Metric[A, B, C] { - def compare(a1: A, a2: A)(implicit b: B): Option[C] +object Metric { + trait MetricLike[A, B] { + def compare(a1: A, a2: A): Option[B] + } + + + trait StringMetricLike[A] extends MetricLike[Array[Char], A] { + def compare(string1: String, string2: String): Option[A] + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/StringAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/StringAlgorithm.scala deleted file mode 100755 index 0d194da..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/StringAlgorithm.scala +++ /dev/null @@ -1,42 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringAlgorithm[A, B] extends Algorithm[String, A, B] { - def compute(charArray: Array[Char])(implicit a: A): Option[Array[Char]] -} - -object StringAlgorithm { - type Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm - val Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm - - type Nysiis = com.rockymadden.stringmetric.phonetic.NysiisAlgorithm - val Nysiis = com.rockymadden.stringmetric.phonetic.NysiisAlgorithm - - type RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisAlgorithm - val RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisAlgorithm - - type RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm - val RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm - - type Soundex = com.rockymadden.stringmetric.phonetic.SoundexAlgorithm - val Soundex = com.rockymadden.stringmetric.phonetic.SoundexAlgorithm - - def computeWithMetaphone(charArray: Array[Char]) = Metaphone.compute(charArray) - - def computeWithMetaphone(string: String) = Metaphone.compute(string) - - def computeWithNysiis(charArray: Array[Char]) = Nysiis.compute(charArray) - - def computeWithNysiis(string: String) = Nysiis.compute(string) - - def computeWithRefinedNysiis(charArray: Array[Char]) = RefinedNysiis.compute(charArray) - - def computeWithRefinedNysiis(string: String) = RefinedNysiis.compute(string) - - def computeWithRefinedSoundex(charArray: Array[Char]) = RefinedSoundex.compute(charArray) - - def computeWithRefinedSoundex(string: String) = RefinedSoundex.compute(string) - - def computeWithSoundex(charArray: Array[Char]) = Soundex.compute(charArray) - - def computeWithSoundex(string: String) = Soundex.compute(string) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/StringFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/StringFilter.scala deleted file mode 100755 index 1430d34..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/StringFilter.scala +++ /dev/null @@ -1,45 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.filter.StringFilterDelegate - -trait StringFilter extends Filter[String] with StringFilterable { - override def filter(charArray: Array[Char]): Array[Char] = charArray -} - -object StringFilter { - type AsciiControl = com.rockymadden.stringmetric.filter.AsciiControlFilter - lazy val asciiControl = new StringFilterDelegate with AsciiControl - - type AsciiControlOnly = com.rockymadden.stringmetric.filter.AsciiControlOnlyFilter - lazy val asciiControlOnly = new StringFilterDelegate with AsciiControlOnly - - type AsciiLetterNumber = com.rockymadden.stringmetric.filter.AsciiLetterNumberFilter - lazy val asciiLetterNumber = new StringFilterDelegate with AsciiLetterNumber - - type AsciiLetterNumberOnly = com.rockymadden.stringmetric.filter.AsciiLetterNumberOnlyFilter - lazy val asciiLetterNumberOnly = new StringFilterDelegate with AsciiLetterNumberOnly - - type AsciiLetter = com.rockymadden.stringmetric.filter.AsciiLetterFilter - lazy val asciiLetter = new StringFilterDelegate with AsciiLetter - - type AsciiLetterOnly = com.rockymadden.stringmetric.filter.AsciiLetterOnlyFilter - lazy val asciiLetterOnly = new StringFilterDelegate with AsciiLetterOnly - - type AsciiNumber = com.rockymadden.stringmetric.filter.AsciiNumberFilter - lazy val asciiNumber = new StringFilterDelegate with AsciiNumber - - type AsciiNumberOnly = com.rockymadden.stringmetric.filter.AsciiNumberOnlyFilter - lazy val asciiNumberOnly = new StringFilterDelegate with AsciiNumberOnly - - type AsciiSpace = com.rockymadden.stringmetric.filter.AsciiSpaceFilter - lazy val asciiSpace = new StringFilterDelegate with AsciiSpace - - type AsciiSymbol = com.rockymadden.stringmetric.filter.AsciiSymbolFilter - lazy val asciiSymbol = new StringFilterDelegate with AsciiSymbol - - type AsciiSymbolOnly = com.rockymadden.stringmetric.filter.AsciiSymbolOnlyFilter - lazy val asciiSymbolOnly = new StringFilterDelegate with AsciiSymbolOnly - - type IgnoreAsciiLetterCase = com.rockymadden.stringmetric.filter.IgnoreAsciiLetterCaseFilter - lazy val ignoreAsciiLetterCase = new StringFilterDelegate with IgnoreAsciiLetterCase -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/StringFilterable.scala b/core/source/main/scala/com/rockymadden/stringmetric/StringFilterable.scala deleted file mode 100755 index d639dfb..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/StringFilterable.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringFilterable extends Filterable[String] { - def filter(charArray: Array[Char]): Array[Char] -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/StringMetric.scala deleted file mode 100755 index 212f76d..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/StringMetric.scala +++ /dev/null @@ -1,120 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringMetric[A, B] extends Metric[String, A, B] { - def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit a: A): Option[B] -} - -object StringMetric { - type DiceSorensen = com.rockymadden.stringmetric.similarity.DiceSorensenMetric - val DiceSorensen = com.rockymadden.stringmetric.similarity.DiceSorensenMetric - - type Hamming = com.rockymadden.stringmetric.similarity.HammingMetric - val Hamming = com.rockymadden.stringmetric.similarity.HammingMetric - - type Jaccard = com.rockymadden.stringmetric.similarity.JaccardMetric - val Jaccard = com.rockymadden.stringmetric.similarity.JaccardMetric - - type Jaro = com.rockymadden.stringmetric.similarity.JaroMetric - val Jaro = com.rockymadden.stringmetric.similarity.JaroMetric - - type JaroWinkler = com.rockymadden.stringmetric.similarity.JaroWinklerMetric - val JaroWinkler = com.rockymadden.stringmetric.similarity.JaroWinklerMetric - - type Levenshtein = com.rockymadden.stringmetric.similarity.LevenshteinMetric - val Levenshtein = com.rockymadden.stringmetric.similarity.LevenshteinMetric - - type Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneMetric - val Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneMetric - - type NGram = com.rockymadden.stringmetric.similarity.NGramMetric - val NGram = com.rockymadden.stringmetric.similarity.NGramMetric - - type Nysiis = com.rockymadden.stringmetric.phonetic.NysiisMetric - val Nysiis = com.rockymadden.stringmetric.phonetic.NysiisMetric - - type Overlap = com.rockymadden.stringmetric.similarity.OverlapMetric - val Overlap = com.rockymadden.stringmetric.similarity.OverlapMetric - - type RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisMetric - val RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisMetric - - type RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexMetric - val RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexMetric - - type Soundex = com.rockymadden.stringmetric.phonetic.SoundexMetric - val Soundex = com.rockymadden.stringmetric.phonetic.SoundexMetric - - type WeightedLevenshtein = com.rockymadden.stringmetric.similarity.WeightedLevenshteinMetric - val WeightedLevenshtein = com.rockymadden.stringmetric.similarity.WeightedLevenshteinMetric - - def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = - DiceSorensen.compare(charArray1, charArray2)(n) - - def compareWithDiceSorensen(string1: String, string2: String)(n: Int) = DiceSorensen.compare(string1, string2)(n) - - def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char]) = Hamming.compare(charArray1, charArray2) - - def compareWithHamming(string1: String, string2: String)= Hamming.compare(string1, string2) - - def compareWithJaccard(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = - Jaccard.compare(charArray1, charArray2)(n) - - def compareWithJaccard(string1: String, string2: String)(n: Int) = Jaccard.compare(string1, string2)(n) - - def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char]) = Jaro.compare(charArray1, charArray2) - - def compareWithJaro(string1: String, string2: String) = Jaro.compare(string1, string2) - - def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]) = - JaroWinkler.compare(charArray1, charArray2) - - def compareWithJaroWinkler(string1: String, string2: String) = JaroWinkler.compare(string1, string2) - - def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char]) = - Levenshtein.compare(charArray1, charArray2) - - def compareWithLevenshtein(string1: String, string2: String) = Levenshtein.compare(string1, string2) - - def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char]) = - Metaphone.compare(charArray1, charArray2) - - def compareWithMetaphone(string1: String, string2: String) = Metaphone.compare(string1, string2) - - def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = - NGram.compare(charArray1, charArray2)(n) - - def compareWithNGram(string1: String, string2: String)(n: Int) = NGram.compare(string1, string2)(n) - - def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char]) = Nysiis.compare(charArray1, charArray2) - - def compareWithNysiis(string1: String, string2: String) = Nysiis.compare(string1, string2) - - def compareWithOverlap(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = - Overlap.compare(charArray1, charArray2)(n) - - def compareWithOverlap(string1: String, string2: String)(n: Int) = Overlap.compare(string1, string2)(n) - - def compareWithRefinedNysiis(charArray1: Array[Char], charArray2: Array[Char]) = - RefinedNysiis.compare(charArray1, charArray2) - - def compareWithRefinedNysiis(string1: String, string2: String) = RefinedNysiis.compare(string1, string2) - - def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]) = - RefinedSoundex.compare(charArray1, charArray2) - - def compareWithRefinedSoundex(string1: String, string2: String) = RefinedSoundex.compare(string1, string2) - - def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char]) = Soundex.compare(charArray1, charArray2) - - def compareWithSoundex(string1: String, string2: String) = Soundex.compare(string1, string2) - - def compareWithWeightedLevenshtein(charArray1: Array[Char], charArray2: Array[Char]) - (options: (BigDecimal, BigDecimal, BigDecimal)) = - - WeightedLevenshtein.compare(charArray1, charArray2)(options) - - def compareWithWeightedLevenshtein(string1: String, string2: String) - (options: (BigDecimal, BigDecimal, BigDecimal)) = - - WeightedLevenshtein.compare(string1, string2)(options) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/StringTokenizer.scala b/core/source/main/scala/com/rockymadden/stringmetric/StringTokenizer.scala deleted file mode 100755 index bef56d9..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/StringTokenizer.scala +++ /dev/null @@ -1,14 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringTokenizer[A, B] extends Tokenizer[String, A, B] { - def tokenize(charArray: Array[Char])(implicit a: A): Option[Array[Array[Char]]] -} - -object StringTokenizer { - type NGram = com.rockymadden.stringmetric.tokenization.NGramTokenizer - val NGram = com.rockymadden.stringmetric.tokenization.NGramTokenizer - - def tokenizeWithNGram(charArray: Array[Char])(n: Int) = NGram.tokenize(charArray)(n) - - def tokenizeWithNGram(string: String)(n: Int) = NGram.tokenize(string)(n) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala b/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala index c9edae5..aae9742 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala @@ -1,5 +1,12 @@ package com.rockymadden.stringmetric -trait Tokenizer[A, B, C] { - def tokenize(a: A)(implicit b: B): Option[C] +object Tokenizer { + trait TokenizerLike[A] { + def tokenize(a: A): Option[Array[A]] + } + + + trait StringTokenizerLike extends TokenizerLike[Array[Char]] { + def tokenize(a: String): Option[Array[String]] + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlFilter.scala deleted file mode 100755 index bd45ecf..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII controls do not matter. */ -trait AsciiControlFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => !(c <= 31 || c == 127))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilter.scala deleted file mode 100755 index c08b686..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures only ASCII control characters matter. */ -trait AsciiControlOnlyFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => (c <= 31 || c == 127))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilter.scala deleted file mode 100755 index 24509cb..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII letters do not matter. */ -trait AsciiLetterFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => !((c >= 65 && c <= 90 ) || (c >= 97 && c <= 122)))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilter.scala deleted file mode 100755 index e17c715..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilter.scala +++ /dev/null @@ -1,15 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII letters and numbers do not matter. */ -trait AsciiLetterNumberFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter( - charArray.filter(c => - !((c >= 48 && c <= 57 ) || (c >= 65 && c <= 90 ) || (c >= 97 && c <= 122)) - ) - ) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilter.scala deleted file mode 100755 index 7cf97ba..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilter.scala +++ /dev/null @@ -1,15 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures only ASCII letters and numbers matter. */ -trait AsciiLetterNumberOnlyFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter( - charArray.filter(c => - ((c >= 48 && c <= 57 ) || (c >= 65 && c <= 90 ) || (c >= 97 && c <= 122)) - ) - ) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilter.scala deleted file mode 100755 index 70032d9..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures only ASCII letters matter. */ -trait AsciiLetterOnlyFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => ((c >= 65 && c <= 90 ) || (c >= 97 && c <= 122)))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilter.scala deleted file mode 100755 index 42fe77e..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII numbers do not matter. */ -trait AsciiNumberFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => !(c >= 48 && c <= 57))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilter.scala deleted file mode 100755 index 3f17099..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures only ASCII numbers matter. */ -trait AsciiNumberOnlyFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.filter(c => (c >= 48 && c <= 57 ))) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilter.scala deleted file mode 100755 index 538107d..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilter.scala +++ /dev/null @@ -1,10 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII spaces do not matter. */ -trait AsciiSpaceFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = super.filter(charArray.filter(_ != ' ')) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilter.scala deleted file mode 100755 index 7b0c810..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilter.scala +++ /dev/null @@ -1,15 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII symbols do not matter. */ -trait AsciiSymbolFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter( - charArray.filter(c => - !((c >= 32 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126)) - ) - ) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilter.scala deleted file mode 100755 index 5cb5e94..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilter.scala +++ /dev/null @@ -1,15 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures only ASCII symbols matter. */ -trait AsciiSymbolOnlyFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter( - charArray.filter(c => - ((c >= 32 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126)) - ) - ) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilter.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilter.scala deleted file mode 100755 index 54fe66f..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilter.scala +++ /dev/null @@ -1,11 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -/** Ensures ASCII letter case-sensitivity does not matter. */ -trait IgnoreAsciiLetterCaseFilter extends StringFilter { - abstract override def filter(charArray: Array[Char]): Array[Char] = - super.filter(charArray.map(c => if (c >= 65 && c <= 90) (c + 32).toChar else c)) - - abstract override def filter(string: String): String = filter(string.toCharArray).mkString -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala b/core/source/main/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala deleted file mode 100755 index 8ece42d..0000000 --- a/core/source/main/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala +++ /dev/null @@ -1,9 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.StringFilter - -class StringFilterDelegate extends StringFilter { - override def filter(charArray: Array[Char]): Array[Char] = charArray - - override def filter(string: String): String = string -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala index 655a3a5..126f170 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -1,31 +1,27 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringAlgorithm, StringFilter} -import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} +import com.rockymadden.stringmetric.Algorithm.StringAlgorithmLike -/** An implementation of the Metaphone algorithm. */ -class MetaphoneAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: StringFilter => - final override def compute(charArray: Array[Char])(implicit di: DummyImplicit): Option[Array[Char]] = { - val fca = filter(charArray) +case object MetaphoneAlgorithm extends StringAlgorithmLike { + import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} - if (fca.length == 0 || !(Alpha isSuperset fca.head)) None + override def compute(a: Array[Char]): Option[Array[Char]] = + if (a.length == 0 || !(Alpha isSuperset a.head)) None else { - val th = deduplicate(transcodeHead(fca.map(_.toLower))) + val th = deduplicate(transcodeHead(a.map(_.toLower))) val t = transcode(Array.empty[Char], th.head, th.tail, Array.empty[Char]) if (t.length == 0) None else Some(t) // Single Y or W would have 0 length. } - } - final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = - compute(string.toCharArray).map(_.mkString) + override def compute(a: String): Option[String] = compute(a.toCharArray).map(_.mkString) - private[this] def deduplicate(ca: Array[Char]) = + private def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca else ca.sliding(2).withFilter(a => a(0) == 'c' || a(0) != a(1)).map(a => a(0)).toArray[Char] :+ ca.last @annotation.tailrec - private[this] def transcode(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { + private def transcode(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { if (c == '\0' && r.length == 0) o else { def shift(d: Int, ca: Array[Char]) = { @@ -93,7 +89,7 @@ class MetaphoneAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: } } - private[this] def transcodeHead(ca: Array[Char]) = { + private def transcodeHead(ca: Array[Char]) = { (ca.length: @annotation.switch) match { case 0 => ca case 1 => if (ca.head == 'x') Array('s') else ca @@ -109,13 +105,3 @@ class MetaphoneAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: } } } - -object MetaphoneAlgorithm { - private lazy val self = apply() - - def apply(): MetaphoneAlgorithm = new MetaphoneAlgorithm with StringFilter - - def compute(charArray: Array[Char]) = self.compute(charArray) - - def compute(string: String) = self.compute(string) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala index 2975ad3..083016c 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala @@ -1,32 +1,15 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringFilter, StringMetric} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the Metaphone metric. */ -class MetaphoneMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Boolean] = { +case object MetaphoneMetric extends StringMetricLike[Boolean] { + import com.rockymadden.stringmetric.Alphabet.Alpha - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || !(Alpha isSuperset fca1.head) || fca2.length == 0 || !(Alpha isSuperset fca2.head)) None - else MetaphoneAlgorithm.compute(fca1).filter(_.length > 0).flatMap(mp1 => - MetaphoneAlgorithm.compute(fca2).filter(_.length > 0).map(mp1.sameElements(_)) + override def compare(a: Array[Char], b: Array[Char]): Option[Boolean] = + if (a.length == 0 || !(Alpha isSuperset a.head) || b.length == 0 || !(Alpha isSuperset b.head)) None + else MetaphoneAlgorithm.compute(a).filter(_.length > 0).flatMap(mp1 => + MetaphoneAlgorithm.compute(b).filter(_.length > 0).map(mp1.sameElements(_)) ) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = - compare(string1.toCharArray, string2.toCharArray) -} - -object MetaphoneMetric { - private lazy val self = apply() - - def apply(): MetaphoneMetric = new MetaphoneMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - def compare(string1: String, string2: String) = self.compare(string1, string2) + override def compare(a: String, b: String): Option[Boolean] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala index cf16bbc..43c2bc2 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala @@ -1,16 +1,14 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringAlgorithm, StringFilter} -import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} +import com.rockymadden.stringmetric.Algorithm.StringAlgorithmLike -/** An implementation of the NYSIIS algorithm. */ -class NysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: StringFilter => - final override def compute(charArray: Array[Char])(implicit di: DummyImplicit): Option[Array[Char]] = { - val fca = filter(charArray) +case object NysiisAlgorithm extends StringAlgorithmLike { + import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} - if (fca.length == 0 || !(Alpha isSuperset fca.head)) None + override def compute(a: Array[Char]): Option[Array[Char]] = + if (a.length == 0 || !(Alpha isSuperset a.head)) None else { - val tr = transcodeRight(fca.map(_.toLower)) + val tr = transcodeRight(a.map(_.toLower)) val tl = transcodeLeft(tr._1) val t = if (tl._2.length == 0) tl._1 ++ tr._2 @@ -24,26 +22,24 @@ class NysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: Str if (t.length == 1) Some(t) else Some(t.head +: deduplicate(cleanTerminal(cleanLast(t.tail)))) } - } - final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = - compute(string.toCharArray).map(_.mkString) + override def compute(a: String): Option[String] = compute(a.toCharArray).map(_.mkString) - private[this] def cleanLast(ca: Array[Char]) = + private def cleanLast(ca: Array[Char]) = if (ca.length == 0) ca else if(ca.last == 'a' || ca.last == 's') ca.dropRight(ca.reverseIterator.takeWhile(c => c == 'a' || c == 's').length) else ca - private[this] def cleanTerminal(ca: Array[Char]) = + private def cleanTerminal(ca: Array[Char]) = if (ca.length >= 2 && ca.last == 'y' && ca(ca.length - 2) == 'a') ca.dropRight(2) :+ 'y' else ca - private[this] def deduplicate(ca: Array[Char]) = + private def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca else ca.sliding(2).withFilter(a => a(0) != a(1)).map(a => a(0)).toArray[Char] :+ ca.last @annotation.tailrec - private[this] def transcodeCenter(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { + private def transcodeCenter(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { if (c == '\0' && r.length == 0) o else { def shift(d: Int, ca: Array[Char]) = { @@ -86,7 +82,7 @@ class NysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: Str } } - private[this] def transcodeLeft(ca: Array[Char]) = { + private def transcodeLeft(ca: Array[Char]) = { if (ca.length == 0) (Array.empty[Char], ca) else { lazy val tr2 = ca.takeRight(ca.length - 2) @@ -103,7 +99,7 @@ class NysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: Str } } - private[this] def transcodeRight(ca: Array[Char]) = { + private def transcodeRight(ca: Array[Char]) = { if (ca.length >= 2) { val lc = ca(ca.length - 1) val lcm1 = ca(ca.length - 2) @@ -118,13 +114,3 @@ class NysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: Str } else (ca, Array.empty[Char]) } } - -object NysiisAlgorithm { - private lazy val self = apply() - - def apply(): NysiisAlgorithm = new NysiisAlgorithm with StringFilter - - def compute(charArray: Array[Char]) = self.compute(charArray) - - def compute(string: String) = self.compute(string) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala index 6d1c22c..6316981 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala @@ -1,13 +1,11 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringFilter, StringMetric} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the NYSIIS metric. */ -class NysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Boolean] = { +case object NysiisMetric extends StringMetricLike[Boolean] { + import com.rockymadden.stringmetric.Alphabet.Alpha + override def compare(a: Array[Char], b: Array[Char]): Option[Boolean] = { val unequal = (c1: Char, c2: Char) => { val lc1 = c1.toLower val lc2 = c2.toLower @@ -15,26 +13,12 @@ class NysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFi (if (lc1 == 'k') 'c' else lc1) != (if (lc2 == 'k') 'c' else lc2) } - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || !(Alpha isSuperset fca1.head) || fca2.length == 0 || !(Alpha isSuperset fca2.head)) None - else if (unequal(fca1.head, fca2.head)) Some(false) - else NysiisAlgorithm.compute(fca1).filter(_.length > 0).flatMap(ny1 => - NysiisAlgorithm.compute(fca2).filter(_.length > 0).map(ny1.sameElements(_)) + if (a.length == 0 || !(Alpha isSuperset a.head) || b.length == 0 || !(Alpha isSuperset b.head)) None + else if (unequal(a.head, b.head)) Some(false) + else NysiisAlgorithm.compute(a).filter(_.length > 0).flatMap(ny1 => + NysiisAlgorithm.compute(b).filter(_.length > 0).map(ny1.sameElements(_)) ) } - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = - compare(string1.toCharArray, string2.toCharArray) -} - -object NysiisMetric { - private lazy val self = apply() - - def apply(): NysiisMetric = new NysiisMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - - def compare(string1: String, string2: String) = self.compare(string1, string2) + override def compare(a: String, b: String): Option[Boolean] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala index 196681c..72bd84e 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala @@ -1,42 +1,38 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringAlgorithm, StringFilter} -import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} +import com.rockymadden.stringmetric.Algorithm.StringAlgorithmLike -/** An implementation of the refined NYSIIS algorithm. */ -class RefinedNysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: StringFilter => - final override def compute(charArray: Array[Char])(implicit di: DummyImplicit): Option[Array[Char]] = { - val fca = filter(charArray) +case object RefinedNysiisAlgorithm extends StringAlgorithmLike { + import com.rockymadden.stringmetric.Alphabet.{Alpha, LowercaseVowel} - if (fca.length == 0 || !(Alpha isSuperset fca.head)) None + override def compute(a: Array[Char]): Option[Array[Char]] = + if (a.length == 0 || !(Alpha isSuperset a.head)) None else { - val lfca = fca.map(_.toLower) - val tlh = transcodeLast(transcodeHead(lfca.head +: cleanLast(lfca.tail, Set('s', 'z')))) + val lca = a.map(_.toLower) + val tlh = transcodeLast(transcodeHead(lca.head +: cleanLast(lca.tail, Set('s', 'z')))) val t = transcode(Array.empty[Char], tlh.head, tlh.tail, Array.empty[Char]) if (t.length == 1) Some(t) else Some(deduplicate(t.head +: cleanTerminal(cleanLast(t.tail, Set('a'))))) } - } - final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = - compute(string.toCharArray).map(_.mkString) + override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) - private[this] def cleanLast(ca: Array[Char], s: Set[Char]) = + private def cleanLast(ca: Array[Char], s: Set[Char]) = if (ca.length == 0) ca else if(s.contains(ca.last)) ca.dropRight(ca.reverseIterator.takeWhile(c => s.contains(c)).length) else ca - private[this] def cleanTerminal(ca: Array[Char]) = + private def cleanTerminal(ca: Array[Char]) = if (ca.length >= 2 && ca.last == 'y' && ca(ca.length - 2) == 'a') ca.dropRight(2) :+ 'y' else ca - private[this] def deduplicate(ca: Array[Char]) = + private def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca else ca.sliding(2).withFilter(a => a(0) != a(1)).map(a => a(0)).toArray[Char] :+ ca.last @annotation.tailrec - private[this] def transcode(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { + private def transcode(l: Array[Char], c: Char, r: Array[Char], o: Array[Char]): Array[Char] = { if (c == '\0' && r.length == 0) o else { def shift(d: Int, ca: Array[Char]) = { @@ -95,7 +91,7 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { th } } - private[this] def transcodeHead(ca: Array[Char]) = { + private def transcodeHead(ca: Array[Char]) = if (ca.length == 0) ca else (ca.head: @annotation.switch) match { @@ -103,9 +99,8 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { th case 'p' if (ca.length >= 2 && ca(1) == 'f') => 'f' +: ca.takeRight(ca.length - 2) case _ => ca } - } - private[this] def transcodeLast(ca: Array[Char]) = { + private def transcodeLast(ca: Array[Char]) = if (ca.length >= 2) { val lc = ca(ca.length - 1) val lcm1 = ca(ca.length - 2) @@ -120,15 +115,4 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[DummyImplicit, String] { th case _ => ca } } else ca - } -} - -object RefinedNysiisAlgorithm { - private lazy val self = apply() - - def apply(): RefinedNysiisAlgorithm = new RefinedNysiisAlgorithm with StringFilter - - def compute(charArray: Array[Char]) = self.compute(charArray) - - def compute(string: String) = self.compute(string) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala index c96cc52..73795a0 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala @@ -1,13 +1,11 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringFilter, StringMetric} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the refined NYSIIS metric. */ -class RefinedNysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Boolean] = { +case object RefinedNysiisMetric extends StringMetricLike[Boolean] { + import com.rockymadden.stringmetric.Alphabet.Alpha + override def compare(a: Array[Char], b: Array[Char]): Option[Boolean] = { val unequal = (c1: Char, c2: Char) => { val lc1 = c1.toLower val lc2 = c2.toLower @@ -15,26 +13,12 @@ class RefinedNysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: S (if (lc1 == 'k') 'c' else lc1) != (if (lc2 == 'k') 'c' else lc2) } - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || !(Alpha isSuperset fca1.head) || fca2.length == 0 || !(Alpha isSuperset fca2.head)) None - else if (unequal(fca1.head, fca2.head)) Some(false) - else RefinedNysiisAlgorithm.compute(fca1).filter(_.length > 0).flatMap(rny1 => - RefinedNysiisAlgorithm.compute(fca2).filter(_.length > 0).map(rny1.sameElements(_)) + if (a.length == 0 || !(Alpha isSuperset a.head) || b.length == 0 || !(Alpha isSuperset b.head)) None + else if (unequal(a.head, b.head)) Some(false) + else RefinedNysiisAlgorithm.compute(a).filter(_.length > 0).flatMap(rny1 => + RefinedNysiisAlgorithm.compute(b).filter(_.length > 0).map(rny1.sameElements(_)) ) } - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = - compare(string1.toCharArray, string2.toCharArray) -} - -object RefinedNysiisMetric { - private lazy val self = apply() - - def apply(): RefinedNysiisMetric = new RefinedNysiisMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - - def compare(string1: String, string2: String) = self.compare(string1, string2) + override def compare(a: String, b: String): Option[Boolean] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala index c1b0a6e..9f7fce9 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala @@ -1,22 +1,18 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringAlgorithm, StringFilter} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Algorithm.StringAlgorithmLike -/** An implementation of the refined Soundex algorithm. */ -class RefinedSoundexAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: StringFilter => - final override def compute(charArray: Array[Char])(implicit di: DummyImplicit): Option[Array[Char]] = { - val fca = filter(charArray) +case object RefinedSoundexAlgorithm extends StringAlgorithmLike { + import com.rockymadden.stringmetric.Alphabet.Alpha - if (fca.length == 0 || !(Alpha isSuperset fca.head)) None - else Some(transcode(fca, Array(fca.head.toLower))) - } + override def compute(a: Array[Char]): Option[Array[Char]] = + if (a.length == 0 || !(Alpha isSuperset a.head)) None + else Some(transcode(a, Array(a.head.toLower))) - final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = - compute(string.toCharArray).map(_.mkString) + override def compute(a: String): Option[String] = compute(a.toCharArray).map(_.mkString) @annotation.tailrec - private[this] def transcode(i: Array[Char], o: Array[Char]): Array[Char] = { + private def transcode(i: Array[Char], o: Array[Char]): Array[Char] = if (i.length == 0) o else { val c = i.head.toLower @@ -60,15 +56,4 @@ class RefinedSoundexAlgorithm extends StringAlgorithm[DummyImplicit, String] { t transcode(i.tail, if (a != '\0') o :+ a else o) } - } -} - -object RefinedSoundexAlgorithm { - private lazy val self = apply() - - def apply(): RefinedSoundexAlgorithm = new RefinedSoundexAlgorithm with StringFilter - - def compute(charArray: Array[Char]) = self.compute(charArray) - - def compute(string: String) = self.compute(string) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala index eb2f01e..5ad0e30 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala @@ -1,33 +1,16 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringFilter, StringMetric} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the refined Soundex metric. */ -class RefinedSoundexMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Boolean] = { +case object RefinedSoundexMetric extends StringMetricLike[Boolean] { + import com.rockymadden.stringmetric.Alphabet.Alpha - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || !(Alpha isSuperset fca1.head) || fca2.length == 0 || !(Alpha isSuperset fca2.head)) None - else if (fca1.head.toLower != fca2.head.toLower) Some(false) - else RefinedSoundexAlgorithm.compute(fca1).filter(_.length > 0).flatMap(rse1 => - RefinedSoundexAlgorithm.compute(fca2).filter(_.length > 0).map(rse1.sameElements(_)) + override def compare(a: Array[Char], b: Array[Char]): Option[Boolean] = + if (a.length == 0 || !(Alpha isSuperset a.head) || b.length == 0 || !(Alpha isSuperset b.head)) None + else if (a.head.toLower != b.head.toLower) Some(false) + else RefinedSoundexAlgorithm.compute(a).filter(_.length > 0).flatMap(rse1 => + RefinedSoundexAlgorithm.compute(b).filter(_.length > 0).map(rse1.sameElements(_)) ) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = - compare(string1.toCharArray, string2.toCharArray) -} - -object RefinedSoundexMetric { - private lazy val self = apply() - - def apply(): RefinedSoundexMetric = new RefinedSoundexMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - def compare(string1: String, string2: String) = self.compare(string1, string2) + override def compare(a: String, b: String): Option[Boolean] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala index 2f2bf99..d615144 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala @@ -1,26 +1,22 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringAlgorithm, StringFilter} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Algorithm.StringAlgorithmLike -/** An implementation of the Soundex algorithm. */ -class SoundexAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: StringFilter => - final override def compute(charArray: Array[Char])(implicit di: DummyImplicit): Option[Array[Char]] = { - val fca = filter(charArray) +case object SoundexAlgorithm extends StringAlgorithmLike { + import com.rockymadden.stringmetric.Alphabet.Alpha - if (fca.length == 0 || !(Alpha isSuperset fca.head)) None + override def compute(a: Array[Char]): Option[Array[Char]] = + if (a.length == 0 || !(Alpha isSuperset a.head)) None else { - val fc = fca.head.toLower + val fc = a.head.toLower - Some(transcode(fca.tail, fc, Array(fc)).padTo(4, '0')) + Some(transcode(a.tail, fc, Array(fc)).padTo(4, '0')) } - } - final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = - compute(string.toCharArray).map(_.mkString) + override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) @annotation.tailrec - private[this] def transcode(i: Array[Char], pc: Char, o: Array[Char]): Array[Char] = { + private def transcode(i: Array[Char], pc: Char, o: Array[Char]): Array[Char] = if (i.length == 0) o else { val c = i.head.toLower @@ -58,15 +54,4 @@ class SoundexAlgorithm extends StringAlgorithm[DummyImplicit, String] { this: St if (o.length == 3 && a != '\0') o :+ a else transcode(i.tail, c, if (a != '\0') o :+ a else o) } - } -} - -object SoundexAlgorithm { - private lazy val self = apply() - - def apply(): SoundexAlgorithm = new SoundexAlgorithm with StringFilter - - def compute(charArray: Array[Char]) = self.compute(charArray) - - def compute(string: String) = self.compute(string) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala index e4daa17..7e0bf5c 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala @@ -1,33 +1,16 @@ package com.rockymadden.stringmetric.phonetic -import com.rockymadden.stringmetric.{StringFilter, StringMetric} -import com.rockymadden.stringmetric.Alphabet.Alpha +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the Soundex metric. */ -class SoundexMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Boolean] = { +case object SoundexMetric extends StringMetricLike[Boolean] { + import com.rockymadden.stringmetric.Alphabet.Alpha - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || !(Alpha isSuperset fca1.head) || fca2.length == 0 || !(Alpha isSuperset fca2.head)) None - else if (fca1.head.toLower != fca2.head.toLower) Some(false) - else SoundexAlgorithm.compute(fca1).filter(_.length > 0).flatMap(se1 => - SoundexAlgorithm.compute(fca2).filter(_.length > 0).map(se1.sameElements(_)) + override def compare(a: Array[Char], b: Array[Char]): Option[Boolean] = + if (a.length == 0 || !(Alpha isSuperset a.head) || b.length == 0 || !(Alpha isSuperset b.head)) None + else if (a.head.toLower != b.head.toLower) Some(false) + else SoundexAlgorithm.compute(a).filter(_.length > 0).flatMap(se1 => + SoundexAlgorithm.compute(b).filter(_.length > 0).map(se1.sameElements(_)) ) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = - compare(string1.toCharArray, string2.toCharArray) -} - -object SoundexMetric { - private lazy val self = apply() - - def apply(): SoundexMetric = new SoundexMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - def compare(string1: String, string2: String) = self.compare(string1, string2) + final override def compare(a: String, b: String): Option[Boolean] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala index 5e01bb1..8381921 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala @@ -1,23 +1,22 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{StringMetric, MatchTuple, StringFilter} -import com.rockymadden.stringmetric.tokenization.NGramTokenizer +import com.rockymadden.stringmetric.Metric.StringMetricLike /** * An implementation of the Dice/Sorensen metric. This implementation differs in that n-gram size is required. * Traditionally, the algorithm uses bigrams. */ -class DiceSorensenMetric extends StringMetric[Int, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = { - if (n <= 0) throw new IllegalArgumentException("Expected valid n.") +final case class DiceSorensenMetric(private val n: Int) extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.tokenization.NGramTokenizer + import com.rockymadden.stringmetric.MatchTuple - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = { + if (n <= 0) return None - if (fca1.length < n || fca2.length < n) None // Because length is less than n, it is not possible to compare. - else if (fca1.sameElements(fca2)) Some(1d) - else NGramTokenizer.tokenize(fca1)(n).flatMap { ca1bg => - NGramTokenizer.tokenize(fca2)(n).map { ca2bg => + if (a.length < n || b.length < n) None // Because length is less than n, it is not possible to compare. + else if (a.sameElements(b)) Some(1d) + else NGramTokenizer(n).tokenize(a).flatMap { ca1bg => + NGramTokenizer(n).tokenize(b).map { ca2bg => val ms = scoreMatches(ca1bg.map(_.mkString), ca2bg.map(_.mkString)) (2d * ms) / (ca1bg.length + ca2bg.length) @@ -25,18 +24,7 @@ class DiceSorensenMetric extends StringMetric[Int, Double] { this: StringFilter } } - final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(string1.toCharArray, string2.toCharArray)(n: Int) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } - -object DiceSorensenMetric { - private lazy val self = apply() - - def apply(): DiceSorensenMetric = new DiceSorensenMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) - - def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala index 95ff203..09b62bc 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala @@ -1,37 +1,18 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{CompareTuple, StringFilter, StringMetric} +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the Hamming metric. */ -class HammingMetric extends StringMetric[DummyImplicit, Int] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Int] = { +case object HammingMetric extends StringMetricLike[Int] { + import com.rockymadden.stringmetric.CompareTuple - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Int] = + if (a.length == 0 || b.length == 0 || a.length != b.length) None + else if (a.sameElements(b)) Some(0) + else Some(hamming(a, b)) - if (fca1.length == 0 || fca2.length == 0 || fca1.length != fca2.length) None - else if (fca1.sameElements(fca2)) Some(0) - else Some(hamming(fca1, fca2)) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Int] = - compare(string1.toCharArray, string2.toCharArray) - - private[this] def hamming(ct: CompareTuple[Char]) = { - require(ct._1.length == ct._2.length) + override def compare(a: String, b: String): Option[Int] = compare(a.toCharArray, b.toCharArray) + private def hamming(ct: CompareTuple[Char]) = if (ct._1.length == 0) 0 else ct._1.zip(ct._2).count(t => t._1 != t._2) - } -} - -object HammingMetric { - private lazy val self = apply() - - def apply(): HammingMetric = new HammingMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - - def compare(string1: String, string2: String) = self.compare(string1, string2) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala index e32c926..e1fd4ed 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala @@ -1,20 +1,17 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{StringMetric, StringFilter} -import com.rockymadden.stringmetric.tokenization.NGramTokenizer +import com.rockymadden.stringmetric.Metric.StringMetricLike -/* An implementation of the Jaccard metric. */ -class JaccardMetric extends StringMetric[Int, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = { - if (n <= 0) throw new IllegalArgumentException("Expected valid n.") +final case class JaccardMetric(private val n: Int) extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.tokenization.NGramTokenizer - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = { + if (n <= 0) return None - if (fca1.length < n || fca2.length < n) None // Because length is less than n, it is not possible to compare. - else if (fca1.sameElements(fca2)) Some(1d) - else NGramTokenizer.tokenize(fca1)(n).flatMap { ca1bg => - NGramTokenizer.tokenize(fca2)(n).map { ca2bg => + if (a.length < n || b.length < n) None // Because length is less than n, it is not possible to compare. + else if (a.sameElements(b)) Some(1d) + else NGramTokenizer(n).tokenize(a).flatMap { ca1bg => + NGramTokenizer(n).tokenize(b).map { ca2bg => val i = (ca1bg.map(_.mkString) intersect ca2bg.map(_.mkString)).length i.toDouble / (ca1bg.length + ca2bg.length - i) @@ -22,16 +19,5 @@ class JaccardMetric extends StringMetric[Int, Double] { this: StringFilter => } } - final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(string1.toCharArray, string2.toCharArray)(n: Int) -} - -object JaccardMetric { - private lazy val self = apply() - - def apply(): JaccardMetric = new JaccardMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) - - def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala index b7ce2c5..b9d1434 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala @@ -1,38 +1,33 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{CompareTuple, MatchTuple, StringFilter, StringMetric} -import scala.collection.mutable.{ArrayBuffer, HashSet} +import com.rockymadden.stringmetric.Metric.StringMetricLike /** * An implementation of the Jaro metric. One differing detail in this implementation is that if a character is matched * in string2, it cannot be matched upon again. This results in a more penalized distance in these scenarios. */ -class JaroMetric extends StringMetric[DummyImplicit, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Double] = { +case object JaroMetric extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.{CompareTuple, MatchTuple} + import scala.collection.mutable.{ArrayBuffer, HashSet} - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || fca2.length == 0) None - else if (fca1.sameElements(fca2)) Some(1d) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = + if (a.length == 0 || b.length == 0) None + else if (a.sameElements(b)) Some(1d) else { - val mt = `match`(fca1, fca2) + val mt = `match`(a, b) val ms = scoreMatches(mt._1, mt._2) if (ms == 0) Some(0d) else { val ts = scoreTranspositions(mt._1, mt._2) - Some(((ms.toDouble / fca1.length) + (ms.toDouble / fca2.length) + ((ms.toDouble - ts) / ms)) / 3) + Some(((ms.toDouble / a.length) + (ms.toDouble / b.length) + ((ms.toDouble - ts) / ms)) / 3) } } - } - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = - compare(string1.toCharArray, string2.toCharArray) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) - private[this] def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = { + private def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = { lazy val window = math.abs((math.max(ct._1.length, ct._2.length) / 2d).floor.toInt - 1) val one = ArrayBuffer.empty[Int] val two = HashSet.empty[Int] @@ -63,25 +58,7 @@ class JaroMetric extends StringMetric[DummyImplicit, Double] { this: StringFilte (one.toArray.map(ct._1(_)), two.toArray.sortWith(_ < _).map(ct._2(_))) } - private[this] def scoreMatches(mt: MatchTuple[Char]) = { - require(mt._1.length == mt._2.length) - - mt._1.length - } - - private[this] def scoreTranspositions(mt: MatchTuple[Char]) = { - require(mt._1.length == mt._2.length) - - (mt._1.zip(mt._2).count(t => t._1 != t._2) / 2d).floor.toInt - } -} - -object JaroMetric { - private lazy val self = apply() - - def apply(): JaroMetric = new JaroMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) + private def scoreMatches(mt: MatchTuple[Char]) = mt._1.length - def compare(string1: String, string2: String) = self.compare(string1, string2) + private def scoreTranspositions(mt: MatchTuple[Char]) = (mt._1.zip(mt._2).count(t => t._1 != t._2) / 2d).floor.toInt } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala index 4e9aebd..8d5d724 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala @@ -1,40 +1,23 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{StringFilter, StringMetric} +import com.rockymadden.stringmetric.Metric.StringMetricLike /** * An implementation of the Jaro-Winkler metric. One differing detail in this implementation is that if a character is * matched in string2, it cannot be matched upon again. This results in a more penalized distance in these scenarios * (e.g. comparing henka and henkan distance is 0.9666 versus the typical 0.9722). */ -class JaroWinklerMetric extends StringMetric[DummyImplicit, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Double] = { - - val fca1 = filter(charArray1) - val fca2 = filter(charArray2) - - JaroMetric.compare(fca1, fca2).map { +case object JaroWinklerMetric extends StringMetricLike[Double] { + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = + JaroMetric.compare(a, b).map { case 0d => 0d case 1d => 1d case jaro => { - val prefix = fca1.zip(fca2).takeWhile(t => t._1 == t._2) + val prefix = a.zip(b).takeWhile(t => t._1 == t._2) jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1d * (1 - jaro)) } } - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = - compare(string1.toCharArray, string2.toCharArray) -} - -object JaroWinklerMetric { - private lazy val self = apply() - - def apply(): JaroWinklerMetric = new JaroWinklerMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - def compare(string1: String, string2: String) = self.compare(string1, string2) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala index 47dff23..9f78aed 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala @@ -1,24 +1,18 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{CompareTuple, StringFilter, StringMetric} +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the Levenshtein metric. */ -class LevenshteinMetric extends StringMetric[DummyImplicit, Int] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Int] = { +case object LevenshteinMetric extends StringMetricLike[Int] { + import com.rockymadden.stringmetric.CompareTuple - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Int] = + if (a.length == 0 || b.length == 0) None + else if (a.sameElements(b)) Some(0) + else Some(levenshtein(a, b)) - if (fca1.length == 0 || fca2.length == 0) None - else if (fca1.sameElements(fca2)) Some(0) - else Some(levenshtein(fca1, fca2)) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Int] = - compare(string1.toCharArray, string2.toCharArray) + override def compare(a: String, b: String): Option[Int] = compare(a.toCharArray, b.toCharArray) - private[this] def levenshtein(ct: CompareTuple[Char]) = { + private def levenshtein(ct: CompareTuple[Char]) = { val m = Array.fill[Int](ct._1.length + 1, ct._2.length + 1)(-1) def distance(t: (Int, Int)): Int = { @@ -46,13 +40,3 @@ class LevenshteinMetric extends StringMetric[DummyImplicit, Int] { this: StringF distance(ct._1.length, ct._2.length) } } - -object LevenshteinMetric { - private lazy val self = apply() - - def apply(): LevenshteinMetric = new LevenshteinMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - - def compare(string1: String, string2: String) = self.compare(string1, string2) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala index e74e8eb..8025f38 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala @@ -1,21 +1,19 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{StringMetric, MatchTuple, StringFilter} -import com.rockymadden.stringmetric.tokenization.NGramTokenizer -import scala.math +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the N-Gram metric. */ -class NGramMetric extends StringMetric[Int, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = { - if (n <= 0) throw new IllegalArgumentException("Expected valid n.") +final case class NGramMetric(private val n: Int) extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.MatchTuple + import com.rockymadden.stringmetric.tokenization.NGramTokenizer + import scala.math - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = { + if (n <= 0) return None - if (fca1.length < n || fca2.length < n) None // Because length is less than n, it is not possible to compare. - else if (fca1.sameElements(fca2)) Some(1d) - else NGramTokenizer.tokenize(fca1)(n).flatMap { ca1bg => - NGramTokenizer.tokenize(fca2)(n).map { ca2bg => + if (a.length < n || b.length < n) None // Because length is less than n, it is not possible to compare. + else if (a.sameElements(b)) Some(1d) + else NGramTokenizer(n).tokenize(a).flatMap { ca1bg => + NGramTokenizer(n).tokenize(b).map { ca2bg => val ms = scoreMatches((ca1bg.map(_.mkString), ca2bg.map(_.mkString))) ms.toDouble / math.max(ca1bg.length, ca2bg.length) @@ -23,18 +21,7 @@ class NGramMetric extends StringMetric[Int, Double] { this: StringFilter => } } - final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(string1.toCharArray, string2.toCharArray)(n) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } - -object NGramMetric { - private lazy val self = apply() - - def apply(): NGramMetric = new NGramMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) - - def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala index a543a7e..3bfe604 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala @@ -1,40 +1,27 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{StringMetric, MatchTuple, StringFilter} -import com.rockymadden.stringmetric.tokenization.NGramTokenizer -import scala.math +import com.rockymadden.stringmetric.Metric.StringMetricLike -/* An implementation of the overlap metric. */ -class OverlapMetric extends StringMetric[Int, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = { - if (n <= 0) throw new IllegalArgumentException("Expected valid n.") +final case class OverlapMetric(private val n: Int) extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.MatchTuple + import com.rockymadden.stringmetric.tokenization.NGramTokenizer + import scala.math - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = { + if (n <= 0) return None - if (fca1.length < n || fca2.length < n) None // Because length is less than n, it is not possible to compare. - else if (fca1.sameElements(fca2)) Some(1d) - else NGramTokenizer.tokenize(fca1)(n).flatMap { ca1bg => - NGramTokenizer.tokenize(fca2)(n).map { ca2bg => + if (a.length < n || b.length < n) None // Because length is less than n, it is not possible to compare. + else if (a.sameElements(b)) Some(1d) + else NGramTokenizer(n).tokenize(a).flatMap { ca1bg => + NGramTokenizer(n).tokenize(b).map { ca2bg => val ms = scoreMatches(ca1bg.map(_.mkString), ca2bg.map(_.mkString)) - ms.toDouble / (math.min(ca1bg.length, ca2bg.length)) + ms.toDouble / math.min(ca1bg.length, ca2bg.length) } } } - final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] = - compare(string1.toCharArray, string2.toCharArray)(n: Int) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length } - -object OverlapMetric { - private lazy val self = apply() - - def apply(): OverlapMetric = new OverlapMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int) = self.compare(charArray1, charArray2)(n) - - def compare(string1: String, string2: String)(n: Int) = self.compare(string1, string2)(n) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala index 1017b1f..197e59a 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala @@ -1,24 +1,18 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{CompareTuple, StringFilter, StringMetric} +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of the Ratcliff/Obershelp metric. */ -class RatcliffObershelpMetric extends StringMetric[DummyImplicit, Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit di: DummyImplicit): Option[Double] = { +case object RatcliffObershelpMetric extends StringMetricLike[Double] { + import com.rockymadden.stringmetric.CompareTuple - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = + if (a.length == 0 || b.length == 0) None + else if (a.sameElements(b)) Some(1d) + else Some(2d * commonSequences(a, b).foldLeft(0)(_ + _.length) / (a.length + b.length)) - if (fca1.length == 0 || fca2.length == 0) None - else if (fca1.sameElements(fca2)) Some(1d) - else Some(2d * commonSequences(fca1, fca2).foldLeft(0)(_ + _.length) / (fca1.length + fca2.length)) - } - - final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = - compare(string1.toCharArray, string2.toCharArray) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) - private[this] def longestCommonSubsequence(ct: CompareTuple[Char]) = { + private def longestCommonSubsequence(ct: CompareTuple[Char]) = { val m = Array.ofDim[Int](ct._1.length + 1, ct._2.length + 1) var lrc = (0, 0, 0) // Length, row, column. @@ -33,7 +27,7 @@ class RatcliffObershelpMetric extends StringMetric[DummyImplicit, Double] { this lrc } - private[this] def commonSequences(ct: CompareTuple[Char]): Array[Array[Char]] = { + private def commonSequences(ct: CompareTuple[Char]): Array[Array[Char]] = { val lcs = longestCommonSubsequence(ct) if (lcs._1 == 0) Array.empty @@ -45,13 +39,3 @@ class RatcliffObershelpMetric extends StringMetric[DummyImplicit, Double] { this } } } - -object RatcliffObershelpMetric { - private lazy val self = apply() - - def apply(): RatcliffObershelpMetric = new RatcliffObershelpMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char]) = self.compare(charArray1, charArray2) - - def compare(string1: String, string2: String) = self.compare(string1, string2) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala b/core/source/main/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala index 976b01a..2564eb7 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala @@ -1,32 +1,18 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{CompareTuple, StringMetric, StringFilter} -import scala.math.BigDecimal +import com.rockymadden.stringmetric.Metric.StringMetricLike -/** An implementation of a weighted Levenshtein metric. */ -class WeightedLevenshteinMetric - extends StringMetric[(BigDecimal, BigDecimal, BigDecimal), Double] { this: StringFilter => +final case class WeightedLevenshteinMetric(delete: BigDecimal, insert: BigDecimal, substitute: BigDecimal) + extends StringMetricLike[Double] { - /** Options order is delete, insert, then substitute weight. */ - final override def compare(charArray1: Array[Char], charArray2: Array[Char]) - (implicit options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = { + import com.rockymadden.stringmetric.CompareTuple - if (options._1 < 0 || options._2 < 0 || options._3 < 0) - throw new IllegalArgumentException("Expected valid weight options.") + override def compare(a: Array[Char], b: Array[Char]): Option[Double] = + if (a.length == 0 || b.length == 0) None + else if (a.sameElements(b)) Some(0d) + else Some(weightedLevenshtein((a, b), (delete, insert, substitute)).toDouble) - val fca1 = filter(charArray1) - lazy val fca2 = filter(charArray2) - - if (fca1.length == 0 || fca2.length == 0) None - else if (fca1.sameElements(fca2)) Some(0d) - else Some(weightedLevenshtein((fca1, fca2), options).toDouble) - } - - /** Options order is delete, insert, then substitute weight. */ - final override def compare(string1: String, string2: String) - (implicit options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = - - compare(string1.toCharArray, string2.toCharArray)(options) + override def compare(a: String, b: String): Option[Double] = compare(a.toCharArray, b.toCharArray) private[this] def weightedLevenshtein(ct: CompareTuple[Char], w: (BigDecimal, BigDecimal, BigDecimal)) = { val m = Array.ofDim[BigDecimal](ct._1.length + 1, ct._2.length + 1) @@ -47,15 +33,3 @@ class WeightedLevenshteinMetric m(ct._1.length)(ct._2.length) } } - -object WeightedLevenshteinMetric { - private lazy val self = apply() - - def apply(): WeightedLevenshteinMetric = new WeightedLevenshteinMetric with StringFilter - - def compare(charArray1: Array[Char], charArray2: Array[Char])(options: (BigDecimal, BigDecimal, BigDecimal)) = - self.compare(charArray1, charArray2)(options) - - def compare(string1: String, string2: String)(options: (BigDecimal, BigDecimal, BigDecimal)) = - self.compare(string1, string2)(options) -} diff --git a/core/source/main/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizer.scala b/core/source/main/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizer.scala index d858a59..209288f 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizer.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizer.scala @@ -1,20 +1,16 @@ package com.rockymadden.stringmetric.tokenization -import com.rockymadden.stringmetric.{StringFilter, StringTokenizer} +import com.rockymadden.stringmetric.Tokenizer.StringTokenizerLike -/** An implementation of the N-Gram tokenizer. */ -class NGramTokenizer extends StringTokenizer[Int, Array[String]] { this: StringFilter => - final override def tokenize(charArray: Array[Char])(implicit n: Int): Option[Array[Array[Char]]] = { - if (n <= 0) throw new IllegalArgumentException("Expected valid n.") +final case class NGramTokenizer(private val n: Int) extends StringTokenizerLike { + override def tokenize(a: Array[Char]): Option[Array[Array[Char]]] = { + if (n <= 0) return None - val fca = filter(charArray) - - if (fca.length < n) None - else Some(sequence(fca, Array.empty[Array[Char]], n)) + if (a.length < n) None + else Some(sequence(a, Array.empty[Array[Char]], n)) } - final override def tokenize(string: String)(implicit n: Int): Option[Array[String]] = - tokenize(string.toCharArray)(n).map(_.map(_.mkString)) + override def tokenize(a: String): Option[Array[String]] = tokenize(a.toCharArray).map(_.map(_.mkString)) @annotation.tailrec private[this] def sequence(i: Array[Char], o: Array[Array[Char]], n: Int): Array[Array[Char]] = { @@ -24,13 +20,3 @@ class NGramTokenizer extends StringTokenizer[Int, Array[String]] { this: StringF else sequence(i.tail, o :+ i.take(n), n) } } - -object NGramTokenizer { - private lazy val self = apply() - - def apply(): NGramTokenizer = new NGramTokenizer with StringFilter - - def tokenize(charArray: Array[Char])(n: Int) = self.tokenize(charArray)(n) - - def tokenize(string: String)(n: Int) = self.tokenize(string)(n) -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala deleted file mode 100755 index e900f83..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala +++ /dev/null @@ -1,38 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.filter.AsciiNumberFilter -import com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm -import com.rockymadden.stringmetric.similarity.DiceSorensenMetric -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class FilterDecoratedSpec extends ScalaTest { - import FilterDecoratedSpec.{Algorithm, Metric} - - "Filter decorated metrics" should provide { - "compare method" when passed { - "filterable arguments" should returns { - "filtered results" in { - Metric.compare("123", "456")(1).isDefined should be (false) - Metric.compare("ni123ght", "na456cht")(1).get should be (0.6) - } - } - } - } - "Filter decorated algorithms" should provide { - "compute method" when passed { - "filterable argument" should returns { - "filtered results" in { - Algorithm.compute("456").isDefined should be (false) - Algorithm.compute("du123mb456").get should equal ("tm") - } - } - } - } -} - -object FilterDecoratedSpec { - private final val Algorithm = new MetaphoneAlgorithm with AsciiNumberFilter - private final val Metric = new DiceSorensenMetric with AsciiNumberFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/StringAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/StringAlgorithmSpec.scala deleted file mode 100755 index 7ce0c24..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/StringAlgorithmSpec.scala +++ /dev/null @@ -1,59 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.phonetic._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class StringAlgorithmSpec extends ScalaTest { - "StringAlgorithm standalone object" should provide { - "compute method, type, and companion object pass-throughs" in { - val metaphone: StringAlgorithm.Metaphone = StringAlgorithm.Metaphone() - - metaphone.compute("testone").get should - equal (StringAlgorithm.computeWithMetaphone("testone").get) - metaphone.compute("testone".toCharArray).get should - equal (StringAlgorithm.computeWithMetaphone("testone".toCharArray).get) - metaphone.compute("testone".toCharArray).get should - equal (MetaphoneAlgorithm.compute("testone".toCharArray).get) - - val nysiis: StringAlgorithm.Nysiis = StringAlgorithm.Nysiis() - - nysiis.compute("testone").get should - equal (StringAlgorithm.computeWithNysiis("testone").get) - nysiis.compute("testone".toCharArray).get should - equal (StringAlgorithm.computeWithNysiis("testone".toCharArray).get) - nysiis.compute("testone".toCharArray).get should - equal (NysiisAlgorithm.compute("testone".toCharArray).get) - - val refinedNysiis: StringAlgorithm.RefinedNysiis = StringAlgorithm.RefinedNysiis() - - refinedNysiis.compute("testone").get should - equal (StringAlgorithm.computeWithRefinedNysiis("testone").get) - refinedNysiis.compute("testone".toCharArray).get should - equal (StringAlgorithm.computeWithRefinedNysiis("testone".toCharArray).get) - refinedNysiis.compute("testone".toCharArray).get should - equal (RefinedNysiisAlgorithm.compute("testone".toCharArray).get) - - val refinedSoundex: StringAlgorithm.RefinedSoundex = StringAlgorithm.RefinedSoundex() - - refinedSoundex.compute("testone").get should - equal (StringAlgorithm.computeWithRefinedSoundex("testone").get) - refinedSoundex.compute("testone".toCharArray).get should - equal (StringAlgorithm.computeWithRefinedSoundex("testone".toCharArray).get) - refinedSoundex.compute("testone".toCharArray).get should - equal (RefinedSoundexAlgorithm.compute("testone".toCharArray).get) - - val soundex: StringAlgorithm.Soundex = StringAlgorithm.Soundex() - - soundex.compute("testone").get should - equal (StringAlgorithm.computeWithSoundex("testone").get) - soundex.compute("testone".toCharArray).get should - equal (StringAlgorithm.computeWithSoundex("testone".toCharArray).get) - soundex.compute("testone".toCharArray).get should - equal (SoundexAlgorithm.compute("testone".toCharArray).get) - } - } -} - - diff --git a/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala deleted file mode 100755 index ca99bff..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala +++ /dev/null @@ -1,141 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.phonetic._ -import com.rockymadden.stringmetric.similarity._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class StringMetricSpec extends ScalaTest { - "StringMetric standalone object" should provide { - "compare method, type, and companion object pass-throughs" in { - val diceSorensen: StringMetric.DiceSorensen = StringMetric.DiceSorensen() - - diceSorensen.compare("testone", "testtwo")(1).get should - equal (StringMetric.compareWithDiceSorensen("testone", "testtwo")(1).get) - diceSorensen.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (StringMetric.compareWithDiceSorensen("testone".toCharArray, "testtwo".toCharArray)(1).get) - diceSorensen.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (DiceSorensenMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get) - - val hamming: StringMetric.Hamming = StringMetric.Hamming() - - hamming.compare("testone", "testtwo").get should - equal (StringMetric.compareWithHamming("testone", "testtwo").get) - hamming.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithHamming("testone".toCharArray, "testtwo".toCharArray).get) - hamming.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (HammingMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val jaccard: StringMetric.Jaccard = StringMetric.Jaccard() - - jaccard.compare("testone", "testtwo")(1).get should - equal (StringMetric.compareWithJaccard("testone", "testtwo")(1).get) - jaccard.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (StringMetric.compareWithJaccard("testone".toCharArray, "testtwo".toCharArray)(1).get) - jaccard.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (JaccardMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get) - - val jaro: StringMetric.Jaro = StringMetric.Jaro() - - jaro.compare("testone", "testtwo").get should - equal (StringMetric.compareWithJaro("testone", "testtwo").get) - jaro.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithJaro("testone".toCharArray, "testtwo".toCharArray).get) - jaro.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (JaroMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val jaroWinkler: StringMetric.JaroWinkler = StringMetric.JaroWinkler() - - jaroWinkler.compare("testone", "testtwo").get should - equal (StringMetric.compareWithJaroWinkler("testone", "testtwo").get) - jaroWinkler.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithJaroWinkler("testone".toCharArray, "testtwo".toCharArray).get) - jaroWinkler.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (JaroWinklerMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val levenshtein: StringMetric.Levenshtein = StringMetric.Levenshtein() - - levenshtein.compare("testone", "testtwo").get should - equal (StringMetric.compareWithLevenshtein("testone", "testtwo").get) - levenshtein.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithLevenshtein("testone".toCharArray, "testtwo".toCharArray).get) - levenshtein.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (LevenshteinMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val metaphone: StringMetric.Metaphone = StringMetric.Metaphone() - - metaphone.compare("testone", "testtwo").get should - equal (StringMetric.compareWithMetaphone("testone", "testtwo").get) - metaphone.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithMetaphone("testone".toCharArray, "testtwo".toCharArray).get) - metaphone.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (MetaphoneMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val nGram: StringMetric.NGram = StringMetric.NGram() - - nGram.compare("testone", "testtwo")(1).get should - equal (StringMetric.compareWithNGram("testone", "testtwo")(1).get) - nGram.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (StringMetric.compareWithNGram("testone".toCharArray, "testtwo".toCharArray)(1).get) - nGram.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (NGramMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get) - - val nysiis: StringMetric.Nysiis = StringMetric.Nysiis() - - nysiis.compare("testone", "testtwo").get should - equal (StringMetric.compareWithNysiis("testone", "testtwo").get) - nysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithNysiis("testone".toCharArray, "testtwo".toCharArray).get) - nysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (NysiisMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val overlap: StringMetric.Overlap = StringMetric.Overlap() - - overlap.compare("testone", "testtwo")(1).get should - equal (StringMetric.compareWithOverlap("testone", "testtwo")(1).get) - overlap.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (StringMetric.compareWithOverlap("testone".toCharArray, "testtwo".toCharArray)(1).get) - overlap.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (OverlapMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get) - - val refinedNysiis: StringMetric.RefinedNysiis = StringMetric.RefinedNysiis() - - refinedNysiis.compare("testone", "testtwo").get should - equal (StringMetric.compareWithRefinedNysiis("testone", "testtwo").get) - refinedNysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithRefinedNysiis("testone".toCharArray, "testtwo".toCharArray).get) - refinedNysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (RefinedNysiisMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val refinedSoundex: StringMetric.RefinedSoundex = StringMetric.RefinedSoundex() - - refinedSoundex.compare("testone", "testtwo").get should - equal (StringMetric.compareWithRefinedSoundex("testone", "testtwo").get) - refinedSoundex.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithRefinedSoundex("testone".toCharArray, "testtwo".toCharArray).get) - refinedSoundex.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (RefinedSoundexMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val soundex: StringMetric.Soundex = StringMetric.Soundex() - - soundex.compare("testone", "testtwo").get should - equal (StringMetric.compareWithSoundex("testone", "testtwo").get) - soundex.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (StringMetric.compareWithSoundex("testone".toCharArray, "testtwo".toCharArray).get) - soundex.compare("testone".toCharArray, "testtwo".toCharArray).get should - equal (SoundexMetric.compare("testone".toCharArray, "testtwo".toCharArray).get) - - val weightedLevenshtein: StringMetric.WeightedLevenshtein = StringMetric.WeightedLevenshtein() - - weightedLevenshtein.compare("testone", "testtwo")(1, 2, 3).get should - equal (StringMetric.compareWithWeightedLevenshtein("testone", "testtwo")(1, 2, 3).get) - weightedLevenshtein.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get should - equal (StringMetric.compareWithWeightedLevenshtein("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get) - weightedLevenshtein.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get should - equal (WeightedLevenshteinMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get) - } - } -} - - diff --git a/core/source/test/scala/com/rockymadden/stringmetric/StringTokenizerSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/StringTokenizerSpec.scala deleted file mode 100755 index 8837c25..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/StringTokenizerSpec.scala +++ /dev/null @@ -1,23 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.tokenization.NGramTokenizer -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class StringTokenizerSpec extends ScalaTest { - "StringTokenizer standalone object" should provide { - "tokenize method, type, and companion object pass-throughs" in { - val nGram: StringTokenizer.NGram = StringTokenizer.NGram() - - nGram.tokenize("testone")(1).get should - equal (StringTokenizer.tokenizeWithNGram("testone")(1).get) - nGram.tokenize("testone".toCharArray)(1).get should - equal (StringTokenizer.tokenizeWithNGram("testone".toCharArray)(1).get) - nGram.tokenize("testone".toCharArray)(1).get should - equal (NGramTokenizer.tokenize("testone".toCharArray)(1).get) - } - } -} - - diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlFilterSpec.scala deleted file mode 100755 index 1cce0c9..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiControlFilterSpec extends ScalaTest { - import AsciiControlFilterSpec.Filter - - "AsciiControlFilter" should provide { - "overloaded filter method" when passed { - "String with controls" should returns { - "String with controls removed" in { - Filter.filter(" HelloWorld") should equal ("HelloWorld") - Filter.filter("HelloWorld ") should equal ("HelloWorld") - Filter.filter("Hello World") should equal ("HelloWorld") - } - } - "character array with controls" should returns { - "character array with controls removed" in { - Filter.filter(" HelloWorld".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("HelloWorld ".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("Hello World".toCharArray) should equal ("HelloWorld".toCharArray) - } - } - } - } -} - -object AsciiControlFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiControlFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilterSpec.scala deleted file mode 100755 index 958c8ba..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiControlOnlyFilterSpec extends ScalaTest { - import AsciiControlOnlyFilterSpec.Filter - - "AsciiControlOnlyFilter" should provide { - "overloaded filter method" when passed { - "String with mixed characters" should returns { - "String with non-controls removed" in { - Filter.filter("!@#$% ^&*()abc") should equal (" ") - Filter.filter(" ^&*()abc") should equal (" ") - Filter.filter("%^&*()abc ") should equal (" ") - } - } - "character array with mixed characters" should returns { - "character array with non-controls removed" in { - Filter.filter("!@#$% ^&*()abc".toCharArray) should equal (" ".toCharArray) - Filter.filter(" ^&*()abc".toCharArray) should equal (" ".toCharArray) - Filter.filter("%^&*()abc ".toCharArray) should equal (" ".toCharArray) - } - } - } - } -} - -object AsciiControlOnlyFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiControlOnlyFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilterSpec.scala deleted file mode 100755 index d86e7a5..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterFilterSpec.scala +++ /dev/null @@ -1,29 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiLetterFilterSpec extends ScalaTest { - import AsciiLetterFilterSpec.Filter - - "AsciiLetterFilter" should provide { - "overloaded filter method" when passed { - "String with letters" should returns { - "String with letters removed" in { - Filter.filter(" Hello123World!") should equal (" 123!") - } - } - "character array with letters" should returns { - "character array with letters removed" in { - Filter.filter(" Hello123World!".toCharArray) should equal (" 123!".toCharArray) - } - } - } - } -} - -object AsciiLetterFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiLetterFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilterSpec.scala deleted file mode 100755 index edfdce6..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiLetterNumberFilterSpec extends ScalaTest { - import AsciiLetterNumberFilterSpec.Filter - - "AsciiLetterNumberFilter" should provide { - "overloaded filter method" when passed { - "String with letters and numbers" should returns { - "String with letters and numbers removed" in { - Filter.filter(" Hello123World!") should equal (" !") - Filter.filter("Hello123 !World") should equal (" !") - Filter.filter("!Hello123World ") should equal ("! ") - } - } - "character array with letters and numbers" should returns { - "character array with letters and numbers removed" in { - Filter.filter(" Hello123World!".toCharArray) should equal (" !".toCharArray) - Filter.filter("Hello123 !World".toCharArray) should equal (" !".toCharArray) - Filter.filter("!Hello123World ".toCharArray) should equal ("! ".toCharArray) - } - } - } - } -} - -object AsciiLetterNumberFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiLetterNumberFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilterSpec.scala deleted file mode 100755 index 7998e39..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyFilterSpec.scala +++ /dev/null @@ -1,35 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiLetterNumberOnlyFilterSpec extends ScalaTest { - import AsciiLetterNumberOnlyFilterSpec.Filter - - "AsciiLetterNumberOnlyFilter" should provide { - "overloaded filter method" when passed { - "String with mixed characters" should returns { - "String with non-letters and non-numbers removed" in { - Filter.filter("!@#$%^&*()abc") should equal ("abc") - Filter.filter("!@#$%^&*()abc123") should equal ("abc123") - Filter.filter("abc123!@#$%^&*()") should equal ("abc123") - Filter.filter("!@#$%abc123^&*()") should equal ("abc123") - } - } - "character array with mixed characters" should returns { - "character array with non-letters and non-numbers removed" in { - Filter.filter("!@#$%^&*()abc".toCharArray) should equal ("abc".toCharArray) - Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("abc123".toCharArray) - Filter.filter("abc123!@#$%^&*()".toCharArray) should equal ("abc123".toCharArray) - Filter.filter("!@#$%abc123^&*()".toCharArray) should equal ("abc123".toCharArray) - } - } - } - } -} - -object AsciiLetterNumberOnlyFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiLetterNumberOnlyFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilterSpec.scala deleted file mode 100755 index d134792..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiLetterOnlyFilterSpec extends ScalaTest { - import AsciiLetterOnlyFilterSpec.Filter - - "AsciiLetterOnlyFilter" should provide { - "overloaded filter method" when passed { - "String with mixed characters" should returns { - "String with non-letters removed" in { - Filter.filter("!@#$%^&*()abc") should equal ("abc") - Filter.filter("!@#$%^&*()abc123") should equal ("abc") - Filter.filter("abc!@#$%^&*()123") should equal ("abc") - } - } - "character array with mixed characters" should returns { - "character array with non-letters removed" in { - Filter.filter("!@#$%^&*()abc".toCharArray) should equal ("abc".toCharArray) - Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("abc".toCharArray) - Filter.filter("abc!@#$%^&*()123".toCharArray) should equal ("abc".toCharArray) - } - } - } - } -} - -object AsciiLetterOnlyFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiLetterOnlyFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilterSpec.scala deleted file mode 100755 index 7c24d45..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiNumberFilterSpec extends ScalaTest { - import AsciiNumberFilterSpec.Filter - - "AsciiNumberFilter" should provide { - "overloaded filter method" when passed { - "String with numbers" should returns { - "String with numbers removed" in { - Filter.filter(" Hello123World!") should equal (" HelloWorld!") - Filter.filter("123 HelloWorld!") should equal (" HelloWorld!") - Filter.filter(" HelloWorld!123") should equal (" HelloWorld!") - } - } - "character array with numbers" should returns { - "character array with numbers removed" in { - Filter.filter(" Hello123World!".toCharArray) should equal (" HelloWorld!".toCharArray) - Filter.filter("123 HelloWorld!".toCharArray) should equal (" HelloWorld!".toCharArray) - Filter.filter(" HelloWorld!123".toCharArray) should equal (" HelloWorld!".toCharArray) - } - } - } - } -} - -object AsciiNumberFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiNumberFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilterSpec.scala deleted file mode 100755 index db49d25..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiNumberOnlyFilterSpec extends ScalaTest { - import AsciiNumberOnlyFilterSpec.Filter - - "AsciiNumberOnlyFilter" should provide { - "overloaded filter method" when passed { - "String with mixed characters" should returns { - "String with non-numbers removed" in { - Filter.filter("!@#$%^&*()abc123") should equal ("123") - Filter.filter("123!@#$%^&*()abc") should equal ("123") - Filter.filter("!@#$%^123&*()abc") should equal ("123") - } - } - "character array with mixed characters" should returns { - "character array with non-numbers removed" in { - Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("123".toCharArray) - Filter.filter("123!@#$%^&*()abc".toCharArray) should equal ("123".toCharArray) - Filter.filter("!@#$%^123&*()abc".toCharArray) should equal ("123".toCharArray) - } - } - } - } -} - -object AsciiNumberOnlyFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiNumberOnlyFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilterSpec.scala deleted file mode 100755 index 759db3d..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceFilterSpec.scala +++ /dev/null @@ -1,37 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiSpaceFilterSpec extends ScalaTest { - import AsciiSpaceFilterSpec.Filter - - "AsciiSpaceFilter" should provide { - "overloaded filter method" when passed { - "String with spaces" should returns { - "String with spaces removed" in { - Filter.filter("HelloWorld") should equal ("HelloWorld") - Filter.filter(" HelloWorld ") should equal ("HelloWorld") - Filter.filter("Hello World") should equal ("HelloWorld") - Filter.filter("H e l l o W o r l d") should equal ("HelloWorld") - Filter.filter("H e l l o W o r l d") should equal ("HelloWorld") - } - } - "character array with spaces" should returns { - "character array with spaces removed" in { - Filter.filter("HelloWorld".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter(" HelloWorld ".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("Hello World".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("H e l l o W o r l d".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("H e l l o W o r l d".toCharArray) should equal ("HelloWorld".toCharArray) - } - } - } - } -} - -object AsciiSpaceFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiSpaceFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilterSpec.scala deleted file mode 100755 index 99be533..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolFilterSpec.scala +++ /dev/null @@ -1,31 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiSymbolFilterSpec extends ScalaTest { - import AsciiSymbolFilterSpec.Filter - - "AsciiSymbolFilter" should provide { - "overloaded filter method" when passed { - "String with symbols" should returns { - "String with symbols removed" in { - Filter.filter("[HelloWorld]") should equal ("HelloWorld") - Filter.filter("Hello!World") should equal ("HelloWorld") - } - } - "character array with symbols" should returns { - "character array with symbols removed" in { - Filter.filter("[HelloWorld]".toCharArray) should equal ("HelloWorld".toCharArray) - Filter.filter("Hello!World".toCharArray) should equal ("HelloWorld".toCharArray) - } - } - } - } -} - -object AsciiSymbolFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiSymbolFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilterSpec.scala deleted file mode 100755 index c6f1899..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyFilterSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class AsciiSymbolOnlyFilterSpec extends ScalaTest { - import AsciiSymbolOnlyFilterSpec.Filter - - "AsciiSymbolOnlyFilter" should provide { - "overloaded filter method" when passed { - "String with mixed characters" should returns { - "String with non-symbols removed" in { - Filter.filter("!@#$%^&*()abc123") should equal ("!@#$%^&*()") - Filter.filter("abc123!@#$%^&*()") should equal ("!@#$%^&*()") - Filter.filter("!@#$%abc123^&*()") should equal ("!@#$%^&*()") - } - } - "character array with mixed characters" should returns { - "character array with non-symbols removed" in { - Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("!@#$%^&*()".toCharArray) - Filter.filter("abc123!@#$%^&*()".toCharArray) should equal ("!@#$%^&*()".toCharArray) - Filter.filter("!@#$%abc123^&*()".toCharArray) should equal ("!@#$%^&*()".toCharArray) - } - } - } - } -} - -object AsciiSymbolOnlyFilterSpec { - private final val Filter = new StringFilterDelegate with AsciiSymbolOnlyFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilterSpec.scala deleted file mode 100755 index a04a0ae..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/IgnoreAsciiLetterCaseFilterSpec.scala +++ /dev/null @@ -1,41 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class IgnoreAsciiLetterCaseFilterSpec extends ScalaTest { - import IgnoreAsciiLetterCaseFilterSpec.Filter - - "IgnoreAsciiLetterCaseFilter" should provide { - "overloaded filter method" when passed { - "String with mixed case" should returns { - "String with the same case" in { - Filter.filter("HelloWorld") should (equal ("helloworld") or equal ("HELLOWORLD")) - Filter.filter("Hello World") should (equal ("hello world") or equal ("HELLO WORLD")) - Filter.filter("H e l l o W o r l d") should - (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) - Filter.filter("H e l l o W o r l d") should - (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) - } - } - "character array with mixed case" should returns { - "character array with the same case" in { - Filter.filter("HelloWorld".toCharArray) should - (equal ("helloworld".toCharArray) or equal ("HELLOWORLD".toCharArray)) - Filter.filter("Hello World".toCharArray) should - (equal ("hello world".toCharArray) or equal ("HELLO WORLD".toCharArray)) - Filter.filter("H e l l o W o r l d".toCharArray) should - (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) - Filter.filter("H e l l o W o r l d".toCharArray) should - (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) - } - } - } - } -} - -object IgnoreAsciiLetterCaseFilterSpec { - private final val Filter = new StringFilterDelegate with IgnoreAsciiLetterCaseFilter -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala deleted file mode 100755 index 132156b..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala +++ /dev/null @@ -1,31 +0,0 @@ -package com.rockymadden.stringmetric.filter - -import com.rockymadden.stringmetric.ScalaTest -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class StringFilterDelegateSpec extends ScalaTest { - import StringFilterDelegateSpec.Filter - - "StringFilter" should provide { - "overloaded filter method" when passed { - "String" should returns { - "the same String" in { - Filter.filter("Hello World") should equal ("Hello World") - Filter.filter(" Hello! World]") should equal (" Hello! World]") - } - } - "character array" should returns { - "the same character array" in { - Filter.filter("Hello World".toCharArray) should equal ("Hello World".toCharArray) - Filter.filter(" Hello! World]".toCharArray) should equal (" Hello! World]".toCharArray) - } - } - } - } -} - -object StringFilterDelegateSpec { - private final val Filter = new StringFilterDelegate -} diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala index 1f904d5..e29a9ae 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala @@ -6,221 +6,208 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class MetaphoneAlgorithmSpec extends ScalaTest { - import MetaphoneAlgorithmSpec.Algorithm - "MetaphoneAlgorithm" should provide { "compute method" when passed { "empty argument" should returns { "None" in { - Algorithm.compute("").isDefined should be (false) + MetaphoneAlgorithm.compute("").isDefined should be (false) } } "non-phonetic argument" should returns { "None" in { - Algorithm.compute("123").isDefined should be (false) + MetaphoneAlgorithm.compute("123").isDefined should be (false) } } "phonetic argument" should returns { "Some" in { // z - Algorithm.compute("z").get should equal ("s") - Algorithm.compute("zz").get should equal ("s") + MetaphoneAlgorithm.compute("z").get should equal ("s") + MetaphoneAlgorithm.compute("zz").get should equal ("s") // y - Algorithm.compute("y").isDefined should be (false) - Algorithm.compute("zy").get should equal ("s") - Algorithm.compute("zyz").get should equal ("ss") - Algorithm.compute("zya").get should equal ("sy") + MetaphoneAlgorithm.compute("y").isDefined should be (false) + MetaphoneAlgorithm.compute("zy").get should equal ("s") + MetaphoneAlgorithm.compute("zyz").get should equal ("ss") + MetaphoneAlgorithm.compute("zya").get should equal ("sy") // x - Algorithm.compute("x").get should equal ("s") - Algorithm.compute("zx").get should equal ("sks") - Algorithm.compute("zxz").get should equal ("skss") + MetaphoneAlgorithm.compute("x").get should equal ("s") + MetaphoneAlgorithm.compute("zx").get should equal ("sks") + MetaphoneAlgorithm.compute("zxz").get should equal ("skss") // w - Algorithm.compute("w").isDefined should be (false) - Algorithm.compute("zw").get should equal ("s") - Algorithm.compute("zwz").get should equal ("ss") - Algorithm.compute("zwa").get should equal ("sw") + MetaphoneAlgorithm.compute("w").isDefined should be (false) + MetaphoneAlgorithm.compute("zw").get should equal ("s") + MetaphoneAlgorithm.compute("zwz").get should equal ("ss") + MetaphoneAlgorithm.compute("zwa").get should equal ("sw") // v - Algorithm.compute("v").get should equal ("f") - Algorithm.compute("zv").get should equal ("sf") - Algorithm.compute("zvz").get should equal ("sfs") + MetaphoneAlgorithm.compute("v").get should equal ("f") + MetaphoneAlgorithm.compute("zv").get should equal ("sf") + MetaphoneAlgorithm.compute("zvz").get should equal ("sfs") // u - Algorithm.compute("u").get should equal ("u") - Algorithm.compute("zu").get should equal ("s") + MetaphoneAlgorithm.compute("u").get should equal ("u") + MetaphoneAlgorithm.compute("zu").get should equal ("s") // t - Algorithm.compute("t").get should equal ("t") - Algorithm.compute("ztiaz").get should equal ("sxs") - Algorithm.compute("ztioz").get should equal ("sxs") - Algorithm.compute("zthz").get should equal ("s0s") - Algorithm.compute("ztchz").get should equal ("sxs") - Algorithm.compute("ztz").get should equal ("sts") + MetaphoneAlgorithm.compute("t").get should equal ("t") + MetaphoneAlgorithm.compute("ztiaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("ztioz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zthz").get should equal ("s0s") + MetaphoneAlgorithm.compute("ztchz").get should equal ("sxs") + MetaphoneAlgorithm.compute("ztz").get should equal ("sts") // s - Algorithm.compute("s").get should equal ("s") - Algorithm.compute("zshz").get should equal ("sxs") - Algorithm.compute("zsioz").get should equal ("sxs") - Algorithm.compute("zsiaz").get should equal ("sxs") - Algorithm.compute("zs").get should equal ("ss") - Algorithm.compute("zsz").get should equal ("sss") + MetaphoneAlgorithm.compute("s").get should equal ("s") + MetaphoneAlgorithm.compute("zshz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zsioz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zsiaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zs").get should equal ("ss") + MetaphoneAlgorithm.compute("zsz").get should equal ("sss") // r - Algorithm.compute("r").get should equal ("r") - Algorithm.compute("zr").get should equal ("sr") - Algorithm.compute("zrz").get should equal ("srs") + MetaphoneAlgorithm.compute("r").get should equal ("r") + MetaphoneAlgorithm.compute("zr").get should equal ("sr") + MetaphoneAlgorithm.compute("zrz").get should equal ("srs") // q - Algorithm.compute("q").get should equal ("k") - Algorithm.compute("zq").get should equal ("sk") - Algorithm.compute("zqz").get should equal ("sks") + MetaphoneAlgorithm.compute("q").get should equal ("k") + MetaphoneAlgorithm.compute("zq").get should equal ("sk") + MetaphoneAlgorithm.compute("zqz").get should equal ("sks") // p - Algorithm.compute("p").get should equal ("p") - Algorithm.compute("zp").get should equal ("sp") - Algorithm.compute("zph").get should equal ("sf") - Algorithm.compute("zpz").get should equal ("sps") + MetaphoneAlgorithm.compute("p").get should equal ("p") + MetaphoneAlgorithm.compute("zp").get should equal ("sp") + MetaphoneAlgorithm.compute("zph").get should equal ("sf") + MetaphoneAlgorithm.compute("zpz").get should equal ("sps") // o - Algorithm.compute("o").get should equal ("o") - Algorithm.compute("zo").get should equal ("s") + MetaphoneAlgorithm.compute("o").get should equal ("o") + MetaphoneAlgorithm.compute("zo").get should equal ("s") // n - Algorithm.compute("n").get should equal ("n") - Algorithm.compute("zn").get should equal ("sn") - Algorithm.compute("znz").get should equal ("sns") + MetaphoneAlgorithm.compute("n").get should equal ("n") + MetaphoneAlgorithm.compute("zn").get should equal ("sn") + MetaphoneAlgorithm.compute("znz").get should equal ("sns") // m - Algorithm.compute("m").get should equal ("m") - Algorithm.compute("zm").get should equal ("sm") - Algorithm.compute("zmz").get should equal ("sms") + MetaphoneAlgorithm.compute("m").get should equal ("m") + MetaphoneAlgorithm.compute("zm").get should equal ("sm") + MetaphoneAlgorithm.compute("zmz").get should equal ("sms") // l - Algorithm.compute("l").get should equal ("l") - Algorithm.compute("zl").get should equal ("sl") - Algorithm.compute("zlz").get should equal ("sls") + MetaphoneAlgorithm.compute("l").get should equal ("l") + MetaphoneAlgorithm.compute("zl").get should equal ("sl") + MetaphoneAlgorithm.compute("zlz").get should equal ("sls") // k - Algorithm.compute("k").get should equal ("k") - Algorithm.compute("zk").get should equal ("sk") - Algorithm.compute("zck").get should equal ("sk") + MetaphoneAlgorithm.compute("k").get should equal ("k") + MetaphoneAlgorithm.compute("zk").get should equal ("sk") + MetaphoneAlgorithm.compute("zck").get should equal ("sk") // j - Algorithm.compute("j").get should equal ("j") - Algorithm.compute("zj").get should equal ("sj") - Algorithm.compute("zjz").get should equal ("sjs") + MetaphoneAlgorithm.compute("j").get should equal ("j") + MetaphoneAlgorithm.compute("zj").get should equal ("sj") + MetaphoneAlgorithm.compute("zjz").get should equal ("sjs") // i - Algorithm.compute("i").get should equal ("i") - Algorithm.compute("zi").get should equal ("s") + MetaphoneAlgorithm.compute("i").get should equal ("i") + MetaphoneAlgorithm.compute("zi").get should equal ("s") // h - Algorithm.compute("h").get should equal ("h") // php wrongly says nothing - Algorithm.compute("zh").get should equal ("sh") // php wrongly says s - Algorithm.compute("zah").get should equal ("s") - Algorithm.compute("zchh").get should equal ("sx") - Algorithm.compute("ha").get should equal ("h") + MetaphoneAlgorithm.compute("h").get should equal ("h") // php wrongly says nothing + MetaphoneAlgorithm.compute("zh").get should equal ("sh") // php wrongly says s + MetaphoneAlgorithm.compute("zah").get should equal ("s") + MetaphoneAlgorithm.compute("zchh").get should equal ("sx") + MetaphoneAlgorithm.compute("ha").get should equal ("h") // g - Algorithm.compute("g").get should equal ("k") - Algorithm.compute("zg").get should equal ("sk") - Algorithm.compute("zgh").get should equal ("skh") // php wrongly says sf - Algorithm.compute("zghz").get should equal ("shs") // php wrongly says sfs - Algorithm.compute("zgha").get should equal ("sh") // php wrongly says sf others wrongly say skh - Algorithm.compute("zgn").get should equal ("sn") - Algorithm.compute("zgns").get should equal ("skns") - Algorithm.compute("zgned").get should equal ("snt") // others wrongly says sknt - Algorithm.compute("zgneds").get should equal ("sknts") // php wrongly says snts - Algorithm.compute("zgi").get should equal ("sj") - Algorithm.compute("zgiz").get should equal ("sjs") - Algorithm.compute("zge").get should equal ("sj") - Algorithm.compute("zgez").get should equal ("sjs") - Algorithm.compute("zgy").get should equal ("sj") - Algorithm.compute("zgyz").get should equal ("sjs") - Algorithm.compute("zgz").get should equal ("sks") + MetaphoneAlgorithm.compute("g").get should equal ("k") + MetaphoneAlgorithm.compute("zg").get should equal ("sk") + MetaphoneAlgorithm.compute("zgh").get should equal ("skh") // php wrongly says sf + MetaphoneAlgorithm.compute("zghz").get should equal ("shs") // php wrongly says sfs + MetaphoneAlgorithm.compute("zgha").get should equal ("sh") // php wrongly says sf others wrongly say skh + MetaphoneAlgorithm.compute("zgn").get should equal ("sn") + MetaphoneAlgorithm.compute("zgns").get should equal ("skns") + MetaphoneAlgorithm.compute("zgned").get should equal ("snt") // others wrongly says sknt + MetaphoneAlgorithm.compute("zgneds").get should equal ("sknts") // php wrongly says snts + MetaphoneAlgorithm.compute("zgi").get should equal ("sj") + MetaphoneAlgorithm.compute("zgiz").get should equal ("sjs") + MetaphoneAlgorithm.compute("zge").get should equal ("sj") + MetaphoneAlgorithm.compute("zgez").get should equal ("sjs") + MetaphoneAlgorithm.compute("zgy").get should equal ("sj") + MetaphoneAlgorithm.compute("zgyz").get should equal ("sjs") + MetaphoneAlgorithm.compute("zgz").get should equal ("sks") // f - Algorithm.compute("f").get should equal ("f") - Algorithm.compute("zf").get should equal ("sf") - Algorithm.compute("zfz").get should equal ("sfs") + MetaphoneAlgorithm.compute("f").get should equal ("f") + MetaphoneAlgorithm.compute("zf").get should equal ("sf") + MetaphoneAlgorithm.compute("zfz").get should equal ("sfs") // e - Algorithm.compute("e").get should equal ("e") - Algorithm.compute("ze").get should equal ("s") + MetaphoneAlgorithm.compute("e").get should equal ("e") + MetaphoneAlgorithm.compute("ze").get should equal ("s") // d - Algorithm.compute("d").get should equal ("t") - Algorithm.compute("fudge").get should equal ("fjj") // php wrongly says fj - Algorithm.compute("dodgy").get should equal ("tjj") // php wrongly says tj others wrongly say tjjy - Algorithm.compute("dodgi").get should equal ("tjj") // php wrongly says tj - Algorithm.compute("zd").get should equal ("st") - Algorithm.compute("zdz").get should equal ("sts") + MetaphoneAlgorithm.compute("d").get should equal ("t") + MetaphoneAlgorithm.compute("fudge").get should equal ("fjj") // php wrongly says fj + MetaphoneAlgorithm.compute("dodgy").get should equal ("tjj") // php wrongly says tj others wrongly say tjjy + MetaphoneAlgorithm.compute("dodgi").get should equal ("tjj") // php wrongly says tj + MetaphoneAlgorithm.compute("zd").get should equal ("st") + MetaphoneAlgorithm.compute("zdz").get should equal ("sts") // c - Algorithm.compute("c").get should equal ("k") - Algorithm.compute("zcia").get should equal ("sx") - Algorithm.compute("zciaz").get should equal ("sxs") - Algorithm.compute("zch").get should equal ("sx") - Algorithm.compute("zchz").get should equal ("sxs") - Algorithm.compute("zci").get should equal ("ss") - Algorithm.compute("zciz").get should equal ("sss") - Algorithm.compute("zce").get should equal ("ss") - Algorithm.compute("zcez").get should equal ("sss") - Algorithm.compute("zcy").get should equal ("ss") - Algorithm.compute("zcyz").get should equal ("sss") - Algorithm.compute("zsci").get should equal ("ss") - Algorithm.compute("zsciz").get should equal ("sss") - Algorithm.compute("zsce").get should equal ("ss") - Algorithm.compute("zscez").get should equal ("sss") - Algorithm.compute("zscy").get should equal ("ss") - Algorithm.compute("zscyz").get should equal ("sss") - Algorithm.compute("zsch").get should equal ("sskh") // php wrongly says ssx - Algorithm.compute("zc").get should equal ("sk") - Algorithm.compute("zcz").get should equal ("sks") + MetaphoneAlgorithm.compute("c").get should equal ("k") + MetaphoneAlgorithm.compute("zcia").get should equal ("sx") + MetaphoneAlgorithm.compute("zciaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zch").get should equal ("sx") + MetaphoneAlgorithm.compute("zchz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zci").get should equal ("ss") + MetaphoneAlgorithm.compute("zciz").get should equal ("sss") + MetaphoneAlgorithm.compute("zce").get should equal ("ss") + MetaphoneAlgorithm.compute("zcez").get should equal ("sss") + MetaphoneAlgorithm.compute("zcy").get should equal ("ss") + MetaphoneAlgorithm.compute("zcyz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsci").get should equal ("ss") + MetaphoneAlgorithm.compute("zsciz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsce").get should equal ("ss") + MetaphoneAlgorithm.compute("zscez").get should equal ("sss") + MetaphoneAlgorithm.compute("zscy").get should equal ("ss") + MetaphoneAlgorithm.compute("zscyz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsch").get should equal ("sskh") // php wrongly says ssx + MetaphoneAlgorithm.compute("zc").get should equal ("sk") + MetaphoneAlgorithm.compute("zcz").get should equal ("sks") // b - Algorithm.compute("b").get should equal ("b") - Algorithm.compute("zb").get should equal ("sb") - Algorithm.compute("zbz").get should equal ("sbs") - Algorithm.compute("zmb").get should equal ("sm") + MetaphoneAlgorithm.compute("b").get should equal ("b") + MetaphoneAlgorithm.compute("zb").get should equal ("sb") + MetaphoneAlgorithm.compute("zbz").get should equal ("sbs") + MetaphoneAlgorithm.compute("zmb").get should equal ("sm") // a - Algorithm.compute("a").get should equal ("a") - Algorithm.compute("za").get should equal ("s") + MetaphoneAlgorithm.compute("a").get should equal ("a") + MetaphoneAlgorithm.compute("za").get should equal ("s") // Miscellaneous. - Algorithm.compute("dumb").get should equal ("tm") - Algorithm.compute("smith").get should equal ("sm0") - Algorithm.compute("school").get should equal ("skhl") // php wrongly says sxl - Algorithm.compute("merci").get should equal ("mrs") - Algorithm.compute("cool").get should equal ("kl") - Algorithm.compute("aebersold").get should equal ("ebrslt") - Algorithm.compute("gnagy").get should equal ("nj") - Algorithm.compute("knuth").get should equal ("n0") - Algorithm.compute("pniewski").get should equal ("nsk") - Algorithm.compute("wright").get should equal ("rht") // php wrongly says rft - Algorithm.compute("phone").get should equal ("fn") - Algorithm.compute("aggregate").get should equal ("akrkt") - Algorithm.compute("accuracy").get should equal ("akkrs") - Algorithm.compute("encyclopedia").get should equal ("ensklpt") - Algorithm.compute("honorificabilitudinitatibus").get should equal ("hnrfkblttnttbs") - Algorithm.compute("antidisestablishmentarianism").get should equal ("anttsstblxmntrnsm") + MetaphoneAlgorithm.compute("dumb").get should equal ("tm") + MetaphoneAlgorithm.compute("smith").get should equal ("sm0") + MetaphoneAlgorithm.compute("school").get should equal ("skhl") // php wrongly says sxl + MetaphoneAlgorithm.compute("merci").get should equal ("mrs") + MetaphoneAlgorithm.compute("cool").get should equal ("kl") + MetaphoneAlgorithm.compute("aebersold").get should equal ("ebrslt") + MetaphoneAlgorithm.compute("gnagy").get should equal ("nj") + MetaphoneAlgorithm.compute("knuth").get should equal ("n0") + MetaphoneAlgorithm.compute("pniewski").get should equal ("nsk") + MetaphoneAlgorithm.compute("wright").get should equal ("rht") // php wrongly says rft + MetaphoneAlgorithm.compute("phone").get should equal ("fn") + MetaphoneAlgorithm.compute("aggregate").get should equal ("akrkt") + MetaphoneAlgorithm.compute("accuracy").get should equal ("akkrs") + MetaphoneAlgorithm.compute("encyclopedia").get should equal ("ensklpt") + MetaphoneAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hnrfkblttnttbs") + MetaphoneAlgorithm.compute("antidisestablishmentarianism").get should equal ("anttsstblxmntrnsm") } } } } - "MetaphoneAlgorithm companion object" should provide { - "pass-through compute method" should returns { - "same value as class" in { - MetaphoneAlgorithm.compute("dumb").get should equal ("tm") - } - } - } -} - -object MetaphoneAlgorithmSpec { - final private val Algorithm = MetaphoneAlgorithm() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala index 9a029d8..94ff5db 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala @@ -6,49 +6,36 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class MetaphoneMetricSpec extends ScalaTest { - import MetaphoneMetricSpec.Metric - "MetaphoneMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + MetaphoneMetric.compare("", "").isDefined should be (false) + MetaphoneMetric.compare("abc", "").isDefined should be (false) + MetaphoneMetric.compare("", "xyz").isDefined should be (false) } } "non-phonetic arguments" should returns { "None" in { - Metric.compare("123", "123").isDefined should be (false) - Metric.compare("123", "").isDefined should be (false) - Metric.compare("", "123").isDefined should be (false) + MetaphoneMetric.compare("123", "123").isDefined should be (false) + MetaphoneMetric.compare("123", "").isDefined should be (false) + MetaphoneMetric.compare("", "123").isDefined should be (false) } } "phonetically similar arguments" should returns { "Boolean indicating true" in { - Metric.compare("dumb", "dum").get should be (true) - Metric.compare("smith", "smeth").get should be (true) - Metric.compare("merci", "mercy").get should be (true) + MetaphoneMetric.compare("dumb", "dum").get should be (true) + MetaphoneMetric.compare("smith", "smeth").get should be (true) + MetaphoneMetric.compare("merci", "mercy").get should be (true) } } "phonetically dissimilar arguments" should returns { "Boolean indicating false" in { - Metric.compare("dumb", "gum").get should be (false) - Metric.compare("smith", "kiss").get should be (false) - Metric.compare("merci", "burpy").get should be (false) + MetaphoneMetric.compare("dumb", "gum").get should be (false) + MetaphoneMetric.compare("smith", "kiss").get should be (false) + MetaphoneMetric.compare("merci", "burpy").get should be (false) } } } } - "MetaphoneMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - MetaphoneMetric.compare("dumb", "gum").get should be (false) - } - } - } -} - -object MetaphoneMetricSpec { - final private val Metric = MetaphoneMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala index 6a0f113..dea95b8 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala @@ -6,199 +6,186 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class NysiisAlgorithmSpec extends ScalaTest { - import NysiisAlgorithmSpec.Algorithm - "NysiisAlgorithm" should provide { "compute method" when passed { "empty argument" should returns { "None" in { - Algorithm.compute("").isDefined should be (false) + NysiisAlgorithm.compute("").isDefined should be (false) } } "non-phonetic argument" should returns { "None" in { - Algorithm.compute("123").isDefined should be (false) + NysiisAlgorithm.compute("123").isDefined should be (false) } } "phonetic argument" should returns { "Some" in { // a - Algorithm.compute("a").get should equal ("a") - Algorithm.compute("aa").get should equal ("a") + NysiisAlgorithm.compute("a").get should equal ("a") + NysiisAlgorithm.compute("aa").get should equal ("a") // b - Algorithm.compute("b").get should equal ("b") - Algorithm.compute("bb").get should equal ("bb") + NysiisAlgorithm.compute("b").get should equal ("b") + NysiisAlgorithm.compute("bb").get should equal ("bb") // c - Algorithm.compute("c").get should equal ("c") - Algorithm.compute("cc").get should equal ("cc") + NysiisAlgorithm.compute("c").get should equal ("c") + NysiisAlgorithm.compute("cc").get should equal ("cc") // d - Algorithm.compute("d").get should equal ("d") - Algorithm.compute("dd").get should equal ("dd") + NysiisAlgorithm.compute("d").get should equal ("d") + NysiisAlgorithm.compute("dd").get should equal ("dd") // e - Algorithm.compute("e").get should equal ("e") - Algorithm.compute("ee").get should equal ("y") + NysiisAlgorithm.compute("e").get should equal ("e") + NysiisAlgorithm.compute("ee").get should equal ("y") // f - Algorithm.compute("f").get should equal ("f") - Algorithm.compute("ff").get should equal ("ff") + NysiisAlgorithm.compute("f").get should equal ("f") + NysiisAlgorithm.compute("ff").get should equal ("ff") // g - Algorithm.compute("g").get should equal ("g") - Algorithm.compute("gg").get should equal ("gg") + NysiisAlgorithm.compute("g").get should equal ("g") + NysiisAlgorithm.compute("gg").get should equal ("gg") // h - Algorithm.compute("h").get should equal ("h") - Algorithm.compute("hh").get should equal ("hh") + NysiisAlgorithm.compute("h").get should equal ("h") + NysiisAlgorithm.compute("hh").get should equal ("hh") // i - Algorithm.compute("i").get should equal ("i") - Algorithm.compute("ii").get should equal ("i") + NysiisAlgorithm.compute("i").get should equal ("i") + NysiisAlgorithm.compute("ii").get should equal ("i") // j - Algorithm.compute("j").get should equal ("j") - Algorithm.compute("jj").get should equal ("jj") + NysiisAlgorithm.compute("j").get should equal ("j") + NysiisAlgorithm.compute("jj").get should equal ("jj") // k - Algorithm.compute("k").get should equal ("c") - Algorithm.compute("kk").get should equal ("cc") + NysiisAlgorithm.compute("k").get should equal ("c") + NysiisAlgorithm.compute("kk").get should equal ("cc") // l - Algorithm.compute("l").get should equal ("l") - Algorithm.compute("ll").get should equal ("ll") + NysiisAlgorithm.compute("l").get should equal ("l") + NysiisAlgorithm.compute("ll").get should equal ("ll") // m - Algorithm.compute("m").get should equal ("m") - Algorithm.compute("mm").get should equal ("mn") + NysiisAlgorithm.compute("m").get should equal ("m") + NysiisAlgorithm.compute("mm").get should equal ("mn") // n - Algorithm.compute("n").get should equal ("n") - Algorithm.compute("nn").get should equal ("nn") + NysiisAlgorithm.compute("n").get should equal ("n") + NysiisAlgorithm.compute("nn").get should equal ("nn") // o - Algorithm.compute("o").get should equal ("o") - Algorithm.compute("oo").get should equal ("o") + NysiisAlgorithm.compute("o").get should equal ("o") + NysiisAlgorithm.compute("oo").get should equal ("o") // p - Algorithm.compute("p").get should equal ("p") - Algorithm.compute("pp").get should equal ("pp") + NysiisAlgorithm.compute("p").get should equal ("p") + NysiisAlgorithm.compute("pp").get should equal ("pp") // q - Algorithm.compute("q").get should equal ("q") - Algorithm.compute("qq").get should equal ("qg") + NysiisAlgorithm.compute("q").get should equal ("q") + NysiisAlgorithm.compute("qq").get should equal ("qg") // r - Algorithm.compute("r").get should equal ("r") - Algorithm.compute("rr").get should equal ("rr") + NysiisAlgorithm.compute("r").get should equal ("r") + NysiisAlgorithm.compute("rr").get should equal ("rr") // s - Algorithm.compute("s").get should equal ("s") - Algorithm.compute("ss").get should equal ("s") + NysiisAlgorithm.compute("s").get should equal ("s") + NysiisAlgorithm.compute("ss").get should equal ("s") // t - Algorithm.compute("t").get should equal ("t") - Algorithm.compute("tt").get should equal ("tt") + NysiisAlgorithm.compute("t").get should equal ("t") + NysiisAlgorithm.compute("tt").get should equal ("tt") // u - Algorithm.compute("u").get should equal ("u") - Algorithm.compute("uu").get should equal ("u") + NysiisAlgorithm.compute("u").get should equal ("u") + NysiisAlgorithm.compute("uu").get should equal ("u") // v - Algorithm.compute("v").get should equal ("v") - Algorithm.compute("vv").get should equal ("vv") + NysiisAlgorithm.compute("v").get should equal ("v") + NysiisAlgorithm.compute("vv").get should equal ("vv") // w - Algorithm.compute("w").get should equal ("w") - Algorithm.compute("ww").get should equal ("ww") + NysiisAlgorithm.compute("w").get should equal ("w") + NysiisAlgorithm.compute("ww").get should equal ("ww") // x - Algorithm.compute("x").get should equal ("x") - Algorithm.compute("xx").get should equal ("xx") + NysiisAlgorithm.compute("x").get should equal ("x") + NysiisAlgorithm.compute("xx").get should equal ("xx") // y - Algorithm.compute("y").get should equal ("y") - Algorithm.compute("yy").get should equal ("yy") + NysiisAlgorithm.compute("y").get should equal ("y") + NysiisAlgorithm.compute("yy").get should equal ("yy") // z - Algorithm.compute("z").get should equal ("z") - Algorithm.compute("zz").get should equal ("z") + NysiisAlgorithm.compute("z").get should equal ("z") + NysiisAlgorithm.compute("zz").get should equal ("z") // Head cases. - Algorithm.compute("mac").get should equal ("mc") - Algorithm.compute("kn").get should equal ("nn") - Algorithm.compute("k").get should equal ("c") - Algorithm.compute("ph").get should equal ("ff") - Algorithm.compute("pf").get should equal ("ff") - Algorithm.compute("sch").get should equal ("s") // dropby wrongly says ss + NysiisAlgorithm.compute("mac").get should equal ("mc") + NysiisAlgorithm.compute("kn").get should equal ("nn") + NysiisAlgorithm.compute("k").get should equal ("c") + NysiisAlgorithm.compute("ph").get should equal ("ff") + NysiisAlgorithm.compute("pf").get should equal ("ff") + NysiisAlgorithm.compute("sch").get should equal ("s") // dropby wrongly says ss // Last cases. - Algorithm.compute("ee").get should equal ("y") - Algorithm.compute("ie").get should equal ("y") - Algorithm.compute("dt").get should equal ("d") - Algorithm.compute("rt").get should equal ("d") - Algorithm.compute("rd").get should equal ("d") - Algorithm.compute("nt").get should equal ("d") - Algorithm.compute("nd").get should equal ("d") + NysiisAlgorithm.compute("ee").get should equal ("y") + NysiisAlgorithm.compute("ie").get should equal ("y") + NysiisAlgorithm.compute("dt").get should equal ("d") + NysiisAlgorithm.compute("rt").get should equal ("d") + NysiisAlgorithm.compute("rd").get should equal ("d") + NysiisAlgorithm.compute("nt").get should equal ("d") + NysiisAlgorithm.compute("nd").get should equal ("d") // Core cases. - Algorithm.compute("eev").get should equal ("eaf") - Algorithm.compute("zev").get should equal ("zaf") - Algorithm.compute("kkn").get should equal ("cn") - Algorithm.compute("sschn").get should equal ("ssn") - Algorithm.compute("pph").get should equal ("pf") + NysiisAlgorithm.compute("eev").get should equal ("eaf") + NysiisAlgorithm.compute("zev").get should equal ("zaf") + NysiisAlgorithm.compute("kkn").get should equal ("cn") + NysiisAlgorithm.compute("sschn").get should equal ("ssn") + NysiisAlgorithm.compute("pph").get should equal ("pf") // Miscellaneous. - Algorithm.compute("macdonald").get should equal ("mcdanald") - Algorithm.compute("phone").get should equal ("ffan") - Algorithm.compute("aggregate").get should equal ("agragat") - Algorithm.compute("accuracy").get should equal ("acaracy") - Algorithm.compute("encyclopedia").get should equal ("encyclapad") - Algorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") - Algorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") + NysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + NysiisAlgorithm.compute("phone").get should equal ("ffan") + NysiisAlgorithm.compute("aggregate").get should equal ("agragat") + NysiisAlgorithm.compute("accuracy").get should equal ("acaracy") + NysiisAlgorithm.compute("encyclopedia").get should equal ("encyclapad") + NysiisAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") + NysiisAlgorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") // Dropby. - Algorithm.compute("macintosh").get should equal ("mcant") - Algorithm.compute("knuth").get should equal ("nnat") - Algorithm.compute("koehn").get should equal ("can") // dropby wrongly says c - Algorithm.compute("phillipson").get should equal ("ffalapsan") - Algorithm.compute("pfeister").get should equal ("ffastar") - Algorithm.compute("schoenhoeft").get should equal ("ssanaft") - Algorithm.compute("mckee").get should equal ("mcy") - Algorithm.compute("heitschmedt").get should equal ("hatsnad") - Algorithm.compute("bart").get should equal ("bad") - Algorithm.compute("hurd").get should equal ("had") - Algorithm.compute("hunt").get should equal ("had") - Algorithm.compute("westerlund").get should equal ("wastarlad") - Algorithm.compute("casstevens").get should equal ("castafan") - Algorithm.compute("vasquez").get should equal ("vasg") - Algorithm.compute("frazier").get should equal ("frasar") - Algorithm.compute("bowman").get should equal ("banan") - Algorithm.compute("mcknight").get should equal ("mcnagt") - Algorithm.compute("rickert").get should equal ("racad") - Algorithm.compute("deutsch").get should equal ("dat") // dropby wrongly says dats - Algorithm.compute("westphal").get should equal ("wastfal") - Algorithm.compute("shriver").get should equal ("shravar") - Algorithm.compute("kuhl").get should equal ("cal") // dropby wrongly says c - Algorithm.compute("rawson").get should equal ("rasan") - Algorithm.compute("jiles").get should equal ("jal") - Algorithm.compute("carraway").get should equal ("caray") - Algorithm.compute("yamada").get should equal ("yanad") + NysiisAlgorithm.compute("macintosh").get should equal ("mcant") + NysiisAlgorithm.compute("knuth").get should equal ("nnat") + NysiisAlgorithm.compute("koehn").get should equal ("can") // dropby wrongly says c + NysiisAlgorithm.compute("phillipson").get should equal ("ffalapsan") + NysiisAlgorithm.compute("pfeister").get should equal ("ffastar") + NysiisAlgorithm.compute("schoenhoeft").get should equal ("ssanaft") + NysiisAlgorithm.compute("mckee").get should equal ("mcy") + NysiisAlgorithm.compute("heitschmedt").get should equal ("hatsnad") + NysiisAlgorithm.compute("bart").get should equal ("bad") + NysiisAlgorithm.compute("hurd").get should equal ("had") + NysiisAlgorithm.compute("hunt").get should equal ("had") + NysiisAlgorithm.compute("westerlund").get should equal ("wastarlad") + NysiisAlgorithm.compute("casstevens").get should equal ("castafan") + NysiisAlgorithm.compute("vasquez").get should equal ("vasg") + NysiisAlgorithm.compute("frazier").get should equal ("frasar") + NysiisAlgorithm.compute("bowman").get should equal ("banan") + NysiisAlgorithm.compute("mcknight").get should equal ("mcnagt") + NysiisAlgorithm.compute("rickert").get should equal ("racad") + NysiisAlgorithm.compute("deutsch").get should equal ("dat") // dropby wrongly says dats + NysiisAlgorithm.compute("westphal").get should equal ("wastfal") + NysiisAlgorithm.compute("shriver").get should equal ("shravar") + NysiisAlgorithm.compute("kuhl").get should equal ("cal") // dropby wrongly says c + NysiisAlgorithm.compute("rawson").get should equal ("rasan") + NysiisAlgorithm.compute("jiles").get should equal ("jal") + NysiisAlgorithm.compute("carraway").get should equal ("caray") + NysiisAlgorithm.compute("yamada").get should equal ("yanad") } } } } - "NysiisAlgorithm companion object" should provide { - "pass-through compute method" should returns { - "same value as class" in { - NysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") - } - } - } -} - -object NysiisAlgorithmSpec { - final private val Algorithm = NysiisAlgorithm() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala index c6929a2..7e52101 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala @@ -6,45 +6,32 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class NysiisMetricSpec extends ScalaTest { - import NysiisMetricSpec.Metric - "NysiisMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + NysiisMetric.compare("", "").isDefined should be (false) + NysiisMetric.compare("abc", "").isDefined should be (false) + NysiisMetric.compare("", "xyz").isDefined should be (false) } } "non-phonetic arguments" should returns { "None" in { - Metric.compare("123", "123").isDefined should be (false) - Metric.compare("123", "").isDefined should be (false) - Metric.compare("", "123").isDefined should be (false) + NysiisMetric.compare("123", "123").isDefined should be (false) + NysiisMetric.compare("123", "").isDefined should be (false) + NysiisMetric.compare("", "123").isDefined should be (false) } } "phonetically similar arguments" should returns { "Boolean indicating true" in { - Metric.compare("ham", "hum").get should be (true) + NysiisMetric.compare("ham", "hum").get should be (true) } } "phonetically dissimilar arguments" should returns { "Boolean indicating false" in { - Metric.compare("dumb", "gum").get should be (false) + NysiisMetric.compare("dumb", "gum").get should be (false) } } } } - "NysiisMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - NysiisMetric.compare("dumb", "gum").get should be (false) - } - } - } -} - -object NysiisMetricSpec { - final private val Metric = NysiisMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala index 1298d2d..eaa09ce 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala @@ -6,216 +6,203 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class RefinedNysiisAlgorithmSpec extends ScalaTest { - import RefinedNysiisAlgorithmSpec.Algorithm - "RefinedNysiisAlgorithm" should provide { "compute method" when passed { "empty argument" should returns { "None" in { - Algorithm.compute("").isDefined should be (false) + RefinedNysiisAlgorithm.compute("").isDefined should be (false) } } "non-phonetic argument" should returns { "None" in { - Algorithm.compute("123").isDefined should be (false) + RefinedNysiisAlgorithm.compute("123").isDefined should be (false) } } "phonetic argument" should returns { "Some" in { // a - Algorithm.compute("a").get should equal ("a") - Algorithm.compute("aa").get should equal ("a") + RefinedNysiisAlgorithm.compute("a").get should equal ("a") + RefinedNysiisAlgorithm.compute("aa").get should equal ("a") // b - Algorithm.compute("b").get should equal ("b") - Algorithm.compute("bb").get should equal ("b") + RefinedNysiisAlgorithm.compute("b").get should equal ("b") + RefinedNysiisAlgorithm.compute("bb").get should equal ("b") // c - Algorithm.compute("c").get should equal ("c") - Algorithm.compute("cc").get should equal ("c") + RefinedNysiisAlgorithm.compute("c").get should equal ("c") + RefinedNysiisAlgorithm.compute("cc").get should equal ("c") // d - Algorithm.compute("d").get should equal ("d") - Algorithm.compute("dd").get should equal ("d") + RefinedNysiisAlgorithm.compute("d").get should equal ("d") + RefinedNysiisAlgorithm.compute("dd").get should equal ("d") // e - Algorithm.compute("e").get should equal ("e") - Algorithm.compute("ee").get should equal ("y") + RefinedNysiisAlgorithm.compute("e").get should equal ("e") + RefinedNysiisAlgorithm.compute("ee").get should equal ("y") // f - Algorithm.compute("f").get should equal ("f") - Algorithm.compute("ff").get should equal ("f") + RefinedNysiisAlgorithm.compute("f").get should equal ("f") + RefinedNysiisAlgorithm.compute("ff").get should equal ("f") // g - Algorithm.compute("g").get should equal ("g") - Algorithm.compute("gg").get should equal ("g") + RefinedNysiisAlgorithm.compute("g").get should equal ("g") + RefinedNysiisAlgorithm.compute("gg").get should equal ("g") // h - Algorithm.compute("h").get should equal ("h") - Algorithm.compute("hh").get should equal ("h") + RefinedNysiisAlgorithm.compute("h").get should equal ("h") + RefinedNysiisAlgorithm.compute("hh").get should equal ("h") // i - Algorithm.compute("i").get should equal ("i") - Algorithm.compute("ii").get should equal ("i") + RefinedNysiisAlgorithm.compute("i").get should equal ("i") + RefinedNysiisAlgorithm.compute("ii").get should equal ("i") // j - Algorithm.compute("j").get should equal ("j") - Algorithm.compute("jj").get should equal ("j") + RefinedNysiisAlgorithm.compute("j").get should equal ("j") + RefinedNysiisAlgorithm.compute("jj").get should equal ("j") // k - Algorithm.compute("k").get should equal ("c") - Algorithm.compute("kk").get should equal ("c") + RefinedNysiisAlgorithm.compute("k").get should equal ("c") + RefinedNysiisAlgorithm.compute("kk").get should equal ("c") // l - Algorithm.compute("l").get should equal ("l") - Algorithm.compute("ll").get should equal ("l") + RefinedNysiisAlgorithm.compute("l").get should equal ("l") + RefinedNysiisAlgorithm.compute("ll").get should equal ("l") // m - Algorithm.compute("m").get should equal ("m") - Algorithm.compute("mm").get should equal ("mn") + RefinedNysiisAlgorithm.compute("m").get should equal ("m") + RefinedNysiisAlgorithm.compute("mm").get should equal ("mn") // n - Algorithm.compute("n").get should equal ("n") - Algorithm.compute("nn").get should equal ("n") + RefinedNysiisAlgorithm.compute("n").get should equal ("n") + RefinedNysiisAlgorithm.compute("nn").get should equal ("n") // o - Algorithm.compute("o").get should equal ("o") - Algorithm.compute("oo").get should equal ("o") + RefinedNysiisAlgorithm.compute("o").get should equal ("o") + RefinedNysiisAlgorithm.compute("oo").get should equal ("o") // p - Algorithm.compute("p").get should equal ("p") - Algorithm.compute("pp").get should equal ("p") + RefinedNysiisAlgorithm.compute("p").get should equal ("p") + RefinedNysiisAlgorithm.compute("pp").get should equal ("p") // q - Algorithm.compute("q").get should equal ("q") - Algorithm.compute("qq").get should equal ("qg") + RefinedNysiisAlgorithm.compute("q").get should equal ("q") + RefinedNysiisAlgorithm.compute("qq").get should equal ("qg") // r - Algorithm.compute("r").get should equal ("r") - Algorithm.compute("rr").get should equal ("r") + RefinedNysiisAlgorithm.compute("r").get should equal ("r") + RefinedNysiisAlgorithm.compute("rr").get should equal ("r") // s - Algorithm.compute("s").get should equal ("s") - Algorithm.compute("ss").get should equal ("s") + RefinedNysiisAlgorithm.compute("s").get should equal ("s") + RefinedNysiisAlgorithm.compute("ss").get should equal ("s") // t - Algorithm.compute("t").get should equal ("t") - Algorithm.compute("tt").get should equal ("t") + RefinedNysiisAlgorithm.compute("t").get should equal ("t") + RefinedNysiisAlgorithm.compute("tt").get should equal ("t") // u - Algorithm.compute("u").get should equal ("u") - Algorithm.compute("uu").get should equal ("u") + RefinedNysiisAlgorithm.compute("u").get should equal ("u") + RefinedNysiisAlgorithm.compute("uu").get should equal ("u") // v - Algorithm.compute("v").get should equal ("v") - Algorithm.compute("vv").get should equal ("v") + RefinedNysiisAlgorithm.compute("v").get should equal ("v") + RefinedNysiisAlgorithm.compute("vv").get should equal ("v") // w - Algorithm.compute("w").get should equal ("w") - Algorithm.compute("ww").get should equal ("w") + RefinedNysiisAlgorithm.compute("w").get should equal ("w") + RefinedNysiisAlgorithm.compute("ww").get should equal ("w") // x - Algorithm.compute("x").get should equal ("x") - Algorithm.compute("xx").get should equal ("x") + RefinedNysiisAlgorithm.compute("x").get should equal ("x") + RefinedNysiisAlgorithm.compute("xx").get should equal ("x") // y - Algorithm.compute("y").get should equal ("y") - Algorithm.compute("yy").get should equal ("y") - Algorithm.compute("ybyb").get should equal ("ybab") + RefinedNysiisAlgorithm.compute("y").get should equal ("y") + RefinedNysiisAlgorithm.compute("yy").get should equal ("y") + RefinedNysiisAlgorithm.compute("ybyb").get should equal ("ybab") // z - Algorithm.compute("z").get should equal ("z") - Algorithm.compute("zz").get should equal ("z") + RefinedNysiisAlgorithm.compute("z").get should equal ("z") + RefinedNysiisAlgorithm.compute("zz").get should equal ("z") // Head cases. - Algorithm.compute("mac").get should equal ("mc") - Algorithm.compute("pf").get should equal ("f") + RefinedNysiisAlgorithm.compute("mac").get should equal ("mc") + RefinedNysiisAlgorithm.compute("pf").get should equal ("f") // Last cases. - Algorithm.compute("ix").get should equal ("ic") - Algorithm.compute("ex").get should equal ("ec") - Algorithm.compute("ye").get should equal ("y") - Algorithm.compute("ee").get should equal ("y") - Algorithm.compute("ie").get should equal ("y") - Algorithm.compute("dt").get should equal ("d") - Algorithm.compute("rt").get should equal ("d") - Algorithm.compute("rd").get should equal ("d") - Algorithm.compute("nt").get should equal ("d") - Algorithm.compute("nd").get should equal ("d") + RefinedNysiisAlgorithm.compute("ix").get should equal ("ic") + RefinedNysiisAlgorithm.compute("ex").get should equal ("ec") + RefinedNysiisAlgorithm.compute("ye").get should equal ("y") + RefinedNysiisAlgorithm.compute("ee").get should equal ("y") + RefinedNysiisAlgorithm.compute("ie").get should equal ("y") + RefinedNysiisAlgorithm.compute("dt").get should equal ("d") + RefinedNysiisAlgorithm.compute("rt").get should equal ("d") + RefinedNysiisAlgorithm.compute("rd").get should equal ("d") + RefinedNysiisAlgorithm.compute("nt").get should equal ("d") + RefinedNysiisAlgorithm.compute("nd").get should equal ("d") // Core cases. - Algorithm.compute("bevb").get should equal ("bafb") - Algorithm.compute("bghtb").get should equal ("bgtb") - Algorithm.compute("bdgb").get should equal ("bgb") - Algorithm.compute("bphb").get should equal ("bfb") - Algorithm.compute("bknb").get should equal ("bnb") - Algorithm.compute("bshb").get should equal ("bsb") - Algorithm.compute("bschb").get should equal ("bsb") - Algorithm.compute("bywb").get should equal ("bab") - Algorithm.compute("byw").get should equal ("by") - Algorithm.compute("ywb").get should equal ("yb") - Algorithm.compute("bwrb").get should equal ("brb") + RefinedNysiisAlgorithm.compute("bevb").get should equal ("bafb") + RefinedNysiisAlgorithm.compute("bghtb").get should equal ("bgtb") + RefinedNysiisAlgorithm.compute("bdgb").get should equal ("bgb") + RefinedNysiisAlgorithm.compute("bphb").get should equal ("bfb") + RefinedNysiisAlgorithm.compute("bknb").get should equal ("bnb") + RefinedNysiisAlgorithm.compute("bshb").get should equal ("bsb") + RefinedNysiisAlgorithm.compute("bschb").get should equal ("bsb") + RefinedNysiisAlgorithm.compute("bywb").get should equal ("bab") + RefinedNysiisAlgorithm.compute("byw").get should equal ("by") + RefinedNysiisAlgorithm.compute("ywb").get should equal ("yb") + RefinedNysiisAlgorithm.compute("bwrb").get should equal ("brb") // Transcode cases. - Algorithm.compute("bay").get should equal ("by") + RefinedNysiisAlgorithm.compute("bay").get should equal ("by") // Miscellaneous. - Algorithm.compute("macdonald").get should equal ("mcdanald") - Algorithm.compute("phone").get should equal ("fan") - Algorithm.compute("aggregate").get should equal ("agragat") - Algorithm.compute("accuracy").get should equal ("acaracy") - Algorithm.compute("encyclopedia").get should equal ("encaclapad") - Algorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") - Algorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") + RefinedNysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + RefinedNysiisAlgorithm.compute("phone").get should equal ("fan") + RefinedNysiisAlgorithm.compute("aggregate").get should equal ("agragat") + RefinedNysiisAlgorithm.compute("accuracy").get should equal ("acaracy") + RefinedNysiisAlgorithm.compute("encyclopedia").get should equal ("encaclapad") + RefinedNysiisAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") + RefinedNysiisAlgorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") // Dropby. - Algorithm.compute("edwards").get should equal ("edwad") - Algorithm.compute("parez").get should equal ("par") - Algorithm.compute("macintosh").get should equal ("mcantas") - Algorithm.compute("phillipson").get should equal ("falapsan") - Algorithm.compute("haddix").get should equal ("hadac") - Algorithm.compute("essex").get should equal ("esac") - Algorithm.compute("moye").get should equal ("my") - Algorithm.compute("mckee").get should equal ("mcy") - Algorithm.compute("mackie").get should equal ("mcy") - Algorithm.compute("heitschmidt").get should equal ("hatsnad") - Algorithm.compute("bart").get should equal ("bad") - Algorithm.compute("hurd").get should equal ("had") - Algorithm.compute("hunt").get should equal ("had") - Algorithm.compute("westerlund").get should equal ("wastarlad") - Algorithm.compute("evers").get should equal ("evar") - Algorithm.compute("devito").get should equal ("dafat") - Algorithm.compute("rawson").get should equal ("rasan") - Algorithm.compute("shoulders").get should equal ("saldar") - Algorithm.compute("leighton").get should equal ("lagtan") - Algorithm.compute("wooldridge").get should equal ("waldrag") - Algorithm.compute("oliphant").get should equal ("olafad") - Algorithm.compute("hatchett").get should equal ("hatcat") - Algorithm.compute("mcknight").get should equal ("mcnagt") - Algorithm.compute("rickert").get should equal ("racad") - Algorithm.compute("bowman").get should equal ("banan") - Algorithm.compute("vasquez").get should equal ("vasg") - Algorithm.compute("bashaw").get should equal ("bas") - Algorithm.compute("schoenhoeft").get should equal ("sanaft") // dropby wrongly says scanaft - Algorithm.compute("heywood").get should equal ("had") - Algorithm.compute("hayman").get should equal ("hanan") - Algorithm.compute("seawright").get should equal ("saragt") - Algorithm.compute("kratzer").get should equal ("cratsar") - Algorithm.compute("canaday").get should equal ("canady") - Algorithm.compute("crepeau").get should equal ("crap") + RefinedNysiisAlgorithm.compute("edwards").get should equal ("edwad") + RefinedNysiisAlgorithm.compute("parez").get should equal ("par") + RefinedNysiisAlgorithm.compute("macintosh").get should equal ("mcantas") + RefinedNysiisAlgorithm.compute("phillipson").get should equal ("falapsan") + RefinedNysiisAlgorithm.compute("haddix").get should equal ("hadac") + RefinedNysiisAlgorithm.compute("essex").get should equal ("esac") + RefinedNysiisAlgorithm.compute("moye").get should equal ("my") + RefinedNysiisAlgorithm.compute("mckee").get should equal ("mcy") + RefinedNysiisAlgorithm.compute("mackie").get should equal ("mcy") + RefinedNysiisAlgorithm.compute("heitschmidt").get should equal ("hatsnad") + RefinedNysiisAlgorithm.compute("bart").get should equal ("bad") + RefinedNysiisAlgorithm.compute("hurd").get should equal ("had") + RefinedNysiisAlgorithm.compute("hunt").get should equal ("had") + RefinedNysiisAlgorithm.compute("westerlund").get should equal ("wastarlad") + RefinedNysiisAlgorithm.compute("evers").get should equal ("evar") + RefinedNysiisAlgorithm.compute("devito").get should equal ("dafat") + RefinedNysiisAlgorithm.compute("rawson").get should equal ("rasan") + RefinedNysiisAlgorithm.compute("shoulders").get should equal ("saldar") + RefinedNysiisAlgorithm.compute("leighton").get should equal ("lagtan") + RefinedNysiisAlgorithm.compute("wooldridge").get should equal ("waldrag") + RefinedNysiisAlgorithm.compute("oliphant").get should equal ("olafad") + RefinedNysiisAlgorithm.compute("hatchett").get should equal ("hatcat") + RefinedNysiisAlgorithm.compute("mcknight").get should equal ("mcnagt") + RefinedNysiisAlgorithm.compute("rickert").get should equal ("racad") + RefinedNysiisAlgorithm.compute("bowman").get should equal ("banan") + RefinedNysiisAlgorithm.compute("vasquez").get should equal ("vasg") + RefinedNysiisAlgorithm.compute("bashaw").get should equal ("bas") + RefinedNysiisAlgorithm.compute("schoenhoeft").get should equal ("sanaft") // dropby wrongly says scanaft + RefinedNysiisAlgorithm.compute("heywood").get should equal ("had") + RefinedNysiisAlgorithm.compute("hayman").get should equal ("hanan") + RefinedNysiisAlgorithm.compute("seawright").get should equal ("saragt") + RefinedNysiisAlgorithm.compute("kratzer").get should equal ("cratsar") + RefinedNysiisAlgorithm.compute("canaday").get should equal ("canady") + RefinedNysiisAlgorithm.compute("crepeau").get should equal ("crap") } } } } - "RefinedNysiisAlgorithm companion object" should provide { - "pass-through compute method" should returns { - "same value as class" in { - RefinedNysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") - } - } - } -} - -object RefinedNysiisAlgorithmSpec { - final private val Algorithm = RefinedNysiisAlgorithm() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala index ca9d2ec..8ac87e1 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala @@ -6,45 +6,32 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class RefinedNysiisMetricSpec extends ScalaTest { - import RefinedNysiisMetricSpec.Metric - "RefinedNysiisMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + RefinedNysiisMetric.compare("", "").isDefined should be (false) + RefinedNysiisMetric.compare("abc", "").isDefined should be (false) + RefinedNysiisMetric.compare("", "xyz").isDefined should be (false) } } "non-phonetic arguments" should returns { "None" in { - Metric.compare("123", "123").isDefined should be (false) - Metric.compare("123", "").isDefined should be (false) - Metric.compare("", "123").isDefined should be (false) + RefinedNysiisMetric.compare("123", "123").isDefined should be (false) + RefinedNysiisMetric.compare("123", "").isDefined should be (false) + RefinedNysiisMetric.compare("", "123").isDefined should be (false) } } "phonetically similar arguments" should returns { "Boolean indicating true" in { - Metric.compare("ham", "hum").get should be (true) + RefinedNysiisMetric.compare("ham", "hum").get should be (true) } } "phonetically dissimilar arguments" should returns { "Boolean indicating false" in { - Metric.compare("dumb", "gum").get should be (false) + RefinedNysiisMetric.compare("dumb", "gum").get should be (false) } } } } - "RefinedNysiisMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - RefinedNysiisMetric.compare("dumb", "gum").get should be (false) - } - } - } -} - -object RefinedNysiisMetricSpec { - final private val Metric = RefinedNysiisMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala index 254bf06..cc6dc37 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala @@ -6,170 +6,157 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class RefinedSoundexAlgorithmSpec extends ScalaTest { - import RefinedSoundexAlgorithmSpec.Algorithm - "RefinedSoundexAlgorithm" should provide { "compute method" when passed { "empty argument" should returns { "None" in { - Algorithm.compute("").isDefined should be (false) + RefinedSoundexAlgorithm.compute("").isDefined should be (false) } } "non-phonetic argument" should returns { "None" in { - Algorithm.compute("123").isDefined should be (false) + RefinedSoundexAlgorithm.compute("123").isDefined should be (false) } } "phonetic argument" should returns { "Some" in { // a - Algorithm.compute("a").get should equal ("a0") - Algorithm.compute("aa").get should equal ("a0") + RefinedSoundexAlgorithm.compute("a").get should equal ("a0") + RefinedSoundexAlgorithm.compute("aa").get should equal ("a0") // b - Algorithm.compute("b").get should equal ("b1") - Algorithm.compute("bb").get should equal ("b1") + RefinedSoundexAlgorithm.compute("b").get should equal ("b1") + RefinedSoundexAlgorithm.compute("bb").get should equal ("b1") // c - Algorithm.compute("c").get should equal ("c3") - Algorithm.compute("cc").get should equal ("c3") + RefinedSoundexAlgorithm.compute("c").get should equal ("c3") + RefinedSoundexAlgorithm.compute("cc").get should equal ("c3") // d - Algorithm.compute("d").get should equal ("d6") - Algorithm.compute("dd").get should equal ("d6") + RefinedSoundexAlgorithm.compute("d").get should equal ("d6") + RefinedSoundexAlgorithm.compute("dd").get should equal ("d6") // e - Algorithm.compute("e").get should equal ("e0") - Algorithm.compute("ee").get should equal ("e0") + RefinedSoundexAlgorithm.compute("e").get should equal ("e0") + RefinedSoundexAlgorithm.compute("ee").get should equal ("e0") // f - Algorithm.compute("f").get should equal ("f2") - Algorithm.compute("ff").get should equal ("f2") + RefinedSoundexAlgorithm.compute("f").get should equal ("f2") + RefinedSoundexAlgorithm.compute("ff").get should equal ("f2") // g - Algorithm.compute("g").get should equal ("g4") - Algorithm.compute("gg").get should equal ("g4") + RefinedSoundexAlgorithm.compute("g").get should equal ("g4") + RefinedSoundexAlgorithm.compute("gg").get should equal ("g4") // h - Algorithm.compute("h").get should equal ("h0") - Algorithm.compute("hh").get should equal ("h0") + RefinedSoundexAlgorithm.compute("h").get should equal ("h0") + RefinedSoundexAlgorithm.compute("hh").get should equal ("h0") // i - Algorithm.compute("i").get should equal ("i0") - Algorithm.compute("ii").get should equal ("i0") + RefinedSoundexAlgorithm.compute("i").get should equal ("i0") + RefinedSoundexAlgorithm.compute("ii").get should equal ("i0") // j - Algorithm.compute("j").get should equal ("j4") - Algorithm.compute("jj").get should equal ("j4") + RefinedSoundexAlgorithm.compute("j").get should equal ("j4") + RefinedSoundexAlgorithm.compute("jj").get should equal ("j4") // k - Algorithm.compute("k").get should equal ("k3") - Algorithm.compute("kk").get should equal ("k3") + RefinedSoundexAlgorithm.compute("k").get should equal ("k3") + RefinedSoundexAlgorithm.compute("kk").get should equal ("k3") // l - Algorithm.compute("l").get should equal ("l7") - Algorithm.compute("ll").get should equal ("l7") + RefinedSoundexAlgorithm.compute("l").get should equal ("l7") + RefinedSoundexAlgorithm.compute("ll").get should equal ("l7") // m - Algorithm.compute("m").get should equal ("m8") - Algorithm.compute("mm").get should equal ("m8") + RefinedSoundexAlgorithm.compute("m").get should equal ("m8") + RefinedSoundexAlgorithm.compute("mm").get should equal ("m8") // n - Algorithm.compute("n").get should equal ("n8") - Algorithm.compute("nn").get should equal ("n8") + RefinedSoundexAlgorithm.compute("n").get should equal ("n8") + RefinedSoundexAlgorithm.compute("nn").get should equal ("n8") // o - Algorithm.compute("o").get should equal ("o0") - Algorithm.compute("oo").get should equal ("o0") + RefinedSoundexAlgorithm.compute("o").get should equal ("o0") + RefinedSoundexAlgorithm.compute("oo").get should equal ("o0") // p - Algorithm.compute("p").get should equal ("p1") - Algorithm.compute("pp").get should equal ("p1") + RefinedSoundexAlgorithm.compute("p").get should equal ("p1") + RefinedSoundexAlgorithm.compute("pp").get should equal ("p1") // q - Algorithm.compute("q").get should equal ("q5") - Algorithm.compute("qq").get should equal ("q5") + RefinedSoundexAlgorithm.compute("q").get should equal ("q5") + RefinedSoundexAlgorithm.compute("qq").get should equal ("q5") // r - Algorithm.compute("r").get should equal ("r9") - Algorithm.compute("rr").get should equal ("r9") + RefinedSoundexAlgorithm.compute("r").get should equal ("r9") + RefinedSoundexAlgorithm.compute("rr").get should equal ("r9") // s - Algorithm.compute("s").get should equal ("s3") - Algorithm.compute("ss").get should equal ("s3") + RefinedSoundexAlgorithm.compute("s").get should equal ("s3") + RefinedSoundexAlgorithm.compute("ss").get should equal ("s3") // t - Algorithm.compute("t").get should equal ("t6") - Algorithm.compute("tt").get should equal ("t6") + RefinedSoundexAlgorithm.compute("t").get should equal ("t6") + RefinedSoundexAlgorithm.compute("tt").get should equal ("t6") // u - Algorithm.compute("u").get should equal ("u0") - Algorithm.compute("uu").get should equal ("u0") + RefinedSoundexAlgorithm.compute("u").get should equal ("u0") + RefinedSoundexAlgorithm.compute("uu").get should equal ("u0") // v - Algorithm.compute("v").get should equal ("v2") - Algorithm.compute("vv").get should equal ("v2") + RefinedSoundexAlgorithm.compute("v").get should equal ("v2") + RefinedSoundexAlgorithm.compute("vv").get should equal ("v2") // w - Algorithm.compute("w").get should equal ("w0") - Algorithm.compute("ww").get should equal ("w0") + RefinedSoundexAlgorithm.compute("w").get should equal ("w0") + RefinedSoundexAlgorithm.compute("ww").get should equal ("w0") // x - Algorithm.compute("x").get should equal ("x5") - Algorithm.compute("xx").get should equal ("x5") + RefinedSoundexAlgorithm.compute("x").get should equal ("x5") + RefinedSoundexAlgorithm.compute("xx").get should equal ("x5") // y - Algorithm.compute("y").get should equal ("y0") - Algorithm.compute("yy").get should equal ("y0") + RefinedSoundexAlgorithm.compute("y").get should equal ("y0") + RefinedSoundexAlgorithm.compute("yy").get should equal ("y0") // z - Algorithm.compute("z").get should equal ("z5") - Algorithm.compute("zz").get should equal ("z5") + RefinedSoundexAlgorithm.compute("z").get should equal ("z5") + RefinedSoundexAlgorithm.compute("zz").get should equal ("z5") // Starting with letter then numbers. - Algorithm.compute("x123456").get should equal ("x5") - Algorithm.compute("a123456").get should equal ("a0") - Algorithm.compute("f123456").get should equal ("f2") + RefinedSoundexAlgorithm.compute("x123456").get should equal ("x5") + RefinedSoundexAlgorithm.compute("a123456").get should equal ("a0") + RefinedSoundexAlgorithm.compute("f123456").get should equal ("f2") // Miscellaneous. - Algorithm.compute("braz").get should equal ("b1905") - Algorithm.compute("broz").get should equal ("b1905") - Algorithm.compute("caren").get should equal ("c30908") - Algorithm.compute("carren").get should equal ("c30908") - Algorithm.compute("coram").get should equal ("c30908") - Algorithm.compute("corran").get should equal ("c30908") - Algorithm.compute("curreen").get should equal ("c30908") - Algorithm.compute("curwen").get should equal ("c30908") - Algorithm.compute("hairs").get should equal ("h093") - Algorithm.compute("hark").get should equal ("h093") - Algorithm.compute("hars").get should equal ("h093") - Algorithm.compute("hayers").get should equal ("h093") - Algorithm.compute("heers").get should equal ("h093") - Algorithm.compute("hiers").get should equal ("h093") - Algorithm.compute("lambard").get should equal ("l7081096") - Algorithm.compute("lambart").get should equal ("l7081096") - Algorithm.compute("lambert").get should equal ("l7081096") - Algorithm.compute("lambird").get should equal ("l7081096") - Algorithm.compute("lampaert").get should equal ("l7081096") - Algorithm.compute("lampart").get should equal ("l7081096") - Algorithm.compute("lamport").get should equal ("l7081096") - Algorithm.compute("limbert").get should equal ("l7081096") - Algorithm.compute("lombard").get should equal ("l7081096") - Algorithm.compute("nolton").get should equal ("n807608") - Algorithm.compute("noulton").get should equal ("n807608") + RefinedSoundexAlgorithm.compute("braz").get should equal ("b1905") + RefinedSoundexAlgorithm.compute("broz").get should equal ("b1905") + RefinedSoundexAlgorithm.compute("caren").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("carren").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("coram").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("corran").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("curreen").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("curwen").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("hairs").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hark").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hars").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hayers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("heers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hiers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("lambard").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambart").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambird").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lampaert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lampart").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lamport").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("limbert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lombard").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("nolton").get should equal ("n807608") + RefinedSoundexAlgorithm.compute("noulton").get should equal ("n807608") } } } } - "RefinedSoundexAlgorithm companion object" should provide { - "pass-through compute method" should returns { - "same value as class" in { - RefinedSoundexAlgorithm.compute("braz").get should equal ("b1905") - } - } - } -} - -object RefinedSoundexAlgorithmSpec { - final private val Algorithm = RefinedSoundexAlgorithm() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala index cb6a222..57964a5 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala @@ -6,45 +6,32 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class RefinedSoundexMetricSpec extends ScalaTest { - import RefinedSoundexMetricSpec.Metric - "RefinedSoundexMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + RefinedSoundexMetric.compare("", "").isDefined should be (false) + RefinedSoundexMetric.compare("abc", "").isDefined should be (false) + RefinedSoundexMetric.compare("", "xyz").isDefined should be (false) } } "non-phonetic arguments" should returns { "None" in { - Metric.compare("123", "123").isDefined should be (false) - Metric.compare("123", "").isDefined should be (false) - Metric.compare("", "123").isDefined should be (false) + RefinedSoundexMetric.compare("123", "123").isDefined should be (false) + RefinedSoundexMetric.compare("123", "").isDefined should be (false) + RefinedSoundexMetric.compare("", "123").isDefined should be (false) } } "phonetically similar arguments" should returns { "Boolean indicating true" in { - Metric.compare("robert", "rupert").get should be (true) + RefinedSoundexMetric.compare("robert", "rupert").get should be (true) } } "phonetically dissimilar arguments" should returns { "Boolean indicating false" in { - Metric.compare("robert", "rubin").get should be (false) + RefinedSoundexMetric.compare("robert", "rubin").get should be (false) } } } } - "RefinedSoundexMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - RefinedSoundexMetric.compare("robert", "rubin").get should be (false) - } - } - } -} - -object RefinedSoundexMetricSpec { - final private val Metric = RefinedSoundexMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala index 5b7deaa..cfe6ac6 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala @@ -6,169 +6,156 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class SoundexAlgorithmSpec extends ScalaTest { - import SoundexAlgorithmSpec.Algorithm - "SoundexAlgorithm" should provide { "compute method" when passed { "empty argument" should returns { "None" in { - Algorithm.compute("").isDefined should be (false) + SoundexAlgorithm.compute("").isDefined should be (false) } } "non-phonetic argument" should returns { "None" in { - Algorithm.compute("123").isDefined should be (false) + SoundexAlgorithm.compute("123").isDefined should be (false) } } "phonetic argument" should returns { "Some" in { // a - Algorithm.compute("a").get should equal ("a000") - Algorithm.compute("aa").get should equal ("a000") + SoundexAlgorithm.compute("a").get should equal ("a000") + SoundexAlgorithm.compute("aa").get should equal ("a000") // b - Algorithm.compute("b").get should equal ("b000") - Algorithm.compute("bb").get should equal ("b000") + SoundexAlgorithm.compute("b").get should equal ("b000") + SoundexAlgorithm.compute("bb").get should equal ("b000") // c - Algorithm.compute("c").get should equal ("c000") - Algorithm.compute("cc").get should equal ("c000") + SoundexAlgorithm.compute("c").get should equal ("c000") + SoundexAlgorithm.compute("cc").get should equal ("c000") // d - Algorithm.compute("d").get should equal ("d000") - Algorithm.compute("dd").get should equal ("d000") + SoundexAlgorithm.compute("d").get should equal ("d000") + SoundexAlgorithm.compute("dd").get should equal ("d000") // e - Algorithm.compute("e").get should equal ("e000") - Algorithm.compute("ee").get should equal ("e000") + SoundexAlgorithm.compute("e").get should equal ("e000") + SoundexAlgorithm.compute("ee").get should equal ("e000") // f - Algorithm.compute("f").get should equal ("f000") - Algorithm.compute("ff").get should equal ("f000") + SoundexAlgorithm.compute("f").get should equal ("f000") + SoundexAlgorithm.compute("ff").get should equal ("f000") // g - Algorithm.compute("g").get should equal ("g000") - Algorithm.compute("gg").get should equal ("g000") + SoundexAlgorithm.compute("g").get should equal ("g000") + SoundexAlgorithm.compute("gg").get should equal ("g000") // h - Algorithm.compute("h").get should equal ("h000") - Algorithm.compute("hh").get should equal ("h000") + SoundexAlgorithm.compute("h").get should equal ("h000") + SoundexAlgorithm.compute("hh").get should equal ("h000") // i - Algorithm.compute("i").get should equal ("i000") - Algorithm.compute("ii").get should equal ("i000") + SoundexAlgorithm.compute("i").get should equal ("i000") + SoundexAlgorithm.compute("ii").get should equal ("i000") // j - Algorithm.compute("j").get should equal ("j000") - Algorithm.compute("jj").get should equal ("j000") + SoundexAlgorithm.compute("j").get should equal ("j000") + SoundexAlgorithm.compute("jj").get should equal ("j000") // k - Algorithm.compute("k").get should equal ("k000") - Algorithm.compute("kk").get should equal ("k000") + SoundexAlgorithm.compute("k").get should equal ("k000") + SoundexAlgorithm.compute("kk").get should equal ("k000") // l - Algorithm.compute("l").get should equal ("l000") - Algorithm.compute("ll").get should equal ("l000") + SoundexAlgorithm.compute("l").get should equal ("l000") + SoundexAlgorithm.compute("ll").get should equal ("l000") // m - Algorithm.compute("m").get should equal ("m000") - Algorithm.compute("mm").get should equal ("m000") + SoundexAlgorithm.compute("m").get should equal ("m000") + SoundexAlgorithm.compute("mm").get should equal ("m000") // n - Algorithm.compute("n").get should equal ("n000") - Algorithm.compute("nn").get should equal ("n000") + SoundexAlgorithm.compute("n").get should equal ("n000") + SoundexAlgorithm.compute("nn").get should equal ("n000") // o - Algorithm.compute("o").get should equal ("o000") - Algorithm.compute("oo").get should equal ("o000") + SoundexAlgorithm.compute("o").get should equal ("o000") + SoundexAlgorithm.compute("oo").get should equal ("o000") // p - Algorithm.compute("p").get should equal ("p000") - Algorithm.compute("pp").get should equal ("p000") + SoundexAlgorithm.compute("p").get should equal ("p000") + SoundexAlgorithm.compute("pp").get should equal ("p000") // q - Algorithm.compute("q").get should equal ("q000") - Algorithm.compute("qq").get should equal ("q000") + SoundexAlgorithm.compute("q").get should equal ("q000") + SoundexAlgorithm.compute("qq").get should equal ("q000") // r - Algorithm.compute("r").get should equal ("r000") - Algorithm.compute("rr").get should equal ("r000") + SoundexAlgorithm.compute("r").get should equal ("r000") + SoundexAlgorithm.compute("rr").get should equal ("r000") // s - Algorithm.compute("s").get should equal ("s000") - Algorithm.compute("ss").get should equal ("s000") + SoundexAlgorithm.compute("s").get should equal ("s000") + SoundexAlgorithm.compute("ss").get should equal ("s000") // t - Algorithm.compute("t").get should equal ("t000") - Algorithm.compute("tt").get should equal ("t000") + SoundexAlgorithm.compute("t").get should equal ("t000") + SoundexAlgorithm.compute("tt").get should equal ("t000") // u - Algorithm.compute("u").get should equal ("u000") - Algorithm.compute("uu").get should equal ("u000") + SoundexAlgorithm.compute("u").get should equal ("u000") + SoundexAlgorithm.compute("uu").get should equal ("u000") // v - Algorithm.compute("v").get should equal ("v000") - Algorithm.compute("vv").get should equal ("v000") + SoundexAlgorithm.compute("v").get should equal ("v000") + SoundexAlgorithm.compute("vv").get should equal ("v000") // w - Algorithm.compute("w").get should equal ("w000") - Algorithm.compute("ww").get should equal ("w000") + SoundexAlgorithm.compute("w").get should equal ("w000") + SoundexAlgorithm.compute("ww").get should equal ("w000") // x - Algorithm.compute("x").get should equal ("x000") - Algorithm.compute("xx").get should equal ("x000") + SoundexAlgorithm.compute("x").get should equal ("x000") + SoundexAlgorithm.compute("xx").get should equal ("x000") // y - Algorithm.compute("y").get should equal ("y000") - Algorithm.compute("yy").get should equal ("y000") + SoundexAlgorithm.compute("y").get should equal ("y000") + SoundexAlgorithm.compute("yy").get should equal ("y000") // z - Algorithm.compute("z").get should equal ("z000") - Algorithm.compute("zz").get should equal ("z000") + SoundexAlgorithm.compute("z").get should equal ("z000") + SoundexAlgorithm.compute("zz").get should equal ("z000") // Starting with letter then numbers. - Algorithm.compute("x123456").get should equal ("x000") - Algorithm.compute("a123456").get should equal ("a000") - Algorithm.compute("f123456").get should equal ("f000") + SoundexAlgorithm.compute("x123456").get should equal ("x000") + SoundexAlgorithm.compute("a123456").get should equal ("a000") + SoundexAlgorithm.compute("f123456").get should equal ("f000") // Miscellaneous. - Algorithm.compute("abc").get should equal ("a120") - Algorithm.compute("xyz").get should equal ("x200") - Algorithm.compute("robert").get should equal ("r163") - Algorithm.compute("rupert").get should equal ("r163") - Algorithm.compute("rubin").get should equal ("r150") - Algorithm.compute("ashcraft").get should equal ("a261") - Algorithm.compute("tymczak").get should equal ("t522") - Algorithm.compute("pfister").get should equal ("p236") - Algorithm.compute("euler").get should equal ("e460") - Algorithm.compute("gauss").get should equal ("g200") - Algorithm.compute("hilbert").get should equal ("h416") - Algorithm.compute("knuth").get should equal ("k530") - Algorithm.compute("lloyd").get should equal ("l300") - Algorithm.compute("lukasiewicz").get should equal ("l222") - Algorithm.compute("ashcroft").get should equal ("a261") - Algorithm.compute("tymczak").get should equal ("t522") - Algorithm.compute("pfister").get should equal ("p236") - Algorithm.compute("ellery").get should equal ("e460") - Algorithm.compute("ghosh").get should equal ("g200") - Algorithm.compute("heilbronn").get should equal ("h416") - Algorithm.compute("kant").get should equal ("k530") - Algorithm.compute("ladd").get should equal ("l300") - Algorithm.compute("lissajous").get should equal ("l222") - Algorithm.compute("fusedale").get should equal ("f234") + SoundexAlgorithm.compute("abc").get should equal ("a120") + SoundexAlgorithm.compute("xyz").get should equal ("x200") + SoundexAlgorithm.compute("robert").get should equal ("r163") + SoundexAlgorithm.compute("rupert").get should equal ("r163") + SoundexAlgorithm.compute("rubin").get should equal ("r150") + SoundexAlgorithm.compute("ashcraft").get should equal ("a261") + SoundexAlgorithm.compute("tymczak").get should equal ("t522") + SoundexAlgorithm.compute("pfister").get should equal ("p236") + SoundexAlgorithm.compute("euler").get should equal ("e460") + SoundexAlgorithm.compute("gauss").get should equal ("g200") + SoundexAlgorithm.compute("hilbert").get should equal ("h416") + SoundexAlgorithm.compute("knuth").get should equal ("k530") + SoundexAlgorithm.compute("lloyd").get should equal ("l300") + SoundexAlgorithm.compute("lukasiewicz").get should equal ("l222") + SoundexAlgorithm.compute("ashcroft").get should equal ("a261") + SoundexAlgorithm.compute("tymczak").get should equal ("t522") + SoundexAlgorithm.compute("pfister").get should equal ("p236") + SoundexAlgorithm.compute("ellery").get should equal ("e460") + SoundexAlgorithm.compute("ghosh").get should equal ("g200") + SoundexAlgorithm.compute("heilbronn").get should equal ("h416") + SoundexAlgorithm.compute("kant").get should equal ("k530") + SoundexAlgorithm.compute("ladd").get should equal ("l300") + SoundexAlgorithm.compute("lissajous").get should equal ("l222") + SoundexAlgorithm.compute("fusedale").get should equal ("f234") } } } } - "SoundexAlgorithm companion object" should provide { - "pass-through compute method" should returns { - "same value as class" in { - SoundexAlgorithm.compute("abc").get should equal ("a120") - } - } - } -} - -object SoundexAlgorithmSpec { - final private val Algorithm = SoundexAlgorithm() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala index 9fc47d8..6d4873a 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala @@ -6,45 +6,32 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class SoundexMetricSpec extends ScalaTest { - import SoundexMetricSpec.Metric - "SoundexMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + SoundexMetric.compare("", "").isDefined should be (false) + SoundexMetric.compare("abc", "").isDefined should be (false) + SoundexMetric.compare("", "xyz").isDefined should be (false) } } "non-phonetic arguments" should returns { "None" in { - Metric.compare("123", "123").isDefined should be (false) - Metric.compare("123", "").isDefined should be (false) - Metric.compare("", "123").isDefined should be (false) + SoundexMetric.compare("123", "123").isDefined should be (false) + SoundexMetric.compare("123", "").isDefined should be (false) + SoundexMetric.compare("", "123").isDefined should be (false) } } "phonetically similar arguments" should returns { "Boolean indicating true" in { - Metric.compare("robert", "rupert").get should be (true) + SoundexMetric.compare("robert", "rupert").get should be (true) } } "phonetically dissimilar arguments" should returns { "Boolean indicating false" in { - Metric.compare("robert", "rubin").get should be (false) + SoundexMetric.compare("robert", "rubin").get should be (false) } } } } - "SoundexMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - SoundexMetric.compare("robert", "rubin").get should be (false) - } - } - } -} - -object SoundexMetricSpec { - final private val Metric = SoundexMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala index 5ddfc06..6611e27 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala @@ -6,70 +6,57 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class DiceSorensenMetricSpec extends ScalaTest { - import DiceSorensenMetricSpec.Metric - "DiceSorensenMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "")(1).isDefined should be (false) - Metric.compare("abc", "")(1).isDefined should be (false) - Metric.compare("", "xyz")(1).isDefined should be (false) + DiceSorensenMetric(1).compare("", "").isDefined should be (false) + DiceSorensenMetric(1).compare("abc", "").isDefined should be (false) + DiceSorensenMetric(1).compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("abc", "abc")(1).get should be (1) - Metric.compare("abc", "abc")(2).get should be (1) - Metric.compare("abc", "abc")(3).get should be (1) + DiceSorensenMetric(1).compare("abc", "abc").get should be (1) + DiceSorensenMetric(2).compare("abc", "abc").get should be (1) + DiceSorensenMetric(2).compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz")(1).get should be (0) - Metric.compare("abc", "xyz")(2).get should be (0) - Metric.compare("abc", "xyz")(3).get should be (0) + DiceSorensenMetric(1).compare("abc", "xyz").get should be (0) + DiceSorensenMetric(2).compare("abc", "xyz").get should be (0) + DiceSorensenMetric(3).compare("abc", "xyz").get should be (0) } } "invalid arguments" should returns { "None" in { - Metric.compare("n", "naght")(2).isDefined should be (false) - Metric.compare("night", "n")(2).isDefined should be (false) - Metric.compare("ni", "naght")(3).isDefined should be (false) - Metric.compare("night", "na")(3).isDefined should be (false) + DiceSorensenMetric(2).compare("n", "naght").isDefined should be (false) + DiceSorensenMetric(2).compare("night", "n").isDefined should be (false) + DiceSorensenMetric(3).compare("ni", "naght").isDefined should be (false) + DiceSorensenMetric(3).compare("night", "na").isDefined should be (false) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("night", "nacht")(1).get should be (0.6) - Metric.compare("night", "naght")(1).get should be (0.8) - Metric.compare("context", "contact")(1).get should be (0.7142857142857143) + DiceSorensenMetric(1).compare("night", "nacht").get should be (0.6) + DiceSorensenMetric(1).compare("night", "naght").get should be (0.8) + DiceSorensenMetric(1).compare("context", "contact").get should be (0.7142857142857143) - Metric.compare("night", "nacht")(2).get should be (0.25) - Metric.compare("night", "naght")(2).get should be (0.5) - Metric.compare("context", "contact")(2).get should be (0.5) - Metric.compare("contextcontext", "contact")(2).get should be (0.3157894736842105) - Metric.compare("context", "contactcontact")(2).get should be (0.3157894736842105) - Metric.compare("ht", "nacht")(2).get should be (0.4) - Metric.compare("xp", "nacht")(2).get should be (0) - Metric.compare("ht", "hththt")(2).get should be (0.3333333333333333) + DiceSorensenMetric(2).compare("night", "nacht").get should be (0.25) + DiceSorensenMetric(2).compare("night", "naght").get should be (0.5) + DiceSorensenMetric(2).compare("context", "contact").get should be (0.5) + DiceSorensenMetric(2).compare("contextcontext", "contact").get should be (0.3157894736842105) + DiceSorensenMetric(2).compare("context", "contactcontact").get should be (0.3157894736842105) + DiceSorensenMetric(2).compare("ht", "nacht").get should be (0.4) + DiceSorensenMetric(2).compare("xp", "nacht").get should be (0) + DiceSorensenMetric(2).compare("ht", "hththt").get should be (0.3333333333333333) - Metric.compare("night", "nacht")(3).get should be (0) - Metric.compare("night", "naght")(3).get should be (0.3333333333333333) - Metric.compare("context", "contact")(3).get should be (0.4) + DiceSorensenMetric(3).compare("night", "nacht").get should be (0) + DiceSorensenMetric(3).compare("night", "naght").get should be (0.3333333333333333) + DiceSorensenMetric(3).compare("context", "contact").get should be (0.4) } } } } - "DiceSorensenMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - DiceSorensenMetric.compare("context", "contact")(3).get should be (0.4) - } - } - } -} - -object DiceSorensenMetricSpec { - private final val Metric = DiceSorensenMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala index c69d860..c26996a 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala @@ -6,47 +6,34 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class HammingMetricSpec extends ScalaTest { - import HammingMetricSpec.Metric - "HammingMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + HammingMetric.compare("", "").isDefined should be (false) + HammingMetric.compare("abc", "").isDefined should be (false) + HammingMetric.compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "0" in { - Metric.compare("abc", "abc").get should be (0) - Metric.compare("123", "123").get should be (0) + HammingMetric.compare("abc", "abc").get should be (0) + HammingMetric.compare("123", "123").get should be (0) } } "unequal arguments" should returns { "Int indicating distance" in { - Metric.compare("abc", "xyz").get should be (3) - Metric.compare("123", "456").get should be (3) + HammingMetric.compare("abc", "xyz").get should be (3) + HammingMetric.compare("123", "456").get should be (3) } } "valid arguments" should returns { "Int indicating distance" in { - Metric.compare("toned", "roses").get should be (3) - Metric.compare("1011101", "1001001").get should be (2) - Metric.compare("2173896", "2233796").get should be (3) + HammingMetric.compare("toned", "roses").get should be (3) + HammingMetric.compare("1011101", "1001001").get should be (2) + HammingMetric.compare("2173896", "2233796").get should be (3) } } } } - "HammingMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - HammingMetric.compare("2173896", "2233796").get should be (3) - } - } - } -} - -object HammingMetricSpec { - private final val Metric = HammingMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaccardMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaccardMetricSpec.scala index 17bc3ef..06b8928 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaccardMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaccardMetricSpec.scala @@ -6,72 +6,57 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class JaccardMetricSpec extends ScalaTest { - import JaccardMetricSpec.Metric - "JaccardMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "")(1).isDefined should be (false) - Metric.compare("abc", "")(1).isDefined should be (false) - Metric.compare("", "xyz")(1).isDefined should be (false) + JaccardMetric(1).compare("", "").isDefined should be (false) + JaccardMetric(1).compare("abc", "").isDefined should be (false) + JaccardMetric(1).compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("abc", "abc")(1).get should be (1) - Metric.compare("abc", "abc")(2).get should be (1) - Metric.compare("abc", "abc")(3).get should be (1) + JaccardMetric(1).compare("abc", "abc").get should be (1) + JaccardMetric(2).compare("abc", "abc").get should be (1) + JaccardMetric(3).compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz")(1).get should be (0) - Metric.compare("abc", "xyz")(2).get should be (0) - Metric.compare("abc", "xyz")(3).get should be (0) + JaccardMetric(1).compare("abc", "xyz").get should be (0) + JaccardMetric(2).compare("abc", "xyz").get should be (0) + JaccardMetric(3).compare("abc", "xyz").get should be (0) } } "invalid arguments" should returns { "None" in { - Metric.compare("n", "naght")(2).isDefined should be (false) - Metric.compare("night", "n")(2).isDefined should be (false) - Metric.compare("ni", "naght")(3).isDefined should be (false) - Metric.compare("night", "na")(3).isDefined should be (false) + JaccardMetric(2).compare("n", "naght").isDefined should be (false) + JaccardMetric(2).compare("night", "n").isDefined should be (false) + JaccardMetric(3).compare("ni", "naght").isDefined should be (false) + JaccardMetric(3).compare("night", "na").isDefined should be (false) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("night", "nacht")(1).get should be (0.42857142857142855) - Metric.compare("night", "naght")(1).get should be (0.6666666666666666) - Metric.compare("context", "contact")(1).get should be (0.5555555555555556) - - Metric.compare("night", "nacht")(2).get should be (0.14285714285714285) - Metric.compare("night", "naght")(2).get should be (0.3333333333333333) - Metric.compare("context", "contact")(2).get should be (0.3333333333333333) - Metric.compare("contextcontext", "contact")(2).get should be (0.1875) - Metric.compare("context", "contactcontact")(2).get should be (0.1875) - Metric.compare("ht", "nacht")(2).get should be (0.25) - Metric.compare("xp", "nacht")(2).get should be (0) - Metric.compare("ht", "hththt")(2).get should be (0.2) - - Metric.compare("night", "nacht")(3).get should be (0) - Metric.compare("night", "naght")(3).get should be (0.2) - Metric.compare("context", "contact")(3).get should be (0.25) + JaccardMetric(1).compare("night", "nacht").get should be (0.42857142857142855) + JaccardMetric(1).compare("night", "naght").get should be (0.6666666666666666) + JaccardMetric(1).compare("context", "contact").get should be (0.5555555555555556) + + JaccardMetric(2).compare("night", "nacht").get should be (0.14285714285714285) + JaccardMetric(2).compare("night", "naght").get should be (0.3333333333333333) + JaccardMetric(2).compare("context", "contact").get should be (0.3333333333333333) + JaccardMetric(2).compare("contextcontext", "contact").get should be (0.1875) + JaccardMetric(2).compare("context", "contactcontact").get should be (0.1875) + JaccardMetric(2).compare("ht", "nacht").get should be (0.25) + JaccardMetric(2).compare("xp", "nacht").get should be (0) + JaccardMetric(2).compare("ht", "hththt").get should be (0.2) + + JaccardMetric(3).compare("night", "nacht").get should be (0) + JaccardMetric(3).compare("night", "naght").get should be (0.2) + JaccardMetric(3).compare("context", "contact").get should be (0.25) } } } } - "JaccardMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - JaccardMetric.compare("context", "contact")(3).get should be (0.25) - } - } - } -} - -object JaccardMetricSpec { - private final val Metric = JaccardMetric() } - - diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala index 00f4daf..d5037c5 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala @@ -6,61 +6,48 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class JaroMetricSpec extends ScalaTest { - import JaroMetricSpec.Metric - "JaroMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + JaroMetric.compare("", "").isDefined should be (false) + JaroMetric.compare("abc", "").isDefined should be (false) + JaroMetric.compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("a", "a").get should be (1) - Metric.compare("abc", "abc").get should be (1) - Metric.compare("123", "123").get should be (1) + JaroMetric.compare("a", "a").get should be (1) + JaroMetric.compare("abc", "abc").get should be (1) + JaroMetric.compare("123", "123").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz").get should be (0) - Metric.compare("123", "456").get should be (0) + JaroMetric.compare("abc", "xyz").get should be (0) + JaroMetric.compare("123", "456").get should be (0) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("aa", "a").get should be (0.8333333333333334) - Metric.compare("a", "aa").get should be (0.8333333333333334) - Metric.compare("veryveryverylong", "v").get should be (0.6875) - Metric.compare("v", "veryveryverylong").get should be (0.6875) - Metric.compare("martha", "marhta").get should be (0.9444444444444445) - Metric.compare("dwayne", "duane").get should be (0.8222222222222223) - Metric.compare("dixon", "dicksonx").get should be (0.7666666666666666) - Metric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) - Metric.compare("jones", "johnson").get should be (0.7904761904761904) - Metric.compare("henka", "henkan").get should be (0.9444444444444445) - Metric.compare("fvie", "ten").get should be (0) + JaroMetric.compare("aa", "a").get should be (0.8333333333333334) + JaroMetric.compare("a", "aa").get should be (0.8333333333333334) + JaroMetric.compare("veryveryverylong", "v").get should be (0.6875) + JaroMetric.compare("v", "veryveryverylong").get should be (0.6875) + JaroMetric.compare("martha", "marhta").get should be (0.9444444444444445) + JaroMetric.compare("dwayne", "duane").get should be (0.8222222222222223) + JaroMetric.compare("dixon", "dicksonx").get should be (0.7666666666666666) + JaroMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroMetric.compare("jones", "johnson").get should be (0.7904761904761904) + JaroMetric.compare("henka", "henkan").get should be (0.9444444444444445) + JaroMetric.compare("fvie", "ten").get should be (0) - Metric.compare("zac ephron", "zac efron").get should be > - Metric.compare("zac ephron", "kai ephron").get - Metric.compare("brittney spears", "britney spears").get should be > - Metric.compare("brittney spears", "brittney startzman").get + JaroMetric.compare("zac ephron", "zac efron").get should be > + JaroMetric.compare("zac ephron", "kai ephron").get + JaroMetric.compare("brittney spears", "britney spears").get should be > + JaroMetric.compare("brittney spears", "brittney startzman").get } } } } - "JaroMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - JaroMetric.compare("fvie", "ten").get should be (0) - } - } - } -} - -object JaroMetricSpec { - private final val Metric = JaroMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala index 06421a8..14f7cbb 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala @@ -6,61 +6,48 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class JaroWinklerMetricSpec extends ScalaTest { - import JaroWinklerMetricSpec.Metric - "JaroWinklerMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + JaroWinklerMetric.compare("", "").isDefined should be (false) + JaroWinklerMetric.compare("abc", "").isDefined should be (false) + JaroWinklerMetric.compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("a", "a").get should be (1) - Metric.compare("abc", "abc").get should be (1) - Metric.compare("123", "123").get should be (1) + JaroWinklerMetric.compare("a", "a").get should be (1) + JaroWinklerMetric.compare("abc", "abc").get should be (1) + JaroWinklerMetric.compare("123", "123").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz").get should be (0) - Metric.compare("123", "456").get should be (0) + JaroWinklerMetric.compare("abc", "xyz").get should be (0) + JaroWinklerMetric.compare("123", "456").get should be (0) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("aa", "a").get should be (0.8500000000000001) - Metric.compare("a", "aa").get should be (0.8500000000000001) - Metric.compare("veryveryverylong", "v").get should be (0.71875) - Metric.compare("v", "veryveryverylong").get should be (0.71875) - Metric.compare("martha", "marhta").get should be (0.9611111111111111) - Metric.compare("dwayne", "duane").get should be (0.8400000000000001) - Metric.compare("dixon", "dicksonx").get should be (0.8133333333333332) - Metric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) - Metric.compare("jones", "johnson").get should be (0.8323809523809523) - Metric.compare("henka", "henkan").get should be (0.9666666666666667) - Metric.compare("fvie", "ten").get should be (0) + JaroWinklerMetric.compare("aa", "a").get should be (0.8500000000000001) + JaroWinklerMetric.compare("a", "aa").get should be (0.8500000000000001) + JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875) + JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875) + JaroWinklerMetric.compare("martha", "marhta").get should be (0.9611111111111111) + JaroWinklerMetric.compare("dwayne", "duane").get should be (0.8400000000000001) + JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.8133333333333332) + JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809523809523) + JaroWinklerMetric.compare("henka", "henkan").get should be (0.9666666666666667) + JaroWinklerMetric.compare("fvie", "ten").get should be (0) - Metric.compare("zac ephron", "zac efron").get should be > - Metric.compare("zac ephron", "kai ephron").get - Metric.compare("brittney spears", "britney spears").get should be > - Metric.compare("brittney spears", "brittney startzman").get + JaroWinklerMetric.compare("zac ephron", "zac efron").get should be > + JaroWinklerMetric.compare("zac ephron", "kai ephron").get + JaroWinklerMetric.compare("brittney spears", "britney spears").get should be > + JaroWinklerMetric.compare("brittney spears", "brittney startzman").get } } } } - "JaroWinklerMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - JaroWinklerMetric.compare("fvie", "ten").get should be (0) - } - } - } -} - -object JaroWinklerMetricSpec { - private final val Metric = JaroWinklerMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala index 51de2ca..8e8bf11 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala @@ -6,60 +6,47 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class LevenshteinMetricSpec extends ScalaTest { - import LevenshteinMetricSpec.Metric - "LevenshteinMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + LevenshteinMetric.compare("", "").isDefined should be (false) + LevenshteinMetric.compare("abc", "").isDefined should be (false) + LevenshteinMetric.compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "0" in { - Metric.compare("abc", "abc").get should be (0) - Metric.compare("123", "123").get should be (0) + LevenshteinMetric.compare("abc", "abc").get should be (0) + LevenshteinMetric.compare("123", "123").get should be (0) } } "unequal arguments" should returns { "Int indicating distance" in { - Metric.compare("abc", "xyz").get should be (3) - Metric.compare("123", "456").get should be (3) + LevenshteinMetric.compare("abc", "xyz").get should be (3) + LevenshteinMetric.compare("123", "456").get should be (3) } } "valid arguments" should returns { "Int indicating distance" in { - Metric.compare("abc", "a").get should be (2) - Metric.compare("a", "abc").get should be (2) - Metric.compare("abc", "c").get should be (2) - Metric.compare("c", "abc").get should be (2) - Metric.compare("sitting", "kitten").get should be (3) - Metric.compare("kitten", "sitting").get should be (3) - Metric.compare("cake", "drake").get should be (2) - Metric.compare("drake", "cake").get should be (2) - Metric.compare("saturday", "sunday").get should be (3) - Metric.compare("sunday", "saturday").get should be (3) - Metric.compare("book", "back").get should be (2) - Metric.compare("dog", "fog").get should be (1) - Metric.compare("foq", "fog").get should be (1) - Metric.compare("fvg", "fog").get should be (1) - Metric.compare("encyclopedia", "encyclopediaz").get should be (1) - Metric.compare("encyclopediz", "encyclopediaz").get should be (1) + LevenshteinMetric.compare("abc", "a").get should be (2) + LevenshteinMetric.compare("a", "abc").get should be (2) + LevenshteinMetric.compare("abc", "c").get should be (2) + LevenshteinMetric.compare("c", "abc").get should be (2) + LevenshteinMetric.compare("sitting", "kitten").get should be (3) + LevenshteinMetric.compare("kitten", "sitting").get should be (3) + LevenshteinMetric.compare("cake", "drake").get should be (2) + LevenshteinMetric.compare("drake", "cake").get should be (2) + LevenshteinMetric.compare("saturday", "sunday").get should be (3) + LevenshteinMetric.compare("sunday", "saturday").get should be (3) + LevenshteinMetric.compare("book", "back").get should be (2) + LevenshteinMetric.compare("dog", "fog").get should be (1) + LevenshteinMetric.compare("foq", "fog").get should be (1) + LevenshteinMetric.compare("fvg", "fog").get should be (1) + LevenshteinMetric.compare("encyclopedia", "encyclopediaz").get should be (1) + LevenshteinMetric.compare("encyclopediz", "encyclopediaz").get should be (1) } } } } - "LevenshteinMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - LevenshteinMetric.compare("fvg", "fog").get should be (1) - } - } - } -} - -object LevenshteinMetricSpec { - private final val Metric = LevenshteinMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala index 39d97e5..6d9749e 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala @@ -6,70 +6,57 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class NGramMetricSpec extends ScalaTest { - import NGramMetricSpec.Metric - "NGramMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "")(1).isDefined should be (false) - Metric.compare("abc", "")(1).isDefined should be (false) - Metric.compare("", "xyz")(1).isDefined should be (false) + NGramMetric(1).compare("", "").isDefined should be (false) + NGramMetric(1).compare("abc", "").isDefined should be (false) + NGramMetric(1).compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("abc", "abc")(1).get should be (1) - Metric.compare("abc", "abc")(2).get should be (1) - Metric.compare("abc", "abc")(3).get should be (1) + NGramMetric(1).compare("abc", "abc").get should be (1) + NGramMetric(2).compare("abc", "abc").get should be (1) + NGramMetric(3).compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz")(1).get should be (0) - Metric.compare("abc", "xyz")(2).get should be (0) - Metric.compare("abc", "xyz")(3).get should be (0) + NGramMetric(1).compare("abc", "xyz").get should be (0) + NGramMetric(2).compare("abc", "xyz").get should be (0) + NGramMetric(3).compare("abc", "xyz").get should be (0) } } "invalid arguments" should returns { "None" in { - Metric.compare("n", "naght")(2).isDefined should be (false) - Metric.compare("night", "n")(2).isDefined should be (false) - Metric.compare("ni", "naght")(3).isDefined should be (false) - Metric.compare("night", "na")(3).isDefined should be (false) + NGramMetric(2).compare("n", "naght").isDefined should be (false) + NGramMetric(2).compare("night", "n").isDefined should be (false) + NGramMetric(3).compare("ni", "naght").isDefined should be (false) + NGramMetric(3).compare("night", "na").isDefined should be (false) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("night", "nacht")(1).get should be (0.6) - Metric.compare("night", "naght")(1).get should be (0.8) - Metric.compare("context", "contact")(1).get should be (0.7142857142857143) + NGramMetric(1).compare("night", "nacht").get should be (0.6) + NGramMetric(1).compare("night", "naght").get should be (0.8) + NGramMetric(1).compare("context", "contact").get should be (0.7142857142857143) - Metric.compare("night", "nacht")(2).get should be (0.25) - Metric.compare("night", "naght")(2).get should be (0.5) - Metric.compare("context", "contact")(2).get should be (0.5) - Metric.compare("contextcontext", "contact")(2).get should be (0.23076923076923078) - Metric.compare("context", "contactcontact")(2).get should be (0.23076923076923078) - Metric.compare("ht", "nacht")(2).get should be (0.25) - Metric.compare("xp", "nacht")(2).get should be (0) - Metric.compare("ht", "hththt")(2).get should be (0.2) + NGramMetric(2).compare("night", "nacht").get should be (0.25) + NGramMetric(2).compare("night", "naght").get should be (0.5) + NGramMetric(2).compare("context", "contact").get should be (0.5) + NGramMetric(2).compare("contextcontext", "contact").get should be (0.23076923076923078) + NGramMetric(2).compare("context", "contactcontact").get should be (0.23076923076923078) + NGramMetric(2).compare("ht", "nacht").get should be (0.25) + NGramMetric(2).compare("xp", "nacht").get should be (0) + NGramMetric(2).compare("ht", "hththt").get should be (0.2) - Metric.compare("night", "nacht")(3).get should be (0) - Metric.compare("night", "naght")(3).get should be (0.3333333333333333) - Metric.compare("context", "contact")(3).get should be (0.4) + NGramMetric(3).compare("night", "nacht").get should be (0) + NGramMetric(3).compare("night", "naght").get should be (0.3333333333333333) + NGramMetric(3).compare("context", "contact").get should be (0.4) } } } } - "NGramMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - NGramMetric.compare("context", "contact")(3).get should be (0.4) - } - } - } -} - -object NGramMetricSpec { - private final val Metric = NGramMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala index 32c9650..20d1b2e 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala @@ -6,72 +6,59 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class OverlapMetricSpec extends ScalaTest { - import OverlapMetricSpec.Metric - "OverlapMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "")(1).isDefined should be (false) - Metric.compare("abc", "")(1).isDefined should be (false) - Metric.compare("", "xyz")(1).isDefined should be (false) + OverlapMetric(1).compare("", "").isDefined should be (false) + OverlapMetric(1).compare("abc", "").isDefined should be (false) + OverlapMetric(1).compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "1" in { - Metric.compare("abc", "abc")(1).get should be (1) - Metric.compare("abc", "abc")(2).get should be (1) - Metric.compare("abc", "abc")(3).get should be (1) + OverlapMetric(1).compare("abc", "abc").get should be (1) + OverlapMetric(2).compare("abc", "abc").get should be (1) + OverlapMetric(3).compare("abc", "abc").get should be (1) } } "unequal arguments" should returns { "0" in { - Metric.compare("abc", "xyz")(1).get should be (0) - Metric.compare("abc", "xyz")(2).get should be (0) - Metric.compare("abc", "xyz")(3).get should be (0) + OverlapMetric(1).compare("abc", "xyz").get should be (0) + OverlapMetric(2).compare("abc", "xyz").get should be (0) + OverlapMetric(3).compare("abc", "xyz").get should be (0) } } "invalid arguments" should returns { "None" in { - Metric.compare("n", "naght")(2).isDefined should be (false) - Metric.compare("night", "n")(2).isDefined should be (false) - Metric.compare("ni", "naght")(3).isDefined should be (false) - Metric.compare("night", "na")(3).isDefined should be (false) + OverlapMetric(2).compare("n", "naght").isDefined should be (false) + OverlapMetric(2).compare("night", "n").isDefined should be (false) + OverlapMetric(3).compare("ni", "naght").isDefined should be (false) + OverlapMetric(3).compare("night", "na").isDefined should be (false) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("bob", "bobman") (1).get should be (1) - Metric.compare("bob", "manbobman") (1).get should be (1) - Metric.compare("night", "nacht")(1).get should be (0.6) - Metric.compare("night", "naght")(1).get should be (0.8) - Metric.compare("context", "contact")(1).get should be (0.7142857142857143) + OverlapMetric(1).compare("bob", "bobman").get should be (1) + OverlapMetric(1).compare("bob", "manbobman").get should be (1) + OverlapMetric(1).compare("night", "nacht").get should be (0.6) + OverlapMetric(1).compare("night", "naght").get should be (0.8) + OverlapMetric(1).compare("context", "contact").get should be (0.7142857142857143) - Metric.compare("night", "nacht")(2).get should be (0.25) - Metric.compare("night", "naght")(2).get should be (0.5) - Metric.compare("context", "contact")(2).get should be (0.5) - Metric.compare("contextcontext", "contact")(2).get should be (0.5) - Metric.compare("context", "contactcontact")(2).get should be (0.5) - Metric.compare("ht", "nacht")(2).get should be (1) - Metric.compare("xp", "nacht")(2).get should be (0) - Metric.compare("ht", "hththt")(2).get should be (1) + OverlapMetric(2).compare("night", "nacht").get should be (0.25) + OverlapMetric(2).compare("night", "naght").get should be (0.5) + OverlapMetric(2).compare("context", "contact").get should be (0.5) + OverlapMetric(2).compare("contextcontext", "contact").get should be (0.5) + OverlapMetric(2).compare("context", "contactcontact").get should be (0.5) + OverlapMetric(2).compare("ht", "nacht").get should be (1) + OverlapMetric(2).compare("xp", "nacht").get should be (0) + OverlapMetric(2).compare("ht", "hththt").get should be (1) - Metric.compare("night", "nacht")(3).get should be (0) - Metric.compare("night", "naght")(3).get should be (0.3333333333333333) - Metric.compare("context", "contact")(3).get should be (0.4) + OverlapMetric(3).compare("night", "nacht").get should be (0) + OverlapMetric(3).compare("night", "naght").get should be (0.3333333333333333) + OverlapMetric(3).compare("context", "contact").get should be (0.4) } } } } - "OverlapMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - OverlapMetric.compare("context", "contact")(3).get should be (0.4) - } - } - } -} - -object OverlapMetricSpec { - private final val Metric = OverlapMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala index 638536f..e1ff9cf 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala @@ -6,51 +6,37 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class RatcliffObershelpMetricSpec extends ScalaTest { - import RatcliffObershelpMetricSpec.Metric - "RatcliffObershelpMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "").isDefined should be (false) - Metric.compare("abc", "").isDefined should be (false) - Metric.compare("", "xyz").isDefined should be (false) + RatcliffObershelpMetric.compare("", "").isDefined should be (false) + RatcliffObershelpMetric.compare("abc", "").isDefined should be (false) + RatcliffObershelpMetric.compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "0" in { - Metric.compare("abc", "abc").get should be (1) - Metric.compare("123", "123").get should be (1) + RatcliffObershelpMetric.compare("abc", "abc").get should be (1) + RatcliffObershelpMetric.compare("123", "123").get should be (1) } } "unequal arguments" should returns { "Double indicating distance" in { - Metric.compare("abc", "xyz").get should be (0) - Metric.compare("123", "456").get should be (0) + RatcliffObershelpMetric.compare("abc", "xyz").get should be (0) + RatcliffObershelpMetric.compare("123", "456").get should be (0) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("aleksander", "alexandre").get should be (0.7368421052631579) - Metric.compare("alexandre", "aleksander").get should be (0.7368421052631579) - Metric.compare("pennsylvania", "pencilvaneya").get should be (0.6666666666666666) - Metric.compare("pencilvaneya", "pennsylvania").get should be (0.6666666666666666) - Metric.compare("abcefglmn", "abefglmo").get should be (0.8235294117647058) - Metric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058) + RatcliffObershelpMetric.compare("aleksander", "alexandre").get should be (0.7368421052631579) + RatcliffObershelpMetric.compare("alexandre", "aleksander").get should be (0.7368421052631579) + RatcliffObershelpMetric.compare("pennsylvania", "pencilvaneya").get should be (0.6666666666666666) + RatcliffObershelpMetric.compare("pencilvaneya", "pennsylvania").get should be (0.6666666666666666) + RatcliffObershelpMetric.compare("abcefglmn", "abefglmo").get should be (0.8235294117647058) + RatcliffObershelpMetric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058) } } } } - "RatcliffObershelpMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - RatcliffObershelpMetric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058) - } - } - } } - -object RatcliffObershelpMetricSpec { - private final val Metric = RatcliffObershelpMetric() -} - diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala index 9c46c89..bcd17ec 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala @@ -6,59 +6,45 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class WeightedLevenshteinMetricSpec extends ScalaTest { - import WeightedLevenshteinMetricSpec.{Metric, Options} - "WeightedLevenshteinMetric" should provide { "compare method" when passed { "empty arguments" should returns { "None" in { - Metric.compare("", "")(Options).isDefined should be (false) - Metric.compare("abc", "")(Options).isDefined should be (false) - Metric.compare("", "xyz")(Options).isDefined should be (false) + WeightedLevenshteinMetric(10, 0.1, 1).compare("", "").isDefined should be (false) + WeightedLevenshteinMetric(10, 0.1, 1).compare("abc", "").isDefined should be (false) + WeightedLevenshteinMetric(10, 0.1, 1).compare("", "xyz").isDefined should be (false) } } "equal arguments" should returns { "0" in { - Metric.compare("abc", "abc")(Options).get should be (0) - Metric.compare("123", "123")(Options).get should be (0) + WeightedLevenshteinMetric(10, 0.1, 1).compare("abc", "abc").get should be (0) + WeightedLevenshteinMetric(10, 0.1, 1).compare("123", "123").get should be (0) } } "unequal arguments" should returns { "Double indicating distance" in { - Metric.compare("abc", "xyz")(Options).get should be (3) - Metric.compare("123", "456")(Options).get should be (3) + WeightedLevenshteinMetric(10, 0.1, 1).compare("abc", "xyz").get should be (3) + WeightedLevenshteinMetric(10, 0.1, 1).compare("123", "456").get should be (3) } } "valid arguments" should returns { "Double indicating distance" in { - Metric.compare("az", "z")(Options).get should be (10) - Metric.compare("z", "az")(Options).get should be (0.1) - Metric.compare("a", "z")(Options).get should be (1) - Metric.compare("z", "a")(Options).get should be (1) - Metric.compare("ab", "yz")(Options).get should be (2) - Metric.compare("yz", "ab")(Options).get should be (2) - Metric.compare("0", "0123456789")(Options).get should be (0.9) - Metric.compare("0123456789", "0")(Options).get should be (90) - Metric.compare("book", "back")(Options).get should be (2) - Metric.compare("back", "book")(Options).get should be (2) - Metric.compare("hosp", "hospital")(Options).get should be (0.4) - Metric.compare("hospital", "hosp")(Options).get should be (40) - Metric.compare("clmbs blvd", "columbus boulevard")(Options).get should be (0.8) - Metric.compare("columbus boulevard", "clmbs blvd")(Options).get should be (80) + WeightedLevenshteinMetric(10, 0.1, 1).compare("az", "z").get should be (10) + WeightedLevenshteinMetric(10, 0.1, 1).compare("z", "az").get should be (0.1) + WeightedLevenshteinMetric(10, 0.1, 1).compare("a", "z").get should be (1) + WeightedLevenshteinMetric(10, 0.1, 1).compare("z", "a").get should be (1) + WeightedLevenshteinMetric(10, 0.1, 1).compare("ab", "yz").get should be (2) + WeightedLevenshteinMetric(10, 0.1, 1).compare("yz", "ab").get should be (2) + WeightedLevenshteinMetric(10, 0.1, 1).compare("0", "0123456789").get should be (0.9) + WeightedLevenshteinMetric(10, 0.1, 1).compare("0123456789", "0").get should be (90) + WeightedLevenshteinMetric(10, 0.1, 1).compare("book", "back").get should be (2) + WeightedLevenshteinMetric(10, 0.1, 1).compare("back", "book").get should be (2) + WeightedLevenshteinMetric(10, 0.1, 1).compare("hosp", "hospital").get should be (0.4) + WeightedLevenshteinMetric(10, 0.1, 1).compare("hospital", "hosp").get should be (40) + WeightedLevenshteinMetric(10, 0.1, 1).compare("clmbs blvd", "columbus boulevard").get should be (0.8) + WeightedLevenshteinMetric(10, 0.1, 1).compare("columbus boulevard", "clmbs blvd").get should be (80) } } } } - "WeightedLevenshteinMetric companion object" should provide { - "pass-through compare method" should returns { - "same value as class" in { - WeightedLevenshteinMetric.compare("hospital", "hosp")(Options).get should be (40) - } - } - } -} - -object WeightedLevenshteinMetricSpec { - private final val Options = Tuple3[BigDecimal, BigDecimal, BigDecimal](10, 0.1, 1) - private final val Metric = WeightedLevenshteinMetric() } diff --git a/core/source/test/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizerSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizerSpec.scala index 56fdc13..1598a93 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizerSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/tokenization/NGramTokenizerSpec.scala @@ -5,65 +5,40 @@ import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) -final class NGramTokenizerSpec extends ScalaTest { - import NGramTokenizerSpec.Tokenizer - - "NGramTokenizer" should provide { - "tokenize method" when passed { - "empty argument" should returns { - "None" in { - Tokenizer.tokenize("")(1).isDefined should be (false) - } - } - "invalid n argument" should throws { - "IllegalArgumentException" in { - evaluating { - Tokenizer.tokenize("")(0).isDefined should be (false) - } should produce [IllegalArgumentException] - - evaluating { - Tokenizer.tokenize("")(-1).isDefined should be (false) - } should produce [IllegalArgumentException] - } +final class NGramTokenizerSpec extends ScalaTest { "NGramTokenizer" should provide { + "tokenize method" when passed { + "empty argument" should returns { + "None" in { + NGramTokenizer(1).tokenize("").isDefined should be (false) } - "valid argument" should returns { - "Array[String]" in { - Tokenizer.tokenize("abcdefghijklmnopqrstuvwxyz")(1).get should equal ( - Array( - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", - "s", "t", "u", "v", "w", "x", "y", "z" - ) - ) - Tokenizer.tokenize("abcdefghijklmnopqrstuvwxyz")(2).get should equal ( - Array( - "ab", "bc", "cd", "de", "ef", "fg", "gh", "hi", "ij", "jk", "kl", "lm", "mn", "no", "op", - "pq", "qr", "rs", "st", "tu", "uv", "vw", "wx", "xy", "yz" - ) - ) - Tokenizer.tokenize("abcdefghijklmnopqrstuvwxyz")(3).get should equal ( - Array( - "abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl", "klm", "lmn", "mno", - "nop", "opq", "pqr", "qrs", "rst", "stu", "tuv", "uvw", "vwx", "wxy", "xyz" - ) - ) - } + } + "invalid n argument" should returns { + "None" in { + NGramTokenizer(0).tokenize("").isDefined should be (false) + NGramTokenizer(-1).tokenize("").isDefined should be (false) } } - } - "NGramTokenizer companion object" should provide { - "pass-through tokenize method" should returns { - "same value as class" in { - NGramTokenizer.tokenize("abcdefghijklmnopqrstuvwxyz")(1).get should equal ( + "valid argument" should returns { + "Array[String]" in { + NGramTokenizer(1).tokenize("abcdefghijklmnopqrstuvwxyz").get should equal ( Array( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ) ) + NGramTokenizer(2).tokenize("abcdefghijklmnopqrstuvwxyz").get should equal ( + Array( + "ab", "bc", "cd", "de", "ef", "fg", "gh", "hi", "ij", "jk", "kl", "lm", "mn", "no", "op", + "pq", "qr", "rs", "st", "tu", "uv", "vw", "wx", "xy", "yz" + ) + ) + NGramTokenizer(3).tokenize("abcdefghijklmnopqrstuvwxyz").get should equal ( + Array( + "abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl", "klm", "lmn", "mno", + "nop", "opq", "pqr", "qrs", "rst", "stu", "tuv", "uvw", "vwx", "wxy", "xyz" + ) + ) } } } -} - -object NGramTokenizerSpec { - private final val Tokenizer = NGramTokenizer() -} +}} -- cgit v1.2.3