diff options
author | Rocky Madden <git@rockymadden.com> | 2013-02-18 23:14:20 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-02-18 23:14:20 -0700 |
commit | 26397170c22cc80e43759c8fd3bb239a510f0460 (patch) | |
tree | 17d1dad4c38828bd0e1003e61e8016d8817cb4fe | |
parent | eb36c1bc243d8d7e3969b3808bbaaf8b233fb40a (diff) | |
download | stringmetric-26397170c22cc80e43759c8fd3bb239a510f0460.tar.gz stringmetric-26397170c22cc80e43759c8fd3bb239a510f0460.tar.bz2 stringmetric-26397170c22cc80e43759c8fd3bb239a510f0460.zip |
Collapsed traits.
22 files changed, 34 insertions, 66 deletions
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala index 40d0d5a..f20f58c 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Algorithm.scala @@ -1,3 +1,5 @@ package com.rockymadden.stringmetric -trait Algorithm[T, R] extends AlgorithmLike[T, R] +trait Algorithm[T, R] { + def compute(t: T): Option[R] +} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala deleted file mode 100755 index 0ac1b75..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait AlgorithmLike[T, R] { - def compute(t: T): Option[R] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala index 34d5919..6fa592f 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithm.scala @@ -1,3 +1,5 @@ package com.rockymadden.stringmetric -trait ConfigurableAlgorithm[T, R, O] extends ConfigurableAlgorithmLike[T, R, O] +trait ConfigurableAlgorithm[T, R, O] { + def compute(t: T)(implicit o: O): Option[R] +} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala deleted file mode 100755 index 85b6b0c..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableAlgorithmLike[T, R, O] { - 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 index 035027e..e05adf1 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetric.scala @@ -1,3 +1,5 @@ package com.rockymadden.stringmetric -trait ConfigurableMetric[T, R, O] extends ConfigurableMetricLike[T, R, O] +trait ConfigurableMetric[T, R, O] { + def compare(t1: T, t2: T)(implicit o: O): Option[R] +} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala deleted file mode 100755 index d64ccaf..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableMetricLike[T, R, O] { - 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 index 20464a7..8cef966 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithm.scala @@ -2,8 +2,8 @@ package com.rockymadden.stringmetric import com.rockymadden.stringmetric.similarity.NGramAlgorithm -trait ConfigurableStringAlgorithm[R, O] - extends ConfigurableAlgorithm[String, R, O] with ConfigurableStringAlgorithmLike[R, O] with StringFilterLike { +trait ConfigurableStringAlgorithm[R, O] extends ConfigurableAlgorithm[String, R, O] with StringFilterable { + def compute(charArray: Array[Char])(implicit o: O): Option[Array[_]] override def filter(charArray: Array[Char]): Array[Char] = charArray diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala deleted file mode 100755 index 669cbd9..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableStringAlgorithmLike[R, O] extends ConfigurableAlgorithmLike[String, R, O] { - def compute(charArray: Array[Char])(implicit o: O): Option[Array[_]] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala index 3ee31b7..da3e333 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetric.scala @@ -2,8 +2,8 @@ package com.rockymadden.stringmetric import com.rockymadden.stringmetric.similarity.{ DiceSorensenMetric, NGramMetric, WeightedLevenshteinMetric } -trait ConfigurableStringMetric[R, O] - extends ConfigurableMetric[String, R, O] with ConfigurableStringMetricLike[R, O] with StringFilterLike { +trait ConfigurableStringMetric[R, O] extends ConfigurableMetric[String, R, O] with StringFilterable { + def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit o: O): Option[R] override def filter(charArray: Array[Char]): Array[Char] = charArray diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala deleted file mode 100755 index 87c87ce..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait ConfigurableStringMetricLike[R, O] extends ConfigurableMetricLike[String, R, O] { - def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit o: O): Option[R] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/Filter.scala b/core/source/core/scala/com/rockymadden/stringmetric/Filter.scala index 17efad9..860c9e3 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/Filter.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Filter.scala @@ -1,3 +1,3 @@ package com.rockymadden.stringmetric -trait Filter[T] extends FilterLike[T] +trait Filter[T] extends Filterable[T] diff --git a/core/source/core/scala/com/rockymadden/stringmetric/FilterLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/Filterable.scala index 081e0b5..537333d 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/FilterLike.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Filterable.scala @@ -1,5 +1,5 @@ package com.rockymadden.stringmetric -trait FilterLike[T] { +trait Filterable[T] { def filter(t: T): T } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala b/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala index b20755e..f865b4f 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/Metric.scala @@ -1,3 +1,5 @@ package com.rockymadden.stringmetric -trait Metric[T, R] extends MetricLike[T, R] +trait Metric[T, R] { + def compare(t1: T, t2: T): Option[R] +} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala deleted file mode 100755 index 622d937..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait MetricLike[T, R] { - def compare(t1: T, t2: T): 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 f8e4a50..87d0dc6 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala @@ -2,7 +2,9 @@ package com.rockymadden.stringmetric import com.rockymadden.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm } -trait StringAlgorithm[R] extends Algorithm[String, R] with StringAlgorithmLike[R] with StringFilterLike { +trait StringAlgorithm[R] extends Algorithm[String, R] with StringFilterable { + def compute(charArray: Array[Char]): Option[Array[_]] + override def filter(charArray: Array[Char]): Array[Char] = charArray override def filter(string: String): String = string diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala deleted file mode 100755 index 9b734ac..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringAlgorithmLike[R] extends AlgorithmLike[String, R] { - def compute(charArray: Array[Char]): Option[Array[_]] -} diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala index e6895b1..e362b2f 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala @@ -2,9 +2,7 @@ package com.rockymadden.stringmetric import com.rockymadden.stringmetric.filter._ -trait StringFilter extends StringFilterLike { - def filter(charArray: Array[Char]): Array[Char] -} +trait StringFilter extends Filter[String] with StringFilterable object StringFilter { def asciiControl = new StringFilterDelegate with AsciiControlStringFilter diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringFilterLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringFilterable.scala index e9672e8..d639dfb 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringFilterLike.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringFilterable.scala @@ -1,5 +1,5 @@ package com.rockymadden.stringmetric -trait StringFilterLike extends FilterLike[String] { +trait StringFilterable extends Filterable[String] { def filter(charArray: Array[Char]): Array[Char] } diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala index 65fcd22..6905ec3 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala @@ -3,7 +3,9 @@ package com.rockymadden.stringmetric import com.rockymadden.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric } import com.rockymadden.stringmetric.similarity._ -trait StringMetric[R] extends Metric[String, R] with StringMetricLike[R] with StringFilterLike { +trait StringMetric[R] extends Metric[String, R] with StringFilterable { + def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[R] + override def filter(charArray: Array[Char]): Array[Char] = charArray override def filter(string: String): String = string diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala deleted file mode 100755 index 4ae93b5..0000000 --- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.rockymadden.stringmetric - -trait StringMetricLike[R] extends MetricLike[String, R] { - def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[R] -} 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 5e5dc70..6a9becf 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala @@ -3,7 +3,7 @@ package com.rockymadden.stringmetric.phonetic import com.rockymadden.stringmetric.StringMetric import com.rockymadden.stringmetric.phonetic.Alphabet._ -/** A implementation of Metaphone metric. */ +/** A implementation of the Metaphone metric. */ class MetaphoneMetric extends StringMetric[Boolean] { final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = { val fca1 = filter(charArray1) 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 56dfc55..baa9bf1 100755 --- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala +++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala @@ -12,17 +12,15 @@ class JaroWinklerMetric extends StringMetric[Double] { val fca1 = filter(charArray1) val fca2 = filter(charArray2) - JaroMetric().compare(fca1, fca2).map( - _ match { - case 0d => 0d - case 1d => 1d - case jaro => { - val prefix = fca1.zip(fca2).takeWhile(t => t._1 == t._2) + JaroMetric().compare(fca1, fca2).map { + case 0d => 0d + case 1d => 1d + case jaro => { + val prefix = fca1.zip(fca2).takeWhile(t => t._1 == t._2) - jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1d * (1 - jaro)) - } + jaro + ((if (prefix.length <= 4) prefix.length else 4) * 0.1d * (1 - jaro)) } - ) + } } final override def compare(string1: String, string2: String): Option[Double] = |