diff options
author | Rocky Madden <git@rockymadden.com> | 2013-03-18 21:32:59 -0600 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-03-18 21:32:59 -0600 |
commit | 8c76926e2f5b2280f5fd8028c74c6137a99d34e3 (patch) | |
tree | 6eef32d226bd9e621ede78fba43fa8312ea4ec80 /core/source | |
parent | d6b602cdb30051f45a6e7aac65e78bdc2680ffb1 (diff) | |
download | stringmetric-8c76926e2f5b2280f5fd8028c74c6137a99d34e3.tar.gz stringmetric-8c76926e2f5b2280f5fd8028c74c6137a99d34e3.tar.bz2 stringmetric-8c76926e2f5b2280f5fd8028c74c6137a99d34e3.zip |
Streamlined traits.
Diffstat (limited to 'core/source')
30 files changed, 178 insertions, 191 deletions
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala index f20f58c..4481848 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala @@ -1,5 +1,5 @@ package com.rockymadden.stringmetric -trait Algorithm[T, R] { - def compute(t: T): Option[R] +trait Algorithm[T, O, R] { + def compute(t: T)(implicit o: O): Option[R] } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala deleted file mode 100755 index dea1c42..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableAlgorithm[T, O, R] { - def compute(t: T)(implicit o: O): Option[R] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetric.scala deleted file mode 100755 index 16137c2..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetric.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableMetric[T, O, R] { - def compare(t1: T, t2: T)(implicit o: O): Option[R] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala deleted file mode 100755 index 0a43b0c..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala +++ /dev/null @@ -1,7 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableStringAlgorithm[O, R] extends ConfigurableAlgorithm[String, O, R] { - def compute(charArray: Array[Char])(implicit o: O): Option[Array[_]] -} - -object ConfigurableStringAlgorithm diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala deleted file mode 100755 index c17a668..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala +++ /dev/null @@ -1,52 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableStringMetric[O, R] extends ConfigurableMetric[String, O, R] { - def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit o: O): Option[R] -} - -object ConfigurableStringMetric { - type DiceSorensen = com.rockymadden.stringmetric.similarity.DiceSorensenMetric - val DiceSorensen = com.rockymadden.stringmetric.similarity.DiceSorensenMetric - - type Jaccard = com.rockymadden.stringmetric.similarity.JaccardMetric - val Jaccard = com.rockymadden.stringmetric.similarity.JaccardMetric - - type NGram = com.rockymadden.stringmetric.similarity.NGramMetric - val NGram = com.rockymadden.stringmetric.similarity.NGramMetric - - type Overlap = com.rockymadden.stringmetric.similarity.OverlapMetric - val Overlap = com.rockymadden.stringmetric.similarity.OverlapMetric - - 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 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 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 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 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/core/scala/com/rockymadden/stringmetric/Metric.scala b/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala index f865b4f..c2b56f2 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala @@ -1,5 +1,5 @@ package com.rockymadden.stringmetric -trait Metric[T, R] { - def compare(t1: T, t2: T): Option[R] +trait Metric[T, O, R] { + def compare(t1: T, t2: T)(implicit o: O): Option[R] } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala index 3c7a5b8..aa7884a 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala @@ -1,7 +1,7 @@ package com.rockymadden.stringmetric -trait StringAlgorithm[R] extends Algorithm[String, R] { - def compute(charArray: Array[Char]): Option[Array[_]] +trait StringAlgorithm[O, R] extends Algorithm[String, O, R] { + def compute(charArray: Array[Char])(implicit o: O): Option[Array[_]] } object StringAlgorithm { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala index 804e2d4..60db101 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala @@ -1,13 +1,19 @@ package com.rockymadden.stringmetric -trait StringMetric[R] extends Metric[String, R] { - def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[R] +trait StringMetric[O, R] extends Metric[String, O, R] { + def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit o: O): Option[R] } 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 @@ -20,9 +26,15 @@ object StringMetric { 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 @@ -32,10 +44,23 @@ object StringMetric { 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) @@ -55,10 +80,20 @@ object StringMetric { 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) @@ -72,4 +107,14 @@ object StringMetric { 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/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala index f061748..17e0931 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala @@ -5,8 +5,8 @@ import com.rockymadden.stringmetric.phonetic.Alphabet.{ Alpha, LowercaseVowel } import scala.annotation.{ switch, tailrec } /** An implementation of the Metaphone algorithm. */ -class MetaphoneAlgorithm extends StringAlgorithm[String] { this: StringFilter => - final override def compute(charArray: Array[Char]): Option[Array[Char]] = { +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) if (fca.length == 0 || !(Alpha isSuperset fca.head)) None @@ -18,7 +18,8 @@ class MetaphoneAlgorithm extends StringAlgorithm[String] { this: StringFilter => } } - final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) + final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = + compute(string.toCharArray).map(_.mkString) private[this] def deduplicate(ca: Array[Char]) = if (ca.length <= 1) ca diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala index df6e7cd..1793766 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala @@ -4,8 +4,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha /** A implementation of the Metaphone metric. */ -class MetaphoneMetric extends StringMetric[Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { +class MetaphoneMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Boolean] = { + val fca1 = filter(charArray1) lazy val fca2 = filter(charArray2) @@ -18,7 +20,7 @@ class MetaphoneMetric extends StringMetric[Boolean] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Boolean] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala index ce9f508..261918f 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala @@ -5,8 +5,8 @@ import com.rockymadden.stringmetric.phonetic.Alphabet.{ Alpha, LowercaseVowel } import scala.annotation.{ switch, tailrec } /** An implementation of the NYSIIS algorithm. */ -class NysiisAlgorithm extends StringAlgorithm[String] { this: StringFilter => - final override def compute(charArray: Array[Char]): Option[Array[Char]] = { +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) if (fca.length == 0 || !(Alpha isSuperset fca.head)) None @@ -27,7 +27,8 @@ class NysiisAlgorithm extends StringAlgorithm[String] { this: StringFilter => } } - final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) + final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = + compute(string.toCharArray).map(_.mkString) private[this] def cleanLast(ca: Array[Char]) = if (ca.length == 0) ca diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala index 61ab218..e83a0e6 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala @@ -4,8 +4,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha /** An implementation of the NYSIIS metric. */ -class NysiisMetric extends StringMetric[Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { +class NysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Boolean] = { + val unequal = (c1: Char, c2: Char) => { val lc1 = c1.toLower val lc2 = c2.toLower @@ -26,7 +28,7 @@ class NysiisMetric extends StringMetric[Boolean] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Boolean] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala index 14ed94b..ec9736b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala @@ -5,8 +5,8 @@ import com.rockymadden.stringmetric.phonetic.Alphabet.{ Alpha, LowercaseVowel } import scala.annotation.{ switch, tailrec } /** An implementation of the refined NYSIIS algorithm. */ -class RefinedNysiisAlgorithm extends StringAlgorithm[String] { this: StringFilter => - final override def compute(charArray: Array[Char]): Option[Array[Char]] = { +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) if (fca.length == 0 || !(Alpha isSuperset fca.head)) None @@ -20,7 +20,8 @@ class RefinedNysiisAlgorithm extends StringAlgorithm[String] { this: StringFilte } } - final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) + final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = + compute(string.toCharArray).map(_.mkString) private[this] def cleanLast(ca: Array[Char], s: Set[Char]) = if (ca.length == 0) ca diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala index 46ffb03..3298cc3 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala @@ -4,8 +4,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha /** An implementation of the refined NYSIIS metric. */ -class RefinedNysiisMetric extends StringMetric[Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { +class RefinedNysiisMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Boolean] = { + val unequal = (c1: Char, c2: Char) => { val lc1 = c1.toLower val lc2 = c2.toLower @@ -26,7 +28,7 @@ class RefinedNysiisMetric extends StringMetric[Boolean] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Boolean] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala index 4f73aff..d6ce29b 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala @@ -5,15 +5,16 @@ import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha import scala.annotation.{ switch, tailrec } /** An implementation of the refined Soundex algorithm. */ -class RefinedSoundexAlgorithm extends StringAlgorithm[String] { this: StringFilter => - final override def compute(charArray: Array[Char]): Option[Array[Char]] = { +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) if (fca.length == 0 || !(Alpha isSuperset fca.head)) None else Some(transcode(fca, Array(fca.head.toLower))) } - final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) + final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = + compute(string.toCharArray).map(_.mkString) @tailrec private[this] def transcode(i: Array[Char], o: Array[Char]): Array[Char] = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala index 3d0616a..7214de7 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala @@ -4,8 +4,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha /** An implementation of the refined Soundex metric. */ -class RefinedSoundexMetric extends StringMetric[Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { +class RefinedSoundexMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Boolean] = { + val fca1 = filter(charArray1) lazy val fca2 = filter(charArray2) @@ -19,7 +21,7 @@ class RefinedSoundexMetric extends StringMetric[Boolean] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Boolean] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala index e5bb579..e616caa 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala @@ -5,8 +5,8 @@ import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha import scala.annotation.{ switch, tailrec } /** An implementation of the Soundex algorithm. */ -class SoundexAlgorithm extends StringAlgorithm[String] { this: StringFilter => - final override def compute(charArray: Array[Char]): Option[Array[Char]] = { +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) if (fca.length == 0 || !(Alpha isSuperset fca.head)) None @@ -17,7 +17,8 @@ class SoundexAlgorithm extends StringAlgorithm[String] { this: StringFilter => } } - final override def compute(string: String): Option[String] = compute(string.toCharArray).map(_.mkString) + final override def compute(string: String)(implicit di: DummyImplicit): Option[String] = + compute(string.toCharArray).map(_.mkString) @tailrec private[this] def transcode(i: Array[Char], pc: Char, o: Array[Char]): Array[Char] = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala index 6b83863..bccfbd9 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala @@ -4,8 +4,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } import com.rockymadden.stringmetric.phonetic.Alphabet.Alpha /** An implementation of the Soundex metric. */ -class SoundexMetric extends StringMetric[Boolean] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { +class SoundexMetric extends StringMetric[DummyImplicit, Boolean] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Boolean] = { + val fca1 = filter(charArray1) lazy val fca2 = filter(charArray2) @@ -19,7 +21,7 @@ class SoundexMetric extends StringMetric[Boolean] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Boolean] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Boolean] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala index 912e2b3..5ee0d1a 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala @@ -1,13 +1,13 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{ ConfigurableStringMetric, MatchTuple, StringFilter } +import com.rockymadden.stringmetric.{ StringMetric, MatchTuple, StringFilter } import com.rockymadden.stringmetric.tokenization.NGramTokenizer /** * 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 ConfigurableStringMetric[Int, Double] { this: StringFilter => +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.") diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala index ece7458..5300ec9 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala @@ -3,8 +3,10 @@ package com.rockymadden.stringmetric.similarity import com.rockymadden.stringmetric.{ CompareTuple, StringFilter, StringMetric } /** An implementation of the Hamming metric. */ -class HammingMetric extends StringMetric[Int] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = { +class HammingMetric extends StringMetric[DummyImplicit, Int] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Int] = { + val fca1 = filter(charArray1) lazy val fca2 = filter(charArray2) @@ -13,7 +15,7 @@ class HammingMetric extends StringMetric[Int] { this: StringFilter => else Some(hamming(fca1, fca2)) } - final override def compare(string1: String, string2: String): Option[Int] = + 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]) = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala index 4547ba4..f54a8c7 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaccardMetric.scala @@ -1,10 +1,10 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{ ConfigurableStringMetric, MatchTuple, StringFilter } +import com.rockymadden.stringmetric.{ StringMetric, MatchTuple, StringFilter } import com.rockymadden.stringmetric.tokenization.NGramTokenizer /* An implementation of the Jaccard metric. */ -class JaccardMetric extends ConfigurableStringMetric[Int, Double] { this: StringFilter => +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.") diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala index 9449f3c..bab89c9 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala @@ -7,8 +7,10 @@ import scala.collection.mutable.{ ArrayBuffer, HashSet } * 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[Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = { +class JaroMetric 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) lazy val fca2 = filter(charArray2) @@ -27,7 +29,7 @@ class JaroMetric extends StringMetric[Double] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Double] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = compare(string1.toCharArray, string2.toCharArray) private[this] def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala index f4a7852..92e5e9d 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala @@ -7,8 +7,10 @@ import com.rockymadden.stringmetric.{ StringFilter, StringMetric } * 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[Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = { +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) @@ -23,7 +25,7 @@ class JaroWinklerMetric extends StringMetric[Double] { this: StringFilter => } } - final override def compare(string1: String, string2: String): Option[Double] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = compare(string1.toCharArray, string2.toCharArray) } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala index d60c218..241523c 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala @@ -3,8 +3,10 @@ package com.rockymadden.stringmetric.similarity import com.rockymadden.stringmetric.{ CompareTuple, StringFilter, StringMetric } /** An implementation of the Levenshtein metric. */ -class LevenshteinMetric extends StringMetric[Int] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = { +class LevenshteinMetric extends StringMetric[DummyImplicit, Int] { this: StringFilter => + final override def compare(charArray1: Array[Char], charArray2: Array[Char]) + (implicit di: DummyImplicit): Option[Int] = { + val fca1 = filter(charArray1) lazy val fca2 = filter(charArray2) @@ -13,7 +15,7 @@ class LevenshteinMetric extends StringMetric[Int] { this: StringFilter => else Some(levenshtein(fca1, fca2)) } - final override def compare(string1: String, string2: String): Option[Int] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Int] = compare(string1.toCharArray, string2.toCharArray) private[this] def levenshtein(ct: CompareTuple[Char]) = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala index 571e280..5ab5ffa 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala @@ -1,11 +1,11 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{ ConfigurableStringMetric, MatchTuple, StringFilter } +import com.rockymadden.stringmetric.{ StringMetric, MatchTuple, StringFilter } import com.rockymadden.stringmetric.tokenization.NGramTokenizer import scala.math /** An implementation of the N-Gram metric. */ -class NGramMetric extends ConfigurableStringMetric[Int, Double] { this: StringFilter => +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.") diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala index 593798f..24ced49 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/OverlapMetric.scala @@ -1,11 +1,11 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{ ConfigurableStringMetric, MatchTuple, StringFilter } +import com.rockymadden.stringmetric.{ StringMetric, MatchTuple, StringFilter } import com.rockymadden.stringmetric.tokenization.NGramTokenizer import scala.math /* An implementation of the overlap metric. */ -class OverlapMetric extends ConfigurableStringMetric[Int, Double] { this: StringFilter => +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.") diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala index d53b8c3..845e5b4 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala @@ -3,8 +3,10 @@ package com.rockymadden.stringmetric.similarity import com.rockymadden.stringmetric.{ CompareTuple, StringFilter, StringMetric } /** An implementation of the Ratcliff/Obershelp metric. */ -class RatcliffObershelpMetric extends StringMetric[Double] { this: StringFilter => - final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = { +class RatcliffObershelpMetric 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) lazy val fca2 = filter(charArray2) @@ -13,7 +15,7 @@ class RatcliffObershelpMetric extends StringMetric[Double] { this: StringFilter else Some(2d * commonSequences(fca1, fca2).foldLeft(0)(_ + _.length) / (fca1.length + fca2.length)) } - final override def compare(string1: String, string2: String): Option[Double] = + final override def compare(string1: String, string2: String)(implicit di: DummyImplicit): Option[Double] = compare(string1.toCharArray, string2.toCharArray) private[this] def longestCommonSubsequence(ct: CompareTuple[Char]) = { diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala index ecd66dc..feb0041 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala @@ -1,11 +1,11 @@ package com.rockymadden.stringmetric.similarity -import com.rockymadden.stringmetric.{ CompareTuple, ConfigurableStringMetric, StringFilter } +import com.rockymadden.stringmetric.{ CompareTuple, StringMetric, StringFilter } import scala.math.BigDecimal /** An implementation of a weighted Levenshtein metric. */ class WeightedLevenshteinMetric - extends ConfigurableStringMetric[(BigDecimal, BigDecimal, BigDecimal), Double] { this: StringFilter => + extends StringMetric[(BigDecimal, BigDecimal, BigDecimal), Double] { this: StringFilter => /** Options order is delete, insert, then substitute weight. */ final override def compare(charArray1: Array[Char], charArray2: Array[Char]) diff --git a/core/source/test/scala/com/rockymadden/stringmetric/ConfigurableStringMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/ConfigurableStringMetricSpec.scala deleted file mode 100755 index c548db3..0000000 --- a/core/source/test/scala/com/rockymadden/stringmetric/ConfigurableStringMetricSpec.scala +++ /dev/null @@ -1,59 +0,0 @@ -package com.rockymadden.stringmetric - -import com.rockymadden.stringmetric.similarity._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) -final class ConfigurableStringMetricSpec extends ScalaTest { - "StringMetric standalone object" should provide { - "compare method, type, and companion object pass-throughs" in { - val diceSorensen: ConfigurableStringMetric.DiceSorensen = ConfigurableStringMetric.DiceSorensen() - - diceSorensen.compare("testone", "testtwo")(1).get should - equal (ConfigurableStringMetric.compareWithDiceSorensen("testone", "testtwo")(1).get) - diceSorensen.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (ConfigurableStringMetric.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 jaccard: ConfigurableStringMetric.Jaccard = ConfigurableStringMetric.Jaccard() - - jaccard.compare("testone", "testtwo")(1).get should - equal (ConfigurableStringMetric.compareWithJaccard("testone", "testtwo")(1).get) - jaccard.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (ConfigurableStringMetric.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 nGram: ConfigurableStringMetric.NGram = ConfigurableStringMetric.NGram() - - nGram.compare("testone", "testtwo")(1).get should - equal (ConfigurableStringMetric.compareWithNGram("testone", "testtwo")(1).get) - nGram.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (ConfigurableStringMetric.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 overlap: ConfigurableStringMetric.Overlap = ConfigurableStringMetric.Overlap() - - overlap.compare("testone", "testtwo")(1).get should - equal (ConfigurableStringMetric.compareWithOverlap("testone", "testtwo")(1).get) - overlap.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should - equal (ConfigurableStringMetric.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 weightedLevenshtein: ConfigurableStringMetric.WeightedLevenshtein = ConfigurableStringMetric.WeightedLevenshtein() - - weightedLevenshtein.compare("testone", "testtwo")(1, 2, 3).get should - equal (ConfigurableStringMetric.compareWithWeightedLevenshtein("testone", "testtwo")(1, 2, 3).get) - weightedLevenshtein.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get should - equal (ConfigurableStringMetric.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/StringMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala index 2fdd925..ca99bff 100755 --- a/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala +++ b/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala @@ -9,6 +9,15 @@ import org.scalatest.junit.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 @@ -18,6 +27,15 @@ final class StringMetricSpec extends ScalaTest { 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 @@ -54,6 +72,15 @@ final class StringMetricSpec extends ScalaTest { 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 @@ -63,6 +90,15 @@ final class StringMetricSpec extends ScalaTest { 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 @@ -89,6 +125,15 @@ final class StringMetricSpec extends ScalaTest { 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) } } } |