summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2013-02-09 22:13:05 -0700
committerRocky Madden <git@rockymadden.com>2013-02-09 22:13:05 -0700
commitbeb0ef90024ab651267b9fd3c708e2cf27743c60 (patch)
tree3901a888fb59f6fd714b3a2e16af309b6ae1933c /core
parentcc777abe17dc2cbda7584dc6d80e8d31416de5fd (diff)
downloadstringmetric-beb0ef90024ab651267b9fd3c708e2cf27743c60.tar.gz
stringmetric-beb0ef90024ab651267b9fd3c708e2cf27743c60.tar.bz2
stringmetric-beb0ef90024ab651267b9fd3c708e2cf27743c60.zip
Refactored traits so that metrics and algorithms can be decorated with additional functionality.
Diffstat (limited to 'core')
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala5
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala5
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala5
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala9
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala9
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/FilterLike.scala5
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringAlgorithm.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringMetric.scala9
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/FilterableStringAlgorithm.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/FilterableStringMetric.scala9
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala5
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala72
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala46
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/StringFilterLike.scala (renamed from core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala)10
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala146
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala103
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilter.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilter.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilter.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilter.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilter.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilter.scala8
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/filter/package.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/package.scala1
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala19
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala32
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala19
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala32
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala19
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala32
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala19
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala32
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala19
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala32
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/phonetic/package.scala6
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala40
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala26
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala29
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala30
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala26
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala26
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala38
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala26
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala31
-rwxr-xr-xcore/source/core/scala/com/rockymadden/stringmetric/similarity/package.scala6
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala38
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala2
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala278
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala32
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala218
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala24
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala248
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala24
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala172
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala24
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala170
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala24
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala62
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala28
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala54
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala54
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala54
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala22
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala62
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala33
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala45
73 files changed, 1412 insertions, 1344 deletions
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala
new file mode 100755
index 0000000..0ac1b75
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/AlgorithmLike.scala
@@ -0,0 +1,5 @@
+package com.rockymadden.stringmetric
+
+trait AlgorithmLike[T, R] {
+ def compute(t: T): Option[R]
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala
new file mode 100755
index 0000000..85b6b0c
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableAlgorithmLike.scala
@@ -0,0 +1,5 @@
+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/ConfigurableMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala
new file mode 100755
index 0000000..d64ccaf
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableMetricLike.scala
@@ -0,0 +1,5 @@
+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/ConfigurableStringAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala
new file mode 100755
index 0000000..8087b55
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringAlgorithmLike.scala
@@ -0,0 +1,9 @@
+package com.rockymadden.stringmetric
+
+trait ConfigurableStringAlgorithmLike[R, O] extends ConfigurableAlgorithmLike[String, R, O] { this: StringFilterLike =>
+ def compute(charArray: Array[Char])(implicit o: O): 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/ConfigurableStringMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala
new file mode 100755
index 0000000..506989f
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/ConfigurableStringMetricLike.scala
@@ -0,0 +1,9 @@
+package com.rockymadden.stringmetric
+
+trait ConfigurableStringMetricLike[R, O] extends ConfigurableMetricLike[String, R, O] { this: StringFilterLike =>
+ def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit o: O): 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/FilterLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/FilterLike.scala
new file mode 100755
index 0000000..081e0b5
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/FilterLike.scala
@@ -0,0 +1,5 @@
+package com.rockymadden.stringmetric
+
+trait FilterLike[T] {
+ def filter(t: T): T
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringAlgorithm.scala
deleted file mode 100755
index 5224354..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringAlgorithm.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Trait for all filterable and configurable [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-trait FilterableConfigurableStringAlgorithm[O] extends StringAlgorithm {
- def compute(string: String)(o: O)(implicit stringFilter: StringFilter): Option[ComputeReturn]
-
- def compute(charArray: Array[Char])(o: O)(implicit stringFilter: StringFilter): Option[Array[_]]
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringMetric.scala
deleted file mode 100755
index 5ed42e0..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/FilterableConfigurableStringMetric.scala
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Trait for all filterable and configurable [[com.rockymadden.stringmetric.StringMetric]]. */
-trait FilterableConfigurableStringMetric[O] extends StringMetric {
- def compare(string1: String, string2: String)(o: O)(implicit stringFilter: StringFilter): Option[CompareReturn]
-
- def compare(charArray1: Array[Char], charArray2: Array[Char])(o: O)
- (implicit stringFilter: StringFilter): Option[CompareReturn]
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringAlgorithm.scala
deleted file mode 100755
index a85e35c..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringAlgorithm.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Trait for all filterable [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-trait FilterableStringAlgorithm extends StringAlgorithm {
- def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn]
-
- def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[_]]
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringMetric.scala
deleted file mode 100755
index cec9b09..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/FilterableStringMetric.scala
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Trait for all filterable [[com.rockymadden.stringmetric.StringMetric]]. */
-trait FilterableStringMetric extends StringMetric {
- def compare(string1: String, string2: String)(implicit stringFilter: StringFilter): Option[CompareReturn]
-
- def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn]
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala
new file mode 100755
index 0000000..622d937
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/MetricLike.scala
@@ -0,0 +1,5 @@
+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
deleted file mode 100755
index 9bb0271..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithm.scala
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.rockymadden.stringmetric
-
-import com.rockymadden.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm }
-import com.rockymadden.stringmetric.similarity.NGramAlgorithm
-
-/** Trait for all string algorithms. */
-trait StringAlgorithm {
- type ComputeReturn <: AnyRef
-}
-
-/** Standalone convenience object for all extending [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object StringAlgorithm {
- def computeWithMetaphone(charArray: Array[Char])
- (implicit stringFilter: StringFilter): Option[Array[Char]] =
-
- MetaphoneAlgorithm.compute(charArray)(stringFilter)
-
- def computeWithMetaphone(string: String)
- (implicit stringFilter: StringFilter): Option[MetaphoneAlgorithm.ComputeReturn] =
-
- MetaphoneAlgorithm.compute(string)(stringFilter)
-
- def computeWithNGram(charArray: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[Array[Array[Char]]] =
-
- NGramAlgorithm.compute(charArray)(n)(stringFilter)
-
- def computeWithNGram(string: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[NGramAlgorithm.ComputeReturn] =
-
- NGramAlgorithm.compute(string)(n)(stringFilter)
-
- def computeWithNysiis(charArray: Array[Char])
- (implicit stringFilter: StringFilter): Option[Array[Char]] =
-
- NysiisAlgorithm.compute(charArray)(stringFilter)
-
- def computeWithNysiis(string: String)
- (implicit stringFilter: StringFilter): Option[NysiisAlgorithm.ComputeReturn] =
-
- NysiisAlgorithm.compute(string)(stringFilter)
-
- def computeWithRefinedSoundex(charArray: Array[Char])
- (implicit stringFilter: StringFilter): Option[Array[Char]] =
-
- RefinedSoundexAlgorithm.compute(charArray)(stringFilter)
-
- def computeWithRefinedSoundex(string: String)
- (implicit stringFilter: StringFilter): Option[RefinedSoundexAlgorithm.ComputeReturn] =
-
- RefinedSoundexAlgorithm.compute(string)(stringFilter)
-
- def computeWithSoundex(charArray: Array[Char])
- (implicit stringFilter: StringFilter): Option[Array[Char]] =
-
- SoundexAlgorithm.compute(charArray)(stringFilter)
-
- def computeWithSoundex(string: String)
- (implicit stringFilter: StringFilter): Option[SoundexAlgorithm.ComputeReturn] =
-
- SoundexAlgorithm.compute(string)(stringFilter)
-
- def metaphone: MetaphoneAlgorithm.type = MetaphoneAlgorithm
-
- def nGram: NGramAlgorithm.type = NGramAlgorithm
-
- def nysiis: NysiisAlgorithm.type = NysiisAlgorithm
-
- def refinedSoundex: RefinedSoundexAlgorithm.type = RefinedSoundexAlgorithm
-
- def soundex: SoundexAlgorithm.type = SoundexAlgorithm
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala
new file mode 100755
index 0000000..d9cf6a7
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/StringAlgorithmLike.scala
@@ -0,0 +1,46 @@
+package com.rockymadden.stringmetric
+
+import com.rockymadden.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm }
+import com.rockymadden.stringmetric.similarity.NGramAlgorithm
+
+trait StringAlgorithmLike[R] extends AlgorithmLike[String, R] { this: StringFilterLike =>
+ def compute(charArray: Array[Char]): Option[Array[_]]
+
+ override def filter(charArray: Array[Char]): Array[Char] = charArray
+
+ override def filter(string: String): String = string
+}
+
+object StringAlgorithmLike {
+ def computeWithMetaphone(charArray: Array[Char]): Option[Array[Char]] = MetaphoneAlgorithm().compute(charArray)
+
+ def computeWithMetaphone(string: String): Option[String] = MetaphoneAlgorithm().compute(string)
+
+ def computeWithNGram(charArray: Array[Char])(n: Int): Option[Array[Array[Char]]] =
+ NGramAlgorithm().compute(charArray)(n)
+
+ def computeWithNGram(string: String)(n: Int): Option[Array[String]] = NGramAlgorithm().compute(string)(n)
+
+ def computeWithNysiis(charArray: Array[Char]): Option[Array[Char]] = NysiisAlgorithm().compute(charArray)
+
+ def computeWithNysiis(string: String): Option[String] = NysiisAlgorithm().compute(string)
+
+ def computeWithRefinedSoundex(charArray: Array[Char]): Option[Array[Char]] =
+ RefinedSoundexAlgorithm().compute(charArray)
+
+ def computeWithRefinedSoundex(string: String): Option[String] = RefinedSoundexAlgorithm().compute(string)
+
+ def computeWithSoundex(charArray: Array[Char]): Option[Array[Char]] = SoundexAlgorithm().compute(charArray)
+
+ def computeWithSoundex(string: String): Option[String] = SoundexAlgorithm().compute(string)
+
+ def metaphone: MetaphoneAlgorithm.type = MetaphoneAlgorithm
+
+ def nGram: NGramAlgorithm.type = NGramAlgorithm
+
+ def nysiis: NysiisAlgorithm.type = NysiisAlgorithm
+
+ def refinedSoundex: RefinedSoundexAlgorithm.type = RefinedSoundexAlgorithm
+
+ def soundex: SoundexAlgorithm.type = SoundexAlgorithm
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringFilterLike.scala
index 2a84360..c2d604a 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/StringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/StringFilterLike.scala
@@ -2,17 +2,11 @@ package com.rockymadden.stringmetric
import com.rockymadden.stringmetric.filter._
-/** Trait for all string filters. */
-trait StringFilter {
- def filter(string: String): String
-
+trait StringFilterLike extends FilterLike[String] {
def filter(charArray: Array[Char]): Array[Char]
}
-/** Standalone convenience object for all extending [[com.rockymadden.stringmetric.StringFilter]]. */
-object StringFilter {
- implicit val stringFilter = delegate
-
+object StringFilterLike {
def asciiControl = new StringFilterDelegate with AsciiControlStringFilter
def asciiControlOnly = new StringFilterDelegate with AsciiControlOnlyStringFilter
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala
deleted file mode 100755
index e05ce4e..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/StringMetric.scala
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.rockymadden.stringmetric
-
-import com.rockymadden.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric }
-import com.rockymadden.stringmetric.similarity._
-
-/** Trait for all string metrics. */
-trait StringMetric {
- type CompareReturn <: AnyVal
-}
-
-/** Stabdalone convenience object for all extending [[com.rockymadden.stringmetric.StringMetric]]. */
-object StringMetric {
- def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[DiceSorensenMetric.CompareReturn] =
-
- DiceSorensenMetric.compare(charArray1, charArray2)(n)(stringFilter)
-
- def compareWithDiceSorensen(string1: String, string2: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[DiceSorensenMetric.CompareReturn] =
-
- DiceSorensenMetric.compare(string1, string2)(n)(stringFilter)
-
- def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[HammingMetric.CompareReturn] =
-
- HammingMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithHamming(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[HammingMetric.CompareReturn] =
-
- HammingMetric.compare(string1, string2)(stringFilter)
-
- def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[JaroMetric.CompareReturn] =
-
- JaroMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithJaro(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[JaroMetric.CompareReturn] =
-
- JaroMetric.compare(string1, string2)(stringFilter)
-
- def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[JaroWinklerMetric.CompareReturn] =
-
- JaroWinklerMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithJaroWinkler(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[JaroWinklerMetric.CompareReturn] =
-
- JaroWinklerMetric.compare(string1, string2)(stringFilter)
-
- def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[LevenshteinMetric.CompareReturn] =
-
- LevenshteinMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithLevenshtein(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[LevenshteinMetric.CompareReturn] =
-
- LevenshteinMetric.compare(string1, string2)(stringFilter)
-
- def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[MetaphoneMetric.CompareReturn] =
-
- MetaphoneMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithMetaphone(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[MetaphoneMetric.CompareReturn] =
-
- MetaphoneMetric.compare(string1, string2)(stringFilter)
-
- def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[NGramMetric.CompareReturn] =
-
- NGramMetric.compare(charArray1, charArray2)(n)(stringFilter)
-
- def compareWithNGram(string1: String, string2: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[NGramMetric.CompareReturn] =
-
- NGramMetric.compare(string1, string2)(n)(stringFilter)
-
- def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[NysiisMetric.CompareReturn] =
-
- NysiisMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithNysiis(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[NysiisMetric.CompareReturn] =
-
- NysiisMetric.compare(string1, string2)(stringFilter)
-
- def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[RefinedSoundexMetric.CompareReturn] =
-
- RefinedSoundexMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithRefinedSoundex(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[RefinedSoundexMetric.CompareReturn] =
-
- RefinedSoundexMetric.compare(string1, string2)(stringFilter)
-
- def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[SoundexMetric.CompareReturn] =
-
- SoundexMetric.compare(charArray1, charArray2)(stringFilter)
-
- def compareWithSoundex(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[SoundexMetric.CompareReturn] =
-
- SoundexMetric.compare(string1, string2)(stringFilter)
-
- def compareWithWeightedLevenshtein(charArray1: Array[Char], charArray2: Array[Char])
- (options: Tuple3[BigDecimal, BigDecimal, BigDecimal])
- (implicit stringFilter: StringFilter): Option[WeightedLevenshteinMetric.CompareReturn] =
-
- WeightedLevenshteinMetric.compare(charArray1, charArray2)(options)(stringFilter)
-
- def compareWithWeightedLevenshtein(string1: String, string2: String)
- (options: Tuple3[BigDecimal, BigDecimal, BigDecimal])
- (implicit stringFilter: StringFilter): Option[WeightedLevenshteinMetric.CompareReturn] =
-
- WeightedLevenshteinMetric.compare(string1, string2)(options)(stringFilter)
-
- def diceSorensen: DiceSorensenMetric.type = DiceSorensenMetric
-
- def hamming: HammingMetric.type = HammingMetric
-
- def jaro: JaroMetric.type = JaroMetric
-
- def jaroWinkler: JaroWinklerMetric.type = JaroWinklerMetric
-
- def levenshtein: LevenshteinMetric.type = LevenshteinMetric
-
- def metaphone: MetaphoneMetric.type = MetaphoneMetric
-
- def nGram: NGramMetric.type = NGramMetric
-
- def nysiis: NysiisMetric.type = NysiisMetric
-
- def refinedSoundex: RefinedSoundexMetric.type = RefinedSoundexMetric
-
- def soundex: SoundexMetric.type = SoundexMetric
-
- def weightedLevenshtein: WeightedLevenshteinMetric.type = WeightedLevenshteinMetric
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala b/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala
new file mode 100755
index 0000000..a0767e3
--- /dev/null
+++ b/core/source/core/scala/com/rockymadden/stringmetric/StringMetricLike.scala
@@ -0,0 +1,103 @@
+package com.rockymadden.stringmetric
+
+import com.rockymadden.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric }
+import com.rockymadden.stringmetric.similarity._
+
+trait StringMetricLike[R] extends MetricLike[String, R] { this: StringFilterLike =>
+ 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
+}
+
+object StringMetricLike {
+ def compareWithDiceSorensen(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] =
+ DiceSorensenMetric().compare(charArray1, charArray2)(n)
+
+ def compareWithDiceSorensen(string1: String, string2: String)(n: Int): Option[Double] =
+ DiceSorensenMetric().compare(string1, string2)(n)
+
+ def compareWithHamming(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] =
+ HammingMetric().compare(charArray1, charArray2)
+
+ def compareWithHamming(string1: String, string2: String): Option[Int] = HammingMetric().compare(string1, string2)
+
+ def compareWithJaro(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] =
+ JaroMetric().compare(charArray1, charArray2)
+
+ def compareWithJaro(string1: String, string2: String): Option[Double] = JaroMetric().compare(string1, string2)
+
+ def compareWithJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] =
+ JaroWinklerMetric().compare(charArray1, charArray2)
+
+ def compareWithJaroWinkler(string1: String, string2: String): Option[Double] =
+ JaroWinklerMetric().compare(string1, string2)
+
+ def compareWithLevenshtein(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] =
+ LevenshteinMetric().compare(charArray1, charArray2)
+
+ def compareWithLevenshtein(string1: String, string2: String): Option[Int] =
+ LevenshteinMetric().compare(string1, string2)
+
+ def compareWithMetaphone(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] =
+ MetaphoneMetric().compare(charArray1, charArray2)
+
+ def compareWithMetaphone(string1: String, string2: String): Option[Boolean] =
+ MetaphoneMetric().compare(string1, string2)
+
+ def compareWithNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int): Option[Double] =
+ NGramMetric().compare(charArray1, charArray2)(n)
+
+ def compareWithNGram(string1: String, string2: String)(n: Int): Option[Double] =
+ NGramMetric().compare(string1, string2)(n)
+
+ def compareWithNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] =
+ NysiisMetric().compare(charArray1, charArray2)
+
+ def compareWithNysiis(string1: String, string2: String): Option[Boolean] = NysiisMetric().compare(string1, string2)
+
+ def compareWithRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] =
+ RefinedSoundexMetric().compare(charArray1, charArray2)
+
+ def compareWithRefinedSoundex(string1: String, string2: String): Option[Boolean] =
+ RefinedSoundexMetric().compare(string1, string2)
+
+ def compareWithSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] =
+ SoundexMetric().compare(charArray1, charArray2)
+
+ def compareWithSoundex(string1: String, string2: String): Option[Boolean] =
+ SoundexMetric().compare(string1, string2)
+
+ def compareWithWeightedLevenshtein(charArray1: Array[Char], charArray2: Array[Char])
+ (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] =
+
+ WeightedLevenshteinMetric().compare(charArray1, charArray2)(options)
+
+ def compareWithWeightedLevenshtein(string1: String, string2: String)
+ (options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] =
+
+ WeightedLevenshteinMetric().compare(string1, string2)(options)
+
+ def diceSorensen: DiceSorensenMetric.type = DiceSorensenMetric
+
+ def hamming: HammingMetric.type = HammingMetric
+
+ def jaro: JaroMetric.type = JaroMetric
+
+ def jaroWinkler: JaroWinklerMetric.type = JaroWinklerMetric
+
+ def levenshtein: LevenshteinMetric.type = LevenshteinMetric
+
+ def metaphone: MetaphoneMetric.type = MetaphoneMetric
+
+ def nGram: NGramMetric.type = NGramMetric
+
+ def nysiis: NysiisMetric.type = NysiisMetric
+
+ def refinedSoundex: RefinedSoundexMetric.type = RefinedSoundexMetric
+
+ def soundex: SoundexMetric.type = SoundexMetric
+
+ def weightedLevenshtein: WeightedLevenshteinMetric.type = WeightedLevenshteinMetric
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilter.scala
index 912d1d9..7fa05e3 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures only ASCII control characters matter. */
-trait AsciiControlOnlyStringFilter extends StringFilter {
+/** Ensures only ASCII control characters matter. */
+trait AsciiControlOnlyStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => (c <= 31 || c == 127)))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilter.scala
index 4442a31..382fc43 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII controls do not matter. */
-trait AsciiControlStringFilter extends StringFilter {
+/** Ensures ASCII controls do not matter. */
+trait AsciiControlStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => !(c <= 31 || c == 127)))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilter.scala
index 88bb542..68cbd59 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII letter case-sensitivity does not matter. */
-trait AsciiLetterCaseStringFilter extends StringFilter {
+/** Ensures ASCII letter case-sensitivity does not matter. */
+trait AsciiLetterCaseStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.map(c => if (c >= 65 && c <= 90) (c + 32).toChar else c))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilter.scala
index 00f32d4..c1fcbd4 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures only ASCII letters and numbers matter. */
-trait AsciiLetterNumberOnlyStringFilter extends StringFilter {
+/** Ensures only ASCII letters and numbers matter. */
+trait AsciiLetterNumberOnlyStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(
charArray.filter(c =>
@@ -12,4 +12,4 @@ trait AsciiLetterNumberOnlyStringFilter extends StringFilter {
)
abstract override def filter(string: String): String = filter(string.toCharArray).mkString
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilter.scala
index 8ece1cd..1c47416 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII letters and numbers do not matter. */
-trait AsciiLetterNumberStringFilter extends StringFilter {
+/** Ensures ASCII letters and numbers do not matter. */
+trait AsciiLetterNumberStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(
charArray.filter(c =>
@@ -12,4 +12,4 @@ trait AsciiLetterNumberStringFilter extends StringFilter {
)
abstract override def filter(string: String): String = filter(string.toCharArray).mkString
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilter.scala
index 86c1c77..09c40c5 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures only ASCII letters matter. */
-trait AsciiLetterOnlyStringFilter extends StringFilter {
+/** Ensures only ASCII letters matter. */
+trait AsciiLetterOnlyStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => ((c >= 65 && c <= 90 ) || (c >= 97 && c <= 122))))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilter.scala
index a86d63d..c9c0890 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII letters do not matter. */
-trait AsciiLetterStringFilter extends StringFilter {
+/** Ensures ASCII letters do not matter. */
+trait AsciiLetterStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => !((c >= 65 && c <= 90 ) || (c >= 97 && c <= 122))))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilter.scala
index 74af4e4..e98f871 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures only ASCII numbers matter. */
-trait AsciiNumberOnlyStringFilter extends StringFilter {
+/** Ensures only ASCII numbers matter. */
+trait AsciiNumberOnlyStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => (c >= 48 && c <= 57 )))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilter.scala
index 2a9ae1f..d74b266 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII numbers do not matter. */
-trait AsciiNumberStringFilter extends StringFilter {
+/** Ensures ASCII numbers do not matter. */
+trait AsciiNumberStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(charArray.filter(c => !(c >= 48 && c <= 57)))
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilter.scala
index 8edffe8..ff3df19 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilter.scala
@@ -1,10 +1,10 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII spaces do not matter. */
-trait AsciiSpaceStringFilter extends StringFilter {
+/** Ensures ASCII spaces do not matter. */
+trait AsciiSpaceStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] = super.filter(charArray.filter(_ != ' '))
abstract override def filter(string: String): String = filter(string.toCharArray).mkString
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilter.scala
index 800cb3b..605a3c0 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures only ASCII symbols matter. */
-trait AsciiSymbolOnlyStringFilter extends StringFilter {
+/** Ensures only ASCII symbols matter. */
+trait AsciiSymbolOnlyStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(
charArray.filter(c =>
@@ -12,4 +12,4 @@ trait AsciiSymbolOnlyStringFilter extends StringFilter {
)
abstract override def filter(string: String): String = filter(string.toCharArray).mkString
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilter.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilter.scala
index 3891f9a..6ed85ed 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilter.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilter.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-/** A decorator [[com.rockymadden.stringmetric.StringFilter]]. Ensures ASCII symbols do not matter. */
-trait AsciiSymbolStringFilter extends StringFilter {
+/** Ensures ASCII symbols do not matter. */
+trait AsciiSymbolStringFilter extends StringFilterLike {
abstract override def filter(charArray: Array[Char]): Array[Char] =
super.filter(
charArray.filter(c =>
@@ -12,4 +12,4 @@ trait AsciiSymbolStringFilter extends StringFilter {
)
abstract override def filter(string: String): String = filter(string.toCharArray).mkString
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala
index ba62e15..3264568 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/filter/StringFilterDelegate.scala
@@ -1,9 +1,9 @@
package com.rockymadden.stringmetric.filter
-import com.rockymadden.stringmetric.StringFilter
+import com.rockymadden.stringmetric.StringFilterLike
-class StringFilterDelegate extends StringFilter {
+class StringFilterDelegate extends StringFilterLike {
override def filter(charArray: Array[Char]): Array[Char] = charArray
override def filter(string: String): String = string
-} \ No newline at end of file
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/filter/package.scala b/core/source/core/scala/com/rockymadden/stringmetric/filter/package.scala
deleted file mode 100755
index ca003eb..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/filter/package.scala
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Provides filter functionality. */
-package object filter {
-
-}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/package.scala b/core/source/core/scala/com/rockymadden/stringmetric/package.scala
index 01c1eb1..6752f4d 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/package.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/package.scala
@@ -1,6 +1,5 @@
package com.rockymadden
-/** Provides traits and standalone convenience objects. */
package object stringmetric {
type CompareTuple[T] = (Array[T], Array[T])
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 a198890..796a922 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithm.scala
@@ -1,15 +1,13 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ StringAlgorithmLike, StringFilterLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
import scala.annotation.{ switch, tailrec }
-/** An implementation of the Metaphone [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
- type ComputeReturn = String
-
- override def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = {
- val fca = stringFilter.filter(charArray)
+/** An implementation of the Metaphone algorithm. */
+class MetaphoneAlgorithm extends StringAlgorithmLike[String] with StringFilterLike {
+ final override def compute(charArray: Array[Char]): Option[Array[Char]] = {
+ val fca = filter(charArray)
if (fca.length == 0 || !(fca.head is Alpha)) None
else {
@@ -20,8 +18,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm
}
}
- override def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn] =
- compute(stringFilter.filter(string.toCharArray)).map(_.mkString)
+ final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString)
private[this] def deduplicate(ca: Array[Char]) =
if (ca.length <= 1) ca
@@ -114,3 +111,7 @@ object MetaphoneAlgorithm extends StringAlgorithm with FilterableStringAlgorithm
}
}
}
+
+object MetaphoneAlgorithm {
+ def apply(): MetaphoneAlgorithm = new MetaphoneAlgorithm
+}
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 132fb67..a9d0a3c 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetric.scala
@@ -1,25 +1,27 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
-/** An implementation of the Metaphone [[com.rockymadden.stringmetric.StringMetric]]. */
-object MetaphoneMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Boolean
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** A implementation of Metaphone metric. */
+class MetaphoneMetric extends StringMetricLike[Boolean] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || !(fca1.head is Alpha) || fca2.length == 0 || !(fca2.head is Alpha)) None
- else MetaphoneAlgorithm.compute(fca1).filter(_.length > 0).flatMap(mp1 =>
- MetaphoneAlgorithm.compute(fca2).filter(_.length > 0).map(mp1.sameElements(_)))
+ else {
+ val metaphoneAlgorithm = MetaphoneAlgorithm()
+
+ metaphoneAlgorithm.compute(fca1).filter(_.length > 0).flatMap(mp1 =>
+ metaphoneAlgorithm.compute(fca2).filter(_.length > 0).map(mp1.sameElements(_)))
+ }
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Boolean] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object MetaphoneMetric {
+ def apply(): MetaphoneMetric = new MetaphoneMetric
}
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 8f47bd0..b92bbcd 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithm.scala
@@ -1,15 +1,13 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ StringAlgorithmLike, StringFilterLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
import scala.annotation.{ switch, tailrec }
-/** An implementation of the NYSIIS [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
- type ComputeReturn = String
-
- override def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = {
- val fca = stringFilter.filter(charArray)
+/** An implementation of the NYSIIS algorithm. */
+class NysiisAlgorithm extends StringAlgorithmLike[String] with StringFilterLike {
+ final override def compute(charArray: Array[Char]): Option[Array[Char]] = {
+ val fca = filter(charArray)
if (fca.length == 0 || !(fca.head is Alpha)) None
else {
@@ -29,8 +27,7 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
}
}
- override def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn] =
- compute(stringFilter.filter(string.toCharArray)).map(_.mkString)
+ final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString)
private[this] def cleanLast(ca: Array[Char]) =
if (ca.length == 0) ca
@@ -121,3 +118,7 @@ object NysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
} else (ca, Array.empty[Char])
}
}
+
+object NysiisAlgorithm {
+ def apply(): NysiisAlgorithm = new NysiisAlgorithm
+}
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 7f1ca3f..52b3e80 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/NysiisMetric.scala
@@ -1,15 +1,11 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
-/** An implementation of the NYSIIS [[com.rockymadden.stringmetric.StringMetric]]. */
-object NysiisMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Boolean
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
+/** An implementation of the NYSIIS metric. */
+class NysiisMetric extends StringMetricLike[Boolean] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = {
val unequal = (c1: Char, c2: Char) => {
val lc1 = c1.toLower
val lc2 = c2.toLower
@@ -17,17 +13,23 @@ object NysiisMetric extends StringMetric with FilterableStringMetric {
(if (lc1 == 'k') 'c' else lc1) != (if (lc2 == 'k') 'c' else lc2)
}
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || !(fca1.head is Alpha) || fca2.length == 0 || !(fca2.head is Alpha)) 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(_)))
+ else {
+ val nysiisAlgorithm = NysiisAlgorithm()
+
+ nysiisAlgorithm.compute(fca1).filter(_.length > 0).flatMap(ny1 =>
+ nysiisAlgorithm.compute(fca2).filter(_.length > 0).map(ny1.sameElements(_)))
+ }
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Boolean] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object NysiisMetric {
+ def apply(): NysiisMetric = new NysiisMetric
}
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 8f92768..54ff8be 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithm.scala
@@ -1,15 +1,13 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ StringAlgorithmLike, StringFilterLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
import scala.annotation.{ switch, tailrec }
-/** An implementation of the refined NYSIIS [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object RefinedNysiisAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
- type ComputeReturn = String
-
- override def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = {
- val fca = stringFilter.filter(charArray)
+/** An implementation of the refined NYSIIS algorithm. */
+class RefinedNysiisAlgorithm extends StringAlgorithmLike[String] with StringFilterLike {
+ final override def compute(charArray: Array[Char]): Option[Array[Char]] = {
+ val fca = filter(charArray)
if (fca.length == 0 || !(fca.head is Alpha)) None
else {
@@ -22,8 +20,7 @@ object RefinedNysiisAlgorithm extends StringAlgorithm with FilterableStringAlgor
}
}
- override def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn] =
- compute(stringFilter.filter(string.toCharArray)).map(_.mkString)
+ final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString)
private[this] def cleanLast(ca: Array[Char], s: Set[Char]) =
if (ca.length == 0) ca
@@ -125,3 +122,7 @@ object RefinedNysiisAlgorithm extends StringAlgorithm with FilterableStringAlgor
} else ca
}
}
+
+object RefinedNysiisAlgorithm {
+ def apply(): RefinedNysiisAlgorithm = new RefinedNysiisAlgorithm
+}
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 8bbf474..a1ffcdd 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetric.scala
@@ -1,15 +1,11 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
-/** An implementation of the refined NYSIIS [[com.rockymadden.stringmetric.StringMetric]]. */
-object RefinedNysiisMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Boolean
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
+/** An implementation of the refined NYSIIS metric. */
+class RefinedNysiisMetric extends StringMetricLike[Boolean] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = {
val unequal = (c1: Char, c2: Char) => {
val lc1 = c1.toLower
val lc2 = c2.toLower
@@ -17,17 +13,23 @@ object RefinedNysiisMetric extends StringMetric with FilterableStringMetric {
(if (lc1 == 'k') 'c' else lc1) != (if (lc2 == 'k') 'c' else lc2)
}
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || !(fca1.head is Alpha) || fca2.length == 0 || !(fca2.head is Alpha)) 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(_)))
+ else {
+ val refinedNysiisAlgorithm = RefinedNysiisAlgorithm()
+
+ refinedNysiisAlgorithm.compute(fca1).filter(_.length > 0).flatMap(rny1 =>
+ refinedNysiisAlgorithm.compute(fca2).filter(_.length > 0).map(rny1.sameElements(_)))
+ }
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Boolean] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object RefinedNysiisMetric {
+ def apply(): RefinedNysiisMetric = new RefinedNysiisMetric
}
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 ffb6fc6..3a3deaa 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithm.scala
@@ -1,22 +1,19 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ StringAlgorithmLike, StringFilterLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
import scala.annotation.{ switch, tailrec }
-/** An implementation of the refined Soundex [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object RefinedSoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
- type ComputeReturn = String
-
- override def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = {
- val fca = stringFilter.filter(charArray)
+/** An implementation of the refined Soundex algorithm. */
+class RefinedSoundexAlgorithm extends StringAlgorithmLike[String] with StringFilterLike {
+ final override def compute(charArray: Array[Char]): Option[Array[Char]] = {
+ val fca = filter(charArray)
if (fca.length == 0 || !(fca.head is Alpha)) None
else Some(transcode(fca, Array(fca.head.toLower)))
}
- override def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn] =
- compute(stringFilter.filter(string.toCharArray)).map(_.mkString)
+ final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString)
@tailrec
private[this] def transcode(i: Array[Char], o: Array[Char]): Array[Char] = {
@@ -65,3 +62,7 @@ object RefinedSoundexAlgorithm extends StringAlgorithm with FilterableStringAlgo
}
}
}
+
+object RefinedSoundexAlgorithm {
+ def apply(): RefinedSoundexAlgorithm = new RefinedSoundexAlgorithm
+}
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 eb203a5..dae089a 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetric.scala
@@ -1,26 +1,28 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
-/** An implementation of the refined Soundex [[com.rockymadden.stringmetric.StringMetric]]. */
-object RefinedSoundexMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Boolean
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** An implementation of the refined Soundex metric. */
+class RefinedSoundexMetric extends StringMetricLike[Boolean] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || !(fca1.head is Alpha) || fca2.length == 0 || !(fca2.head is Alpha)) 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(_)))
+ else {
+ val refinedSoundexAlgorithm = RefinedSoundexAlgorithm()
+
+ refinedSoundexAlgorithm.compute(fca1).filter(_.length > 0).flatMap(rse1 =>
+ refinedSoundexAlgorithm.compute(fca2).filter(_.length > 0).map(rse1.sameElements(_)))
+ }
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Boolean] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object RefinedSoundexMetric {
+ def apply(): RefinedSoundexMetric = new RefinedSoundexMetric
}
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 10519f6..f322225 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithm.scala
@@ -1,15 +1,13 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ StringAlgorithmLike, StringFilterLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
import scala.annotation.{ switch, tailrec }
-/** An implementation of the Soundex [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
- type ComputeReturn = String
-
- override def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = {
- val fca = stringFilter.filter(charArray)
+/** An implementation of the Soundex algorithm. */
+class SoundexAlgorithm extends StringAlgorithmLike[String] with StringFilterLike {
+ final override def compute(charArray: Array[Char]): Option[Array[Char]] = {
+ val fca = filter(charArray)
if (fca.length == 0 || !(fca.head is Alpha)) None
else {
@@ -19,8 +17,7 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
}
}
- override def compute(string: String)(implicit stringFilter: StringFilter): Option[ComputeReturn] =
- compute(stringFilter.filter(string.toCharArray)).map(_.mkString)
+ final override def compute(string: String): Option[String] = compute(filter(string.toCharArray)).map(_.mkString)
@tailrec
private[this] def transcode(i: Array[Char], pc: Char, o: Array[Char]): Array[Char] = {
@@ -63,3 +60,7 @@ object SoundexAlgorithm extends StringAlgorithm with FilterableStringAlgorithm {
}
}
}
+
+object SoundexAlgorithm {
+ def apply(): SoundexAlgorithm = new SoundexAlgorithm
+}
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 4ead1f5..bfd0dd5 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/SoundexMetric.scala
@@ -1,26 +1,28 @@
package com.rockymadden.stringmetric.phonetic
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
import com.rockymadden.stringmetric.phonetic.Alphabet._
-/** An implementation of the Soundex [[com.rockymadden.stringmetric.StringMetric]]. */
-object SoundexMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Boolean
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** An implementation of the Soundex metric. */
+class SoundexMetric extends StringMetricLike[Boolean] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || !(fca1.head is Alpha) || fca2.length == 0 || !(fca2.head is Alpha)) 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(_)))
+ else {
+ val soundexAlgorithm = SoundexAlgorithm()
+
+ soundexAlgorithm.compute(fca1).filter(_.length > 0).flatMap(se1 =>
+ soundexAlgorithm.compute(fca2).filter(_.length > 0).map(se1.sameElements(_)))
+ }
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Boolean] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object SoundexMetric {
+ def apply(): SoundexMetric = new SoundexMetric
}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/package.scala b/core/source/core/scala/com/rockymadden/stringmetric/phonetic/package.scala
deleted file mode 100755
index 1a538a6..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/phonetic/package.scala
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Provides phonetic algorithm and metric functionality. */
-package object phonetic {
-
-}
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 14335ef..3beabd8 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetric.scala
@@ -1,37 +1,39 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ FilterableConfigurableStringMetric, MatchTuple, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ ConfigurableStringMetricLike, MatchTuple, StringFilterLike }
/**
- * An implementation of the Dice, and lesser known Sorensen, [[com.rockymadden.stringmetric.StringMetric]]. This
- * implementation differs in that n-gram size is required. Traditionally, the algorithm uses bigrams.
+ * An implementation of the Dice/Sorensen metric. This implementation differs in that n-gram size is required.
+ * Traditionally, the algorithm uses bigrams.
*/
-object DiceSorensenMetric extends StringMetric with FilterableConfigurableStringMetric[Int] {
- type CompareReturn = Double
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
+class DiceSorensenMetric extends ConfigurableStringMetricLike[Double, Int] with StringFilterLike {
+ override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = {
if (n <= 0) throw new IllegalArgumentException("Expected valid n.")
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
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 NGramAlgorithm.compute(fca1)(n).flatMap { ca1bg =>
- NGramAlgorithm.compute(fca2)(n).map { ca2bg =>
- val ms = scoreMatches((ca1bg.map(_.mkString), ca2bg.map(_.mkString)))
+ else {
+ val nGramAlgorithm = NGramAlgorithm()
+
+ nGramAlgorithm.compute(fca1)(n).flatMap { ca1bg =>
+ nGramAlgorithm.compute(fca2)(n).map { ca2bg =>
+ val ms = scoreMatches((ca1bg.map(_.mkString), ca2bg.map(_.mkString)))
- (2d * ms) / (ca1bg.length + ca2bg.length)
+ (2d * ms) / (ca1bg.length + ca2bg.length)
+ }
}
}
}
- override def compare(string1: String, string2: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))(n: Int)
+ override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))(n: Int)
private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length
}
+
+object DiceSorensenMetric {
+ def apply(): DiceSorensenMetric = new DiceSorensenMetric
+}
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 3cd7ad9..d16554b 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/HammingMetric.scala
@@ -1,26 +1,20 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ CompareTuple, FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ CompareTuple, StringFilterLike, StringMetricLike }
-/** An implementation of the Hamming [[com.rockymadden.stringmetric.StringMetric]]. */
-object HammingMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Int
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** An implementation of the Hamming metric. */
+class HammingMetric extends StringMetricLike[Int] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || fca2.length == 0 || fca1.length != fca2.length) None
else if (fca1.sameElements(fca2)) Some(0)
else Some(hamming(fca1, fca2))
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+ final override def compare(string1: String, string2: String): Option[Int] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
private[this] def hamming(ct: CompareTuple[Char]) = {
require(ct._1.length == ct._2.length)
@@ -29,3 +23,7 @@ object HammingMetric extends StringMetric with FilterableStringMetric {
else ct._1.zip(ct._2).count(t => t._1 != t._2)
}
}
+
+object HammingMetric {
+ def apply(): HammingMetric = new HammingMetric
+}
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 d2e5da5..a21bd6e 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroMetric.scala
@@ -1,21 +1,16 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ CompareTuple, FilterableStringMetric, MatchTuple, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ CompareTuple, MatchTuple, StringFilterLike, StringMetricLike }
import scala.collection.mutable.{ ArrayBuffer, HashSet }
/**
- * An implementation of the Jaro [[com.rockymadden.stringmetric.StringMetric]]. 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.
+ * 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.
*/
-object JaroMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Double
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+class JaroMetric extends StringMetricLike[Double] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || fca2.length == 0) None
else if (fca1.sameElements(fca2)) Some(1d)
@@ -32,10 +27,8 @@ object JaroMetric extends StringMetric with FilterableStringMetric {
}
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+ final override def compare(string1: String, string2: String): Option[Double] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
private[this] def `match`(ct: CompareTuple[Char]): MatchTuple[Char] = {
lazy val window = math.abs((math.max(ct._1.length, ct._2.length) / 2d).floor.toInt - 1)
@@ -80,3 +73,7 @@ object JaroMetric extends StringMetric with FilterableStringMetric {
(mt._1.zip(mt._2).count(t => t._1 != t._2) / 2d).floor.toInt
}
}
+
+object JaroMetric {
+ def apply(): JaroMetric = new JaroMetric
+}
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 2f5fae9..4239ed4 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetric.scala
@@ -1,22 +1,18 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ StringFilterLike, StringMetricLike }
/**
- * An implementation of the Jaro-Winkler [[com.rockymadden.stringmetric.StringMetric]]. 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).
+ * 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).
*/
-object JaroWinklerMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Double
+class JaroWinklerMetric extends StringMetricLike[Double] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = {
+ val fca1 = filter(charArray1)
+ val fca2 = filter(charArray2)
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- val fca2 = stringFilter.filter(charArray2)
-
- JaroMetric.compare(fca1, fca2).map(
+ JaroMetric().compare(fca1, fca2).map(
_ match {
case 0d => 0d
case 1d => 1d
@@ -29,8 +25,10 @@ object JaroWinklerMetric extends StringMetric with FilterableStringMetric {
)
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String): Option[Double] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
+}
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+object JaroWinklerMetric {
+ def apply(): JaroWinklerMetric = new JaroWinklerMetric
}
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 53eff53..f7d47b3 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetric.scala
@@ -1,26 +1,20 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ CompareTuple, FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ CompareTuple, StringFilterLike, StringMetricLike }
-/** An implementation of the Levenshtein [[com.rockymadden.stringmetric.StringMetric]]. */
-object LevenshteinMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Int
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** An implementation of the Levenshtein metric. */
+class LevenshteinMetric extends StringMetricLike[Int] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || fca2.length == 0) None
else if (fca1.sameElements(fca2)) Some(0)
else Some(levenshtein(fca1, fca2))
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+ final override def compare(string1: String, string2: String): Option[Int] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
private[this] def levenshtein(ct: CompareTuple[Char]) = {
val m = Array.fill[Int](ct._1.length + 1, ct._2.length + 1)(-1)
@@ -51,3 +45,7 @@ object LevenshteinMetric extends StringMetric with FilterableStringMetric {
distance(ct._1.length, ct._2.length)
}
}
+
+object LevenshteinMetric {
+ def apply(): LevenshteinMetric = new LevenshteinMetric
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala
index 612c852..9f96794 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithm.scala
@@ -1,27 +1,21 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ FilterableConfigurableStringAlgorithm, StringAlgorithm, StringFilter }
+import com.rockymadden.stringmetric.{ ConfigurableStringAlgorithmLike, StringFilterLike }
import scala.annotation.tailrec
-/** An implementation of the N-Gram [[com.rockymadden.stringmetric.StringAlgorithm]]. */
-object NGramAlgorithm extends StringAlgorithm with FilterableConfigurableStringAlgorithm[Int] {
- type ComputeReturn = Array[String]
-
- override def compute(charArray: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[Array[Array[Char]]] = {
-
+/** An implementation of the N-Gram algorithm. */
+class NGramAlgorithm extends ConfigurableStringAlgorithmLike[Array[String], Int] with StringFilterLike {
+ final override def compute(charArray: Array[Char])(implicit n: Int): Option[Array[Array[Char]]] = {
if (n <= 0) throw new IllegalArgumentException("Expected valid n.")
- val fca = stringFilter.filter(charArray)
+ val fca = filter(charArray)
if (fca.length < n) None
else Some(sequence(fca, Array.empty[Array[Char]], n))
}
- override def compute(string: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[ComputeReturn] =
-
- compute(stringFilter.filter(string.toCharArray))(n).map(_.map(_.mkString))
+ final override def compute(string: String)(implicit n: Int): Option[Array[String]] =
+ compute(filter(string.toCharArray))(n).map(_.map(_.mkString))
@tailrec
private[this] def sequence(i: Array[Char], o: Array[Array[Char]], n: Int): Array[Array[Char]] = {
@@ -30,4 +24,8 @@ object NGramAlgorithm extends StringAlgorithm with FilterableConfigurableStringA
if (i.length <= n) o :+ i
else sequence(i.tail, o :+ i.take(n), n)
}
-} \ No newline at end of file
+}
+
+object NGramAlgorithm {
+ def apply(): NGramAlgorithm = new NGramAlgorithm
+}
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 72e4d4b..362c06c 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/NGramMetric.scala
@@ -1,35 +1,37 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ FilterableConfigurableStringMetric, MatchTuple, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ ConfigurableStringMetricLike, MatchTuple, StringFilterLike }
import scala.math
-/** An implementation of the N-Gram [[com.rockymadden.stringmetric.StringMetric]]. */
-object NGramMetric extends StringMetric with FilterableConfigurableStringMetric[Int] {
- type CompareReturn = Double
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])(n: Int)
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
+/** An implementation of the N-Gram metric. */
+class NGramMetric extends ConfigurableStringMetricLike[Double, Int] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit n: Int): Option[Double] = {
if (n <= 0) throw new IllegalArgumentException("Expected valid n.")
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
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 NGramAlgorithm.compute(fca1)(n).flatMap { ca1bg =>
- NGramAlgorithm.compute(fca2)(n).map { ca2bg =>
- val ms = scoreMatches((ca1bg.map(_.mkString), ca2bg.map(_.mkString)))
+ else {
+ val nGramAlgorithm = NGramAlgorithm()
+
+ nGramAlgorithm.compute(fca1)(n).flatMap { ca1bg =>
+ nGramAlgorithm.compute(fca2)(n).map { ca2bg =>
+ val ms = scoreMatches((ca1bg.map(_.mkString), ca2bg.map(_.mkString)))
- ms.toDouble / math.max(ca1bg.length, ca2bg.length)
+ ms.toDouble / math.max(ca1bg.length, ca2bg.length)
+ }
}
}
}
- override def compare(string1: String, string2: String)(n: Int)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))(n)
+ final override def compare(string1: String, string2: String)(implicit n: Int): Option[Double] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))(n)
private[this] def scoreMatches(mt: MatchTuple[String]) = mt._1.intersect(mt._2).length
}
+
+object NGramMetric {
+ def apply(): NGramMetric = new NGramMetric
+}
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 96e8c39..23959b8 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetric.scala
@@ -1,26 +1,20 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ CompareTuple, FilterableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ CompareTuple, StringFilterLike, StringMetricLike }
-/** An implementation of the Ratcliff/Obershelp [[com.rockymadden.stringmetric.StringMetric]]. */
-object RatcliffObershelpMetric extends StringMetric with FilterableStringMetric {
- type CompareReturn = Double
-
- override def compare(charArray1: Array[Char], charArray2: Array[Char])
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
-
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+/** An implementation of the Ratcliff/Obershelp metric. */
+class RatcliffObershelpMetric extends StringMetricLike[Double] with StringFilterLike {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = {
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
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))
}
- override def compare(string1: String, string2: String)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
-
- compare(stringFilter.filter(string1.toCharArray), stringFilter.filter(string2.toCharArray))
+ final override def compare(string1: String, string2: String): Option[Double] =
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))
private[this] def longestCommonSubsequence(ct: CompareTuple[Char]) = {
val m = Array.ofDim[Int](ct._1.length + 1, ct._2.length + 1)
@@ -49,3 +43,7 @@ object RatcliffObershelpMetric extends StringMetric with FilterableStringMetric
}
}
}
+
+object RatcliffObershelpMetric {
+ def apply(): RatcliffObershelpMetric = new RatcliffObershelpMetric
+}
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 79060e5..05f8c82 100755
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala
+++ b/core/source/core/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetric.scala
@@ -1,24 +1,21 @@
package com.rockymadden.stringmetric.similarity
-import com.rockymadden.stringmetric.{ CompareTuple, FilterableConfigurableStringMetric, StringFilter, StringMetric }
+import com.rockymadden.stringmetric.{ CompareTuple, ConfigurableStringMetricLike, StringFilterLike }
import scala.math.BigDecimal
-/** An implementation of a weighted Levenshtein [[com.rockymadden.stringmetric.StringMetric]]. */
-object WeightedLevenshteinMetric
- extends StringMetric with FilterableConfigurableStringMetric[(BigDecimal, BigDecimal, BigDecimal)] {
-
- type CompareReturn = Double
- type Options = (BigDecimal, BigDecimal, BigDecimal)
+/** An implementation of a weighted Levenshtein metric. */
+class WeightedLevenshteinMetric
+ extends ConfigurableStringMetricLike[Double, (BigDecimal, BigDecimal, BigDecimal)] with StringFilterLike {
/** Options order is delete, insert, then substitute weight. */
- override def compare(charArray1: Array[Char], charArray2: Array[Char])(options: Options)
- (implicit stringFilter: StringFilter): Option[CompareReturn] = {
+ final override def compare(charArray1: Array[Char], charArray2: Array[Char])
+ (implicit options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] = {
if (options._1 < 0 || options._2 < 0 || options._3 < 0)
throw new IllegalArgumentException("Expected valid weight options.")
- val fca1 = stringFilter.filter(charArray1)
- lazy val fca2 = stringFilter.filter(charArray2)
+ val fca1 = filter(charArray1)
+ lazy val fca2 = filter(charArray2)
if (fca1.length == 0 || fca2.length == 0) None
else if (fca1.sameElements(fca2)) Some(0d)
@@ -26,12 +23,12 @@ object WeightedLevenshteinMetric
}
/** Options order is delete, insert, then substitute weight. */
- override def compare(string1: String, string2: String)(options: Options)
- (implicit stringFilter: StringFilter): Option[CompareReturn] =
+ final override def compare(string1: String, string2: String)
+ (implicit options: (BigDecimal, BigDecimal, BigDecimal)): Option[Double] =
- compare(stringFilter.filter(string1.toCharArray),stringFilter.filter(string2.toCharArray))(options)
+ compare(filter(string1.toCharArray), filter(string2.toCharArray))(options)
- private[this] def weightedLevenshtein(ct: CompareTuple[Char], w: Options) = {
+ private[this] def weightedLevenshtein(ct: CompareTuple[Char], w: (BigDecimal, BigDecimal, BigDecimal)) = {
val m = Array.ofDim[BigDecimal](ct._1.length + 1, ct._2.length + 1)
for (r <- 0 to ct._1.length) m(r)(0) = w._1 * r
@@ -51,3 +48,7 @@ object WeightedLevenshteinMetric
m(ct._1.length)(ct._2.length)
}
}
+
+object WeightedLevenshteinMetric {
+ def apply(): WeightedLevenshteinMetric = new WeightedLevenshteinMetric
+}
diff --git a/core/source/core/scala/com/rockymadden/stringmetric/similarity/package.scala b/core/source/core/scala/com/rockymadden/stringmetric/similarity/package.scala
deleted file mode 100755
index 49a73da..0000000
--- a/core/source/core/scala/com/rockymadden/stringmetric/similarity/package.scala
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.rockymadden.stringmetric
-
-/** Provides similarity algorithm and metric functionality. */
-package object similarity {
-
-}
diff --git a/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala
new file mode 100755
index 0000000..1cca109
--- /dev/null
+++ b/core/source/test/scala/com/rockymadden/stringmetric/FilterDecoratedSpec.scala
@@ -0,0 +1,38 @@
+package com.rockymadden.stringmetric
+
+import com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm
+import com.rockymadden.stringmetric.similarity.DiceSorensenMetric
+import com.rockymadden.stringmetric.filter.AsciiNumberStringFilter
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+final class FilterDecoratedSpec extends ScalaTest {
+ import FilterDecoratedSpec._
+
+ "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 AsciiNumberStringFilter
+ private final val Metric = new DiceSorensenMetric with AsciiNumberStringFilter
+}
diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala
index a1210c0..132156b 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala
@@ -8,7 +8,7 @@ import org.scalatest.junit.JUnitRunner
final class StringFilterDelegateSpec extends ScalaTest {
import StringFilterDelegateSpec.Filter
- "StringFilterDelegate" should provide {
+ "StringFilter" should provide {
"overloaded filter method" when passed {
"String" should returns {
"the same String" in {
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 b6af492..288bd60 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala
@@ -6,208 +6,214 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class MetaphoneAlgorithmSpec extends ScalaTest {
+ import MetaphoneAlgorithmSpec._
+
"MetaphoneAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- MetaphoneAlgorithm.compute("").isDefined should be (false)
+ Algorithm.compute("").isDefined should be (false)
}
}
"non-phonetic argument" should returns {
"None" in {
- MetaphoneAlgorithm.compute("123").isDefined should be (false)
+ Algorithm.compute("123").isDefined should be (false)
}
}
"phonetic argument" should returns {
"Some" in {
// z
- MetaphoneAlgorithm.compute("z").get should equal ("s")
- MetaphoneAlgorithm.compute("zz").get should equal ("s")
+ Algorithm.compute("z").get should equal ("s")
+ Algorithm.compute("zz").get should equal ("s")
// y
- 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")
+ 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")
// x
- MetaphoneAlgorithm.compute("x").get should equal ("s")
- MetaphoneAlgorithm.compute("zx").get should equal ("sks")
- MetaphoneAlgorithm.compute("zxz").get should equal ("skss")
+ Algorithm.compute("x").get should equal ("s")
+ Algorithm.compute("zx").get should equal ("sks")
+ Algorithm.compute("zxz").get should equal ("skss")
// w
- 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")
+ 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")
// v
- MetaphoneAlgorithm.compute("v").get should equal ("f")
- MetaphoneAlgorithm.compute("zv").get should equal ("sf")
- MetaphoneAlgorithm.compute("zvz").get should equal ("sfs")
+ Algorithm.compute("v").get should equal ("f")
+ Algorithm.compute("zv").get should equal ("sf")
+ Algorithm.compute("zvz").get should equal ("sfs")
// u
- MetaphoneAlgorithm.compute("u").get should equal ("u")
- MetaphoneAlgorithm.compute("zu").get should equal ("s")
+ Algorithm.compute("u").get should equal ("u")
+ Algorithm.compute("zu").get should equal ("s")
// t
- 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")
+ 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")
// s
- 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")
+ 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")
// r
- MetaphoneAlgorithm.compute("r").get should equal ("r")
- MetaphoneAlgorithm.compute("zr").get should equal ("sr")
- MetaphoneAlgorithm.compute("zrz").get should equal ("srs")
+ Algorithm.compute("r").get should equal ("r")
+ Algorithm.compute("zr").get should equal ("sr")
+ Algorithm.compute("zrz").get should equal ("srs")
// q
- MetaphoneAlgorithm.compute("q").get should equal ("k")
- MetaphoneAlgorithm.compute("zq").get should equal ("sk")
- MetaphoneAlgorithm.compute("zqz").get should equal ("sks")
+ Algorithm.compute("q").get should equal ("k")
+ Algorithm.compute("zq").get should equal ("sk")
+ Algorithm.compute("zqz").get should equal ("sks")
// p
- 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")
+ 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")
// o
- MetaphoneAlgorithm.compute("o").get should equal ("o")
- MetaphoneAlgorithm.compute("zo").get should equal ("s")
+ Algorithm.compute("o").get should equal ("o")
+ Algorithm.compute("zo").get should equal ("s")
// n
- MetaphoneAlgorithm.compute("n").get should equal ("n")
- MetaphoneAlgorithm.compute("zn").get should equal ("sn")
- MetaphoneAlgorithm.compute("znz").get should equal ("sns")
+ Algorithm.compute("n").get should equal ("n")
+ Algorithm.compute("zn").get should equal ("sn")
+ Algorithm.compute("znz").get should equal ("sns")
// m
- MetaphoneAlgorithm.compute("m").get should equal ("m")
- MetaphoneAlgorithm.compute("zm").get should equal ("sm")
- MetaphoneAlgorithm.compute("zmz").get should equal ("sms")
+ Algorithm.compute("m").get should equal ("m")
+ Algorithm.compute("zm").get should equal ("sm")
+ Algorithm.compute("zmz").get should equal ("sms")
// l
- MetaphoneAlgorithm.compute("l").get should equal ("l")
- MetaphoneAlgorithm.compute("zl").get should equal ("sl")
- MetaphoneAlgorithm.compute("zlz").get should equal ("sls")
+ Algorithm.compute("l").get should equal ("l")
+ Algorithm.compute("zl").get should equal ("sl")
+ Algorithm.compute("zlz").get should equal ("sls")
// k
- MetaphoneAlgorithm.compute("k").get should equal ("k")
- MetaphoneAlgorithm.compute("zk").get should equal ("sk")
- MetaphoneAlgorithm.compute("zck").get should equal ("sk")
+ Algorithm.compute("k").get should equal ("k")
+ Algorithm.compute("zk").get should equal ("sk")
+ Algorithm.compute("zck").get should equal ("sk")
// j
- MetaphoneAlgorithm.compute("j").get should equal ("j")
- MetaphoneAlgorithm.compute("zj").get should equal ("sj")
- MetaphoneAlgorithm.compute("zjz").get should equal ("sjs")
+ Algorithm.compute("j").get should equal ("j")
+ Algorithm.compute("zj").get should equal ("sj")
+ Algorithm.compute("zjz").get should equal ("sjs")
// i
- MetaphoneAlgorithm.compute("i").get should equal ("i")
- MetaphoneAlgorithm.compute("zi").get should equal ("s")
+ Algorithm.compute("i").get should equal ("i")
+ Algorithm.compute("zi").get should equal ("s")
// 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")
+ 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")
// g
- 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")
+ 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")
// f
- MetaphoneAlgorithm.compute("f").get should equal ("f")
- MetaphoneAlgorithm.compute("zf").get should equal ("sf")
- MetaphoneAlgorithm.compute("zfz").get should equal ("sfs")
+ Algorithm.compute("f").get should equal ("f")
+ Algorithm.compute("zf").get should equal ("sf")
+ Algorithm.compute("zfz").get should equal ("sfs")
// e
- MetaphoneAlgorithm.compute("e").get should equal ("e")
- MetaphoneAlgorithm.compute("ze").get should equal ("s")
+ Algorithm.compute("e").get should equal ("e")
+ Algorithm.compute("ze").get should equal ("s")
// d
- 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")
+ 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")
// c
- 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")
+ 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")
// b
- 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")
+ 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")
// a
- MetaphoneAlgorithm.compute("a").get should equal ("a")
- MetaphoneAlgorithm.compute("za").get should equal ("s")
+ Algorithm.compute("a").get should equal ("a")
+ Algorithm.compute("za").get should equal ("s")
// Miscellaneous.
- 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")
+ 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")
}
}
}
}
-} \ No newline at end of file
+}
+
+object MetaphoneAlgorithmSpec {
+ final private val Algorithm = new 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 93de46e..36382ba 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala
@@ -6,36 +6,42 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class MetaphoneMetricSpec extends ScalaTest {
+ import MetaphoneMetricSpec._
+
"MetaphoneMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- MetaphoneMetric.compare("", "").isDefined should be (false)
- MetaphoneMetric.compare("abc", "").isDefined should be (false)
- MetaphoneMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"non-phonetic arguments" should returns {
"None" in {
- MetaphoneMetric.compare("123", "123").isDefined should be (false)
- MetaphoneMetric.compare("123", "").isDefined should be (false)
- MetaphoneMetric.compare("", "123").isDefined should be (false)
+ Metric.compare("123", "123").isDefined should be (false)
+ Metric.compare("123", "").isDefined should be (false)
+ Metric.compare("", "123").isDefined should be (false)
}
}
"phonetically similar arguments" should returns {
"Boolean indicating true" in {
- MetaphoneMetric.compare("dumb", "dum").get should be (true)
- MetaphoneMetric.compare("smith", "smeth").get should be (true)
- MetaphoneMetric.compare("merci", "mercy").get should be (true)
+ Metric.compare("dumb", "dum").get should be (true)
+ Metric.compare("smith", "smeth").get should be (true)
+ Metric.compare("merci", "mercy").get should be (true)
}
}
"phonetically dissimilar arguments" should returns {
"Boolean indicating false" in {
- MetaphoneMetric.compare("dumb", "gum").get should be (false)
- MetaphoneMetric.compare("smith", "kiss").get should be (false)
- MetaphoneMetric.compare("merci", "burpy").get should be (false)
+ Metric.compare("dumb", "gum").get should be (false)
+ Metric.compare("smith", "kiss").get should be (false)
+ Metric.compare("merci", "burpy").get should be (false)
}
}
}
}
-} \ No newline at end of file
+}
+
+object MetaphoneMetricSpec {
+ final private val Metric = new 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 d2af38f..d6c15a8 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala
@@ -6,186 +6,192 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class NysiisAlgorithmSpec extends ScalaTest {
+ import NysiisAlgorithmSpec._
+
"NysiisAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- NysiisAlgorithm.compute("").isDefined should be (false)
+ Algorithm.compute("").isDefined should be (false)
}
}
"non-phonetic argument" should returns {
"None" in {
- NysiisAlgorithm.compute("123").isDefined should be (false)
+ Algorithm.compute("123").isDefined should be (false)
}
}
"phonetic argument" should returns {
"Some" in {
// a
- NysiisAlgorithm.compute("a").get should equal ("a")
- NysiisAlgorithm.compute("aa").get should equal ("a")
+ Algorithm.compute("a").get should equal ("a")
+ Algorithm.compute("aa").get should equal ("a")
// b
- NysiisAlgorithm.compute("b").get should equal ("b")
- NysiisAlgorithm.compute("bb").get should equal ("bb")
+ Algorithm.compute("b").get should equal ("b")
+ Algorithm.compute("bb").get should equal ("bb")
// c
- NysiisAlgorithm.compute("c").get should equal ("c")
- NysiisAlgorithm.compute("cc").get should equal ("cc")
+ Algorithm.compute("c").get should equal ("c")
+ Algorithm.compute("cc").get should equal ("cc")
// d
- NysiisAlgorithm.compute("d").get should equal ("d")
- NysiisAlgorithm.compute("dd").get should equal ("dd")
+ Algorithm.compute("d").get should equal ("d")
+ Algorithm.compute("dd").get should equal ("dd")
// e
- NysiisAlgorithm.compute("e").get should equal ("e")
- NysiisAlgorithm.compute("ee").get should equal ("y")
+ Algorithm.compute("e").get should equal ("e")
+ Algorithm.compute("ee").get should equal ("y")
// f
- NysiisAlgorithm.compute("f").get should equal ("f")
- NysiisAlgorithm.compute("ff").get should equal ("ff")
+ Algorithm.compute("f").get should equal ("f")
+ Algorithm.compute("ff").get should equal ("ff")
// g
- NysiisAlgorithm.compute("g").get should equal ("g")
- NysiisAlgorithm.compute("gg").get should equal ("gg")
+ Algorithm.compute("g").get should equal ("g")
+ Algorithm.compute("gg").get should equal ("gg")
// h
- NysiisAlgorithm.compute("h").get should equal ("h")
- NysiisAlgorithm.compute("hh").get should equal ("hh")
+ Algorithm.compute("h").get should equal ("h")
+ Algorithm.compute("hh").get should equal ("hh")
// i
- NysiisAlgorithm.compute("i").get should equal ("i")
- NysiisAlgorithm.compute("ii").get should equal ("i")
+ Algorithm.compute("i").get should equal ("i")
+ Algorithm.compute("ii").get should equal ("i")
// j
- NysiisAlgorithm.compute("j").get should equal ("j")
- NysiisAlgorithm.compute("jj").get should equal ("jj")
+ Algorithm.compute("j").get should equal ("j")
+ Algorithm.compute("jj").get should equal ("jj")
// k
- NysiisAlgorithm.compute("k").get should equal ("c")
- NysiisAlgorithm.compute("kk").get should equal ("cc")
+ Algorithm.compute("k").get should equal ("c")
+ Algorithm.compute("kk").get should equal ("cc")
// l
- NysiisAlgorithm.compute("l").get should equal ("l")
- NysiisAlgorithm.compute("ll").get should equal ("ll")
+ Algorithm.compute("l").get should equal ("l")
+ Algorithm.compute("ll").get should equal ("ll")
// m
- NysiisAlgorithm.compute("m").get should equal ("m")
- NysiisAlgorithm.compute("mm").get should equal ("mn")
+ Algorithm.compute("m").get should equal ("m")
+ Algorithm.compute("mm").get should equal ("mn")
// n
- NysiisAlgorithm.compute("n").get should equal ("n")
- NysiisAlgorithm.compute("nn").get should equal ("nn")
+ Algorithm.compute("n").get should equal ("n")
+ Algorithm.compute("nn").get should equal ("nn")
// o
- NysiisAlgorithm.compute("o").get should equal ("o")
- NysiisAlgorithm.compute("oo").get should equal ("o")
+ Algorithm.compute("o").get should equal ("o")
+ Algorithm.compute("oo").get should equal ("o")
// p
- NysiisAlgorithm.compute("p").get should equal ("p")
- NysiisAlgorithm.compute("pp").get should equal ("pp")
+ Algorithm.compute("p").get should equal ("p")
+ Algorithm.compute("pp").get should equal ("pp")
// q
- NysiisAlgorithm.compute("q").get should equal ("q")
- NysiisAlgorithm.compute("qq").get should equal ("qg")
+ Algorithm.compute("q").get should equal ("q")
+ Algorithm.compute("qq").get should equal ("qg")
// r
- NysiisAlgorithm.compute("r").get should equal ("r")
- NysiisAlgorithm.compute("rr").get should equal ("rr")
+ Algorithm.compute("r").get should equal ("r")
+ Algorithm.compute("rr").get should equal ("rr")
// s
- NysiisAlgorithm.compute("s").get should equal ("s")
- NysiisAlgorithm.compute("ss").get should equal ("s")
+ Algorithm.compute("s").get should equal ("s")
+ Algorithm.compute("ss").get should equal ("s")
// t
- NysiisAlgorithm.compute("t").get should equal ("t")
- NysiisAlgorithm.compute("tt").get should equal ("tt")
+ Algorithm.compute("t").get should equal ("t")
+ Algorithm.compute("tt").get should equal ("tt")
// u
- NysiisAlgorithm.compute("u").get should equal ("u")
- NysiisAlgorithm.compute("uu").get should equal ("u")
+ Algorithm.compute("u").get should equal ("u")
+ Algorithm.compute("uu").get should equal ("u")
// v
- NysiisAlgorithm.compute("v").get should equal ("v")
- NysiisAlgorithm.compute("vv").get should equal ("vv")
+ Algorithm.compute("v").get should equal ("v")
+ Algorithm.compute("vv").get should equal ("vv")
// w
- NysiisAlgorithm.compute("w").get should equal ("w")
- NysiisAlgorithm.compute("ww").get should equal ("ww")
+ Algorithm.compute("w").get should equal ("w")
+ Algorithm.compute("ww").get should equal ("ww")
// x
- NysiisAlgorithm.compute("x").get should equal ("x")
- NysiisAlgorithm.compute("xx").get should equal ("xx")
+ Algorithm.compute("x").get should equal ("x")
+ Algorithm.compute("xx").get should equal ("xx")
// y
- NysiisAlgorithm.compute("y").get should equal ("y")
- NysiisAlgorithm.compute("yy").get should equal ("yy")
+ Algorithm.compute("y").get should equal ("y")
+ Algorithm.compute("yy").get should equal ("yy")
// z
- NysiisAlgorithm.compute("z").get should equal ("z")
- NysiisAlgorithm.compute("zz").get should equal ("z")
+ Algorithm.compute("z").get should equal ("z")
+ Algorithm.compute("zz").get should equal ("z")
// Head cases.
- 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
+ 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
// Last cases.
- 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")
+ 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")
// Core cases.
- 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")
+ 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")
// Miscellaneous.
- 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")
+ 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")
// Dropby.
- 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")
+ 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")
}
}
}
}
-} \ No newline at end of file
+}
+
+object NysiisAlgorithmSpec {
+ final private val Algorithm = new 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 3e53211..a4ad219 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala
@@ -6,32 +6,38 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class NysiisMetricSpec extends ScalaTest {
+ import NysiisMetricSpec._
+
"NysiisMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- NysiisMetric.compare("", "").isDefined should be (false)
- NysiisMetric.compare("abc", "").isDefined should be (false)
- NysiisMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"non-phonetic arguments" should returns {
"None" in {
- NysiisMetric.compare("123", "123").isDefined should be (false)
- NysiisMetric.compare("123", "").isDefined should be (false)
- NysiisMetric.compare("", "123").isDefined should be (false)
+ Metric.compare("123", "123").isDefined should be (false)
+ Metric.compare("123", "").isDefined should be (false)
+ Metric.compare("", "123").isDefined should be (false)
}
}
"phonetically similar arguments" should returns {
"Boolean indicating true" in {
- NysiisMetric.compare("ham", "hum").get should be (true)
+ Metric.compare("ham", "hum").get should be (true)
}
}
"phonetically dissimilar arguments" should returns {
"Boolean indicating false" in {
- NysiisMetric.compare("dumb", "gum").get should be (false)
+ Metric.compare("dumb", "gum").get should be (false)
}
}
}
}
-} \ No newline at end of file
+}
+
+object NysiisMetricSpec {
+ final private val Metric = new 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 fce2811..d384149 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala
@@ -6,203 +6,209 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class RefinedNysiisAlgorithmSpec extends ScalaTest {
+ import RefinedNysiisAlgorithmSpec._
+
"RefinedNysiisAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- RefinedNysiisAlgorithm.compute("").isDefined should be (false)
+ Algorithm.compute("").isDefined should be (false)
}
}
"non-phonetic argument" should returns {
"None" in {
- RefinedNysiisAlgorithm.compute("123").isDefined should be (false)
+ Algorithm.compute("123").isDefined should be (false)
}
}
"phonetic argument" should returns {
"Some" in {
// a
- RefinedNysiisAlgorithm.compute("a").get should equal ("a")
- RefinedNysiisAlgorithm.compute("aa").get should equal ("a")
+ Algorithm.compute("a").get should equal ("a")
+ Algorithm.compute("aa").get should equal ("a")
// b
- RefinedNysiisAlgorithm.compute("b").get should equal ("b")
- RefinedNysiisAlgorithm.compute("bb").get should equal ("b")
+ Algorithm.compute("b").get should equal ("b")
+ Algorithm.compute("bb").get should equal ("b")
// c
- RefinedNysiisAlgorithm.compute("c").get should equal ("c")
- RefinedNysiisAlgorithm.compute("cc").get should equal ("c")
+ Algorithm.compute("c").get should equal ("c")
+ Algorithm.compute("cc").get should equal ("c")
// d
- RefinedNysiisAlgorithm.compute("d").get should equal ("d")
- RefinedNysiisAlgorithm.compute("dd").get should equal ("d")
+ Algorithm.compute("d").get should equal ("d")
+ Algorithm.compute("dd").get should equal ("d")
// e
- RefinedNysiisAlgorithm.compute("e").get should equal ("e")
- RefinedNysiisAlgorithm.compute("ee").get should equal ("y")
+ Algorithm.compute("e").get should equal ("e")
+ Algorithm.compute("ee").get should equal ("y")
// f
- RefinedNysiisAlgorithm.compute("f").get should equal ("f")
- RefinedNysiisAlgorithm.compute("ff").get should equal ("f")
+ Algorithm.compute("f").get should equal ("f")
+ Algorithm.compute("ff").get should equal ("f")
// g
- RefinedNysiisAlgorithm.compute("g").get should equal ("g")
- RefinedNysiisAlgorithm.compute("gg").get should equal ("g")
+ Algorithm.compute("g").get should equal ("g")
+ Algorithm.compute("gg").get should equal ("g")
// h
- RefinedNysiisAlgorithm.compute("h").get should equal ("h")
- RefinedNysiisAlgorithm.compute("hh").get should equal ("h")
+ Algorithm.compute("h").get should equal ("h")
+ Algorithm.compute("hh").get should equal ("h")
// i
- RefinedNysiisAlgorithm.compute("i").get should equal ("i")
- RefinedNysiisAlgorithm.compute("ii").get should equal ("i")
+ Algorithm.compute("i").get should equal ("i")
+ Algorithm.compute("ii").get should equal ("i")
// j
- RefinedNysiisAlgorithm.compute("j").get should equal ("j")
- RefinedNysiisAlgorithm.compute("jj").get should equal ("j")
+ Algorithm.compute("j").get should equal ("j")
+ Algorithm.compute("jj").get should equal ("j")
// k
- RefinedNysiisAlgorithm.compute("k").get should equal ("c")
- RefinedNysiisAlgorithm.compute("kk").get should equal ("c")
+ Algorithm.compute("k").get should equal ("c")
+ Algorithm.compute("kk").get should equal ("c")
// l
- RefinedNysiisAlgorithm.compute("l").get should equal ("l")
- RefinedNysiisAlgorithm.compute("ll").get should equal ("l")
+ Algorithm.compute("l").get should equal ("l")
+ Algorithm.compute("ll").get should equal ("l")
// m
- RefinedNysiisAlgorithm.compute("m").get should equal ("m")
- RefinedNysiisAlgorithm.compute("mm").get should equal ("mn")
+ Algorithm.compute("m").get should equal ("m")
+ Algorithm.compute("mm").get should equal ("mn")
// n
- RefinedNysiisAlgorithm.compute("n").get should equal ("n")
- RefinedNysiisAlgorithm.compute("nn").get should equal ("n")
+ Algorithm.compute("n").get should equal ("n")
+ Algorithm.compute("nn").get should equal ("n")
// o
- RefinedNysiisAlgorithm.compute("o").get should equal ("o")
- RefinedNysiisAlgorithm.compute("oo").get should equal ("o")
+ Algorithm.compute("o").get should equal ("o")
+ Algorithm.compute("oo").get should equal ("o")
// p
- RefinedNysiisAlgorithm.compute("p").get should equal ("p")
- RefinedNysiisAlgorithm.compute("pp").get should equal ("p")
+ Algorithm.compute("p").get should equal ("p")
+ Algorithm.compute("pp").get should equal ("p")
// q
- RefinedNysiisAlgorithm.compute("q").get should equal ("q")
- RefinedNysiisAlgorithm.compute("qq").get should equal ("qg")
+ Algorithm.compute("q").get should equal ("q")
+ Algorithm.compute("qq").get should equal ("qg")
// r
- RefinedNysiisAlgorithm.compute("r").get should equal ("r")
- RefinedNysiisAlgorithm.compute("rr").get should equal ("r")
+ Algorithm.compute("r").get should equal ("r")
+ Algorithm.compute("rr").get should equal ("r")
// s
- RefinedNysiisAlgorithm.compute("s").get should equal ("s")
- RefinedNysiisAlgorithm.compute("ss").get should equal ("s")
+ Algorithm.compute("s").get should equal ("s")
+ Algorithm.compute("ss").get should equal ("s")
// t
- RefinedNysiisAlgorithm.compute("t").get should equal ("t")
- RefinedNysiisAlgorithm.compute("tt").get should equal ("t")
+ Algorithm.compute("t").get should equal ("t")
+ Algorithm.compute("tt").get should equal ("t")
// u
- RefinedNysiisAlgorithm.compute("u").get should equal ("u")
- RefinedNysiisAlgorithm.compute("uu").get should equal ("u")
+ Algorithm.compute("u").get should equal ("u")
+ Algorithm.compute("uu").get should equal ("u")
// v
- RefinedNysiisAlgorithm.compute("v").get should equal ("v")
- RefinedNysiisAlgorithm.compute("vv").get should equal ("v")
+ Algorithm.compute("v").get should equal ("v")
+ Algorithm.compute("vv").get should equal ("v")
// w
- RefinedNysiisAlgorithm.compute("w").get should equal ("w")
- RefinedNysiisAlgorithm.compute("ww").get should equal ("w")
+ Algorithm.compute("w").get should equal ("w")
+ Algorithm.compute("ww").get should equal ("w")
// x
- RefinedNysiisAlgorithm.compute("x").get should equal ("x")
- RefinedNysiisAlgorithm.compute("xx").get should equal ("x")
+ Algorithm.compute("x").get should equal ("x")
+ Algorithm.compute("xx").get should equal ("x")
// y
- RefinedNysiisAlgorithm.compute("y").get should equal ("y")
- RefinedNysiisAlgorithm.compute("yy").get should equal ("y")
- RefinedNysiisAlgorithm.compute("ybyb").get should equal ("ybab")
+ Algorithm.compute("y").get should equal ("y")
+ Algorithm.compute("yy").get should equal ("y")
+ Algorithm.compute("ybyb").get should equal ("ybab")
// z
- RefinedNysiisAlgorithm.compute("z").get should equal ("z")
- RefinedNysiisAlgorithm.compute("zz").get should equal ("z")
+ Algorithm.compute("z").get should equal ("z")
+ Algorithm.compute("zz").get should equal ("z")
// Head cases.
- RefinedNysiisAlgorithm.compute("mac").get should equal ("mc")
- RefinedNysiisAlgorithm.compute("pf").get should equal ("f")
+ Algorithm.compute("mac").get should equal ("mc")
+ Algorithm.compute("pf").get should equal ("f")
// Last cases.
- 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")
+ 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")
// Core cases.
- 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")
+ 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")
// Transcode cases.
- RefinedNysiisAlgorithm.compute("bay").get should equal ("by")
+ Algorithm.compute("bay").get should equal ("by")
// Miscellaneous.
- 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")
+ 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")
// Dropby.
- 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")
+ 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")
}
}
}
}
-} \ No newline at end of file
+}
+
+object RefinedNysiisAlgorithmSpec {
+ final private val Algorithm = new 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 46b177b..59305b6 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala
@@ -6,32 +6,38 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class RefinedNysiisMetricSpec extends ScalaTest {
+ import RefinedNysiisMetricSpec._
+
"RefinedNysiisMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- RefinedNysiisMetric.compare("", "").isDefined should be (false)
- RefinedNysiisMetric.compare("abc", "").isDefined should be (false)
- RefinedNysiisMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"non-phonetic arguments" should returns {
"None" in {
- RefinedNysiisMetric.compare("123", "123").isDefined should be (false)
- RefinedNysiisMetric.compare("123", "").isDefined should be (false)
- RefinedNysiisMetric.compare("", "123").isDefined should be (false)
+ Metric.compare("123", "123").isDefined should be (false)
+ Metric.compare("123", "").isDefined should be (false)
+ Metric.compare("", "123").isDefined should be (false)
}
}
"phonetically similar arguments" should returns {
"Boolean indicating true" in {
- RefinedNysiisMetric.compare("ham", "hum").get should be (true)
+ Metric.compare("ham", "hum").get should be (true)
}
}
"phonetically dissimilar arguments" should returns {
"Boolean indicating false" in {
- RefinedNysiisMetric.compare("dumb", "gum").get should be (false)
+ Metric.compare("dumb", "gum").get should be (false)
}
}
}
}
-} \ No newline at end of file
+}
+
+object RefinedNysiisMetricSpec {
+ final private val Metric = new 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 57e32cf..e52365c 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala
@@ -6,157 +6,163 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class RefinedSoundexAlgorithmSpec extends ScalaTest {
+ import RefinedSoundexAlgorithmSpec._
+
"RefinedSoundexAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- RefinedSoundexAlgorithm.compute("").isDefined should be (false)
+ Algorithm.compute("").isDefined should be (false)
}
}
"non-phonetic argument" should returns {
"None" in {
- RefinedSoundexAlgorithm.compute("123").isDefined should be (false)
+ Algorithm.compute("123").isDefined should be (false)
}
}
"phonetic argument" should returns {
"Some" in {
// a
- RefinedSoundexAlgorithm.compute("a").get should equal ("a0")
- RefinedSoundexAlgorithm.compute("aa").get should equal ("a0")
+ Algorithm.compute("a").get should equal ("a0")
+ Algorithm.compute("aa").get should equal ("a0")
// b
- RefinedSoundexAlgorithm.compute("b").get should equal ("b1")
- RefinedSoundexAlgorithm.compute("bb").get should equal ("b1")
+ Algorithm.compute("b").get should equal ("b1")
+ Algorithm.compute("bb").get should equal ("b1")
// c
- RefinedSoundexAlgorithm.compute("c").get should equal ("c3")
- RefinedSoundexAlgorithm.compute("cc").get should equal ("c3")
+ Algorithm.compute("c").get should equal ("c3")
+ Algorithm.compute("cc").get should equal ("c3")
// d
- RefinedSoundexAlgorithm.compute("d").get should equal ("d6")
- RefinedSoundexAlgorithm.compute("dd").get should equal ("d6")
+ Algorithm.compute("d").get should equal ("d6")
+ Algorithm.compute("dd").get should equal ("d6")
// e
- RefinedSoundexAlgorithm.compute("e").get should equal ("e0")
- RefinedSoundexAlgorithm.compute("ee").get should equal ("e0")
+ Algorithm.compute("e").get should equal ("e0")
+ Algorithm.compute("ee").get should equal ("e0")
// f
- RefinedSoundexAlgorithm.compute("f").get should equal ("f2")
- RefinedSoundexAlgorithm.compute("ff").get should equal ("f2")
+ Algorithm.compute("f").get should equal ("f2")
+ Algorithm.compute("ff").get should equal ("f2")
// g
- RefinedSoundexAlgorithm.compute("g").get should equal ("g4")
- RefinedSoundexAlgorithm.compute("gg").get should equal ("g4")
+ Algorithm.compute("g").get should equal ("g4")
+ Algorithm.compute("gg").get should equal ("g4")
// h
- RefinedSoundexAlgorithm.compute("h").get should equal ("h0")
- RefinedSoundexAlgorithm.compute("hh").get should equal ("h0")
+ Algorithm.compute("h").get should equal ("h0")
+ Algorithm.compute("hh").get should equal ("h0")
// i
- RefinedSoundexAlgorithm.compute("i").get should equal ("i0")
- RefinedSoundexAlgorithm.compute("ii").get should equal ("i0")
+ Algorithm.compute("i").get should equal ("i0")
+ Algorithm.compute("ii").get should equal ("i0")
// j
- RefinedSoundexAlgorithm.compute("j").get should equal ("j4")
- RefinedSoundexAlgorithm.compute("jj").get should equal ("j4")
+ Algorithm.compute("j").get should equal ("j4")
+ Algorithm.compute("jj").get should equal ("j4")
// k
- RefinedSoundexAlgorithm.compute("k").get should equal ("k3")
- RefinedSoundexAlgorithm.compute("kk").get should equal ("k3")
+ Algorithm.compute("k").get should equal ("k3")
+ Algorithm.compute("kk").get should equal ("k3")
// l
- RefinedSoundexAlgorithm.compute("l").get should equal ("l7")
- RefinedSoundexAlgorithm.compute("ll").get should equal ("l7")
+ Algorithm.compute("l").get should equal ("l7")
+ Algorithm.compute("ll").get should equal ("l7")
// m
- RefinedSoundexAlgorithm.compute("m").get should equal ("m8")
- RefinedSoundexAlgorithm.compute("mm").get should equal ("m8")
+ Algorithm.compute("m").get should equal ("m8")
+ Algorithm.compute("mm").get should equal ("m8")
// n
- RefinedSoundexAlgorithm.compute("n").get should equal ("n8")
- RefinedSoundexAlgorithm.compute("nn").get should equal ("n8")
+ Algorithm.compute("n").get should equal ("n8")
+ Algorithm.compute("nn").get should equal ("n8")
// o
- RefinedSoundexAlgorithm.compute("o").get should equal ("o0")
- RefinedSoundexAlgorithm.compute("oo").get should equal ("o0")
+ Algorithm.compute("o").get should equal ("o0")
+ Algorithm.compute("oo").get should equal ("o0")
// p
- RefinedSoundexAlgorithm.compute("p").get should equal ("p1")
- RefinedSoundexAlgorithm.compute("pp").get should equal ("p1")
+ Algorithm.compute("p").get should equal ("p1")
+ Algorithm.compute("pp").get should equal ("p1")
// q
- RefinedSoundexAlgorithm.compute("q").get should equal ("q5")
- RefinedSoundexAlgorithm.compute("qq").get should equal ("q5")
+ Algorithm.compute("q").get should equal ("q5")
+ Algorithm.compute("qq").get should equal ("q5")
// r
- RefinedSoundexAlgorithm.compute("r").get should equal ("r9")
- RefinedSoundexAlgorithm.compute("rr").get should equal ("r9")
+ Algorithm.compute("r").get should equal ("r9")
+ Algorithm.compute("rr").get should equal ("r9")
// s
- RefinedSoundexAlgorithm.compute("s").get should equal ("s3")
- RefinedSoundexAlgorithm.compute("ss").get should equal ("s3")
+ Algorithm.compute("s").get should equal ("s3")
+ Algorithm.compute("ss").get should equal ("s3")
// t
- RefinedSoundexAlgorithm.compute("t").get should equal ("t6")
- RefinedSoundexAlgorithm.compute("tt").get should equal ("t6")
+ Algorithm.compute("t").get should equal ("t6")
+ Algorithm.compute("tt").get should equal ("t6")
// u
- RefinedSoundexAlgorithm.compute("u").get should equal ("u0")
- RefinedSoundexAlgorithm.compute("uu").get should equal ("u0")
+ Algorithm.compute("u").get should equal ("u0")
+ Algorithm.compute("uu").get should equal ("u0")
// v
- RefinedSoundexAlgorithm.compute("v").get should equal ("v2")
- RefinedSoundexAlgorithm.compute("vv").get should equal ("v2")
+ Algorithm.compute("v").get should equal ("v2")
+ Algorithm.compute("vv").get should equal ("v2")
// w
- RefinedSoundexAlgorithm.compute("w").get should equal ("w0")
- RefinedSoundexAlgorithm.compute("ww").get should equal ("w0")
+ Algorithm.compute("w").get should equal ("w0")
+ Algorithm.compute("ww").get should equal ("w0")
// x
- RefinedSoundexAlgorithm.compute("x").get should equal ("x5")
- RefinedSoundexAlgorithm.compute("xx").get should equal ("x5")
+ Algorithm.compute("x").get should equal ("x5")
+ Algorithm.compute("xx").get should equal ("x5")
// y
- RefinedSoundexAlgorithm.compute("y").get should equal ("y0")
- RefinedSoundexAlgorithm.compute("yy").get should equal ("y0")
+ Algorithm.compute("y").get should equal ("y0")
+ Algorithm.compute("yy").get should equal ("y0")
// z
- RefinedSoundexAlgorithm.compute("z").get should equal ("z5")
- RefinedSoundexAlgorithm.compute("zz").get should equal ("z5")
+ Algorithm.compute("z").get should equal ("z5")
+ Algorithm.compute("zz").get should equal ("z5")
// Starting with letter then numbers.
- RefinedSoundexAlgorithm.compute("x123456").get should equal ("x5")
- RefinedSoundexAlgorithm.compute("a123456").get should equal ("a0")
- RefinedSoundexAlgorithm.compute("f123456").get should equal ("f2")
+ Algorithm.compute("x123456").get should equal ("x5")
+ Algorithm.compute("a123456").get should equal ("a0")
+ Algorithm.compute("f123456").get should equal ("f2")
// Miscellaneous.
- 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")
+ 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")
}
}
}
}
-} \ No newline at end of file
+}
+
+object RefinedSoundexAlgorithmSpec {
+ final private val Algorithm = new 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 97a168b..dd9bd04 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala
@@ -6,32 +6,38 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class RefinedSoundexMetricSpec extends ScalaTest {
+ import RefinedSoundexMetricSpec._
+
"RefinedSoundexMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- RefinedSoundexMetric.compare("", "").isDefined should be (false)
- RefinedSoundexMetric.compare("abc", "").isDefined should be (false)
- RefinedSoundexMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"non-phonetic arguments" should returns {
"None" in {
- RefinedSoundexMetric.compare("123", "123").isDefined should be (false)
- RefinedSoundexMetric.compare("123", "").isDefined should be (false)
- RefinedSoundexMetric.compare("", "123").isDefined should be (false)
+ Metric.compare("123", "123").isDefined should be (false)
+ Metric.compare("123", "").isDefined should be (false)
+ Metric.compare("", "123").isDefined should be (false)
}
}
"phonetically similar arguments" should returns {
"Boolean indicating true" in {
- RefinedSoundexMetric.compare("robert", "rupert").get should be (true)
+ Metric.compare("robert", "rupert").get should be (true)
}
}
"phonetically dissimilar arguments" should returns {
"Boolean indicating false" in {
- RefinedSoundexMetric.compare("robert", "rubin").get should be (false)
+ Metric.compare("robert", "rubin").get should be (false)
}
}
}
}
-} \ No newline at end of file
+}
+
+object RefinedSoundexMetricSpec {
+ final private val Metric = new 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 ec8b2ba..6b286e5 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala
@@ -6,156 +6,162 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class SoundexAlgorithmSpec extends ScalaTest {
+ import SoundexAlgorithmSpec._
+
"SoundexAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- SoundexAlgorithm.compute("").isDefined should be (false)
+ Algorithm.compute("").isDefined should be (false)
}
}
"non-phonetic argument" should returns {
"None" in {
- SoundexAlgorithm.compute("123").isDefined should be (false)
+ Algorithm.compute("123").isDefined should be (false)
}
}
"phonetic argument" should returns {
"Some" in {
// a
- SoundexAlgorithm.compute("a").get should equal ("a000")
- SoundexAlgorithm.compute("aa").get should equal ("a000")
+ Algorithm.compute("a").get should equal ("a000")
+ Algorithm.compute("aa").get should equal ("a000")
// b
- SoundexAlgorithm.compute("b").get should equal ("b000")
- SoundexAlgorithm.compute("bb").get should equal ("b000")
+ Algorithm.compute("b").get should equal ("b000")
+ Algorithm.compute("bb").get should equal ("b000")
// c
- SoundexAlgorithm.compute("c").get should equal ("c000")
- SoundexAlgorithm.compute("cc").get should equal ("c000")
+ Algorithm.compute("c").get should equal ("c000")
+ Algorithm.compute("cc").get should equal ("c000")
// d
- SoundexAlgorithm.compute("d").get should equal ("d000")
- SoundexAlgorithm.compute("dd").get should equal ("d000")
+ Algorithm.compute("d").get should equal ("d000")
+ Algorithm.compute("dd").get should equal ("d000")
// e
- SoundexAlgorithm.compute("e").get should equal ("e000")
- SoundexAlgorithm.compute("ee").get should equal ("e000")
+ Algorithm.compute("e").get should equal ("e000")
+ Algorithm.compute("ee").get should equal ("e000")
// f
- SoundexAlgorithm.compute("f").get should equal ("f000")
- SoundexAlgorithm.compute("ff").get should equal ("f000")
+ Algorithm.compute("f").get should equal ("f000")
+ Algorithm.compute("ff").get should equal ("f000")
// g
- SoundexAlgorithm.compute("g").get should equal ("g000")
- SoundexAlgorithm.compute("gg").get should equal ("g000")
+ Algorithm.compute("g").get should equal ("g000")
+ Algorithm.compute("gg").get should equal ("g000")
// h
- SoundexAlgorithm.compute("h").get should equal ("h000")
- SoundexAlgorithm.compute("hh").get should equal ("h000")
+ Algorithm.compute("h").get should equal ("h000")
+ Algorithm.compute("hh").get should equal ("h000")
// i
- SoundexAlgorithm.compute("i").get should equal ("i000")
- SoundexAlgorithm.compute("ii").get should equal ("i000")
+ Algorithm.compute("i").get should equal ("i000")
+ Algorithm.compute("ii").get should equal ("i000")
// j
- SoundexAlgorithm.compute("j").get should equal ("j000")
- SoundexAlgorithm.compute("jj").get should equal ("j000")
+ Algorithm.compute("j").get should equal ("j000")
+ Algorithm.compute("jj").get should equal ("j000")
// k
- SoundexAlgorithm.compute("k").get should equal ("k000")
- SoundexAlgorithm.compute("kk").get should equal ("k000")
+ Algorithm.compute("k").get should equal ("k000")
+ Algorithm.compute("kk").get should equal ("k000")
// l
- SoundexAlgorithm.compute("l").get should equal ("l000")
- SoundexAlgorithm.compute("ll").get should equal ("l000")
+ Algorithm.compute("l").get should equal ("l000")
+ Algorithm.compute("ll").get should equal ("l000")
// m
- SoundexAlgorithm.compute("m").get should equal ("m000")
- SoundexAlgorithm.compute("mm").get should equal ("m000")
+ Algorithm.compute("m").get should equal ("m000")
+ Algorithm.compute("mm").get should equal ("m000")
// n
- SoundexAlgorithm.compute("n").get should equal ("n000")
- SoundexAlgorithm.compute("nn").get should equal ("n000")
+ Algorithm.compute("n").get should equal ("n000")
+ Algorithm.compute("nn").get should equal ("n000")
// o
- SoundexAlgorithm.compute("o").get should equal ("o000")
- SoundexAlgorithm.compute("oo").get should equal ("o000")
+ Algorithm.compute("o").get should equal ("o000")
+ Algorithm.compute("oo").get should equal ("o000")
// p
- SoundexAlgorithm.compute("p").get should equal ("p000")
- SoundexAlgorithm.compute("pp").get should equal ("p000")
+ Algorithm.compute("p").get should equal ("p000")
+ Algorithm.compute("pp").get should equal ("p000")
// q
- SoundexAlgorithm.compute("q").get should equal ("q000")
- SoundexAlgorithm.compute("qq").get should equal ("q000")
+ Algorithm.compute("q").get should equal ("q000")
+ Algorithm.compute("qq").get should equal ("q000")
// r
- SoundexAlgorithm.compute("r").get should equal ("r000")
- SoundexAlgorithm.compute("rr").get should equal ("r000")
+ Algorithm.compute("r").get should equal ("r000")
+ Algorithm.compute("rr").get should equal ("r000")
// s
- SoundexAlgorithm.compute("s").get should equal ("s000")
- SoundexAlgorithm.compute("ss").get should equal ("s000")
+ Algorithm.compute("s").get should equal ("s000")
+ Algorithm.compute("ss").get should equal ("s000")
// t
- SoundexAlgorithm.compute("t").get should equal ("t000")
- SoundexAlgorithm.compute("tt").get should equal ("t000")
+ Algorithm.compute("t").get should equal ("t000")
+ Algorithm.compute("tt").get should equal ("t000")
// u
- SoundexAlgorithm.compute("u").get should equal ("u000")
- SoundexAlgorithm.compute("uu").get should equal ("u000")
+ Algorithm.compute("u").get should equal ("u000")
+ Algorithm.compute("uu").get should equal ("u000")
// v
- SoundexAlgorithm.compute("v").get should equal ("v000")
- SoundexAlgorithm.compute("vv").get should equal ("v000")
+ Algorithm.compute("v").get should equal ("v000")
+ Algorithm.compute("vv").get should equal ("v000")
// w
- SoundexAlgorithm.compute("w").get should equal ("w000")
- SoundexAlgorithm.compute("ww").get should equal ("w000")
+ Algorithm.compute("w").get should equal ("w000")
+ Algorithm.compute("ww").get should equal ("w000")
// x
- SoundexAlgorithm.compute("x").get should equal ("x000")
- SoundexAlgorithm.compute("xx").get should equal ("x000")
+ Algorithm.compute("x").get should equal ("x000")
+ Algorithm.compute("xx").get should equal ("x000")
// y
- SoundexAlgorithm.compute("y").get should equal ("y000")
- SoundexAlgorithm.compute("yy").get should equal ("y000")
+ Algorithm.compute("y").get should equal ("y000")
+ Algorithm.compute("yy").get should equal ("y000")
// z
- SoundexAlgorithm.compute("z").get should equal ("z000")
- SoundexAlgorithm.compute("zz").get should equal ("z000")
+ Algorithm.compute("z").get should equal ("z000")
+ Algorithm.compute("zz").get should equal ("z000")
// Starting with letter then numbers.
- SoundexAlgorithm.compute("x123456").get should equal ("x000")
- SoundexAlgorithm.compute("a123456").get should equal ("a000")
- SoundexAlgorithm.compute("f123456").get should equal ("f000")
+ Algorithm.compute("x123456").get should equal ("x000")
+ Algorithm.compute("a123456").get should equal ("a000")
+ Algorithm.compute("f123456").get should equal ("f000")
// Miscellaneous.
- 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")
+ 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")
}
}
}
}
-} \ No newline at end of file
+}
+
+object SoundexAlgorithmSpec {
+ final private val Algorithm = new 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 78dae78..5758f86 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala
@@ -6,32 +6,38 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class SoundexMetricSpec extends ScalaTest {
+ import SoundexMetricSpec._
+
"SoundexMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- SoundexMetric.compare("", "").isDefined should be (false)
- SoundexMetric.compare("abc", "").isDefined should be (false)
- SoundexMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"non-phonetic arguments" should returns {
"None" in {
- SoundexMetric.compare("123", "123").isDefined should be (false)
- SoundexMetric.compare("123", "").isDefined should be (false)
- SoundexMetric.compare("", "123").isDefined should be (false)
+ Metric.compare("123", "123").isDefined should be (false)
+ Metric.compare("123", "").isDefined should be (false)
+ Metric.compare("", "123").isDefined should be (false)
}
}
"phonetically similar arguments" should returns {
"Boolean indicating true" in {
- SoundexMetric.compare("robert", "rupert").get should be (true)
+ Metric.compare("robert", "rupert").get should be (true)
}
}
"phonetically dissimilar arguments" should returns {
"Boolean indicating false" in {
- SoundexMetric.compare("robert", "rubin").get should be (false)
+ Metric.compare("robert", "rubin").get should be (false)
}
}
}
}
-} \ No newline at end of file
+}
+
+object SoundexMetricSpec {
+ final private val Metric = new 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 4008683..b05a4fc 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala
@@ -6,57 +6,63 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class DiceSorensenMetricSpec extends ScalaTest {
+ import DiceSorensenMetricSpec._
+
"DiceSorensenMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- DiceSorensenMetric.compare("", "")(1).isDefined should be (false)
- DiceSorensenMetric.compare("abc", "")(1).isDefined should be (false)
- DiceSorensenMetric.compare("", "xyz")(1).isDefined should be (false)
+ Metric.compare("", "")(1).isDefined should be (false)
+ Metric.compare("abc", "")(1).isDefined should be (false)
+ Metric.compare("", "xyz")(1).isDefined should be (false)
}
}
"equal arguments" should returns {
"1" in {
- DiceSorensenMetric.compare("abc", "abc")(1).get should be (1)
- DiceSorensenMetric.compare("abc", "abc")(2).get should be (1)
- DiceSorensenMetric.compare("abc", "abc")(3).get should be (1)
+ 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)
}
}
"unequal arguments" should returns {
"0" in {
- DiceSorensenMetric.compare("abc", "xyz")(1).get should be (0)
- DiceSorensenMetric.compare("abc", "xyz")(2).get should be (0)
- DiceSorensenMetric.compare("abc", "xyz")(3).get should be (0)
+ 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)
}
}
"invalid arguments" should returns {
"None" in {
- DiceSorensenMetric.compare("n", "naght")(2).isDefined should be (false)
- DiceSorensenMetric.compare("night", "n")(2).isDefined should be (false)
- DiceSorensenMetric.compare("ni", "naght")(3).isDefined should be (false)
- DiceSorensenMetric.compare("night", "na")(3).isDefined should be (false)
+ 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)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- DiceSorensenMetric.compare("night", "nacht")(1).get should be (0.6)
- DiceSorensenMetric.compare("night", "naght")(1).get should be (0.8)
- DiceSorensenMetric.compare("context", "contact")(1).get should be (0.7142857142857143)
+ 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.compare("night", "nacht")(2).get should be (0.25)
- DiceSorensenMetric.compare("night", "naght")(2).get should be (0.5)
- DiceSorensenMetric.compare("context", "contact")(2).get should be (0.5)
- DiceSorensenMetric.compare("contextcontext", "contact")(2).get should be (0.3157894736842105)
- DiceSorensenMetric.compare("context", "contactcontact")(2).get should be (0.3157894736842105)
- DiceSorensenMetric.compare("ht", "nacht")(2).get should be (0.4)
- DiceSorensenMetric.compare("xp", "nacht")(2).get should be (0)
- DiceSorensenMetric.compare("ht", "hththt")(2).get should be (0.3333333333333333)
+ 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.compare("night", "nacht")(3).get should be (0)
- DiceSorensenMetric.compare("night", "naght")(3).get should be (0.3333333333333333)
- DiceSorensenMetric.compare("context", "contact")(3).get should be (0.4)
+ 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)
}
}
}
}
-} \ No newline at end of file
+}
+
+object DiceSorensenMetricSpec {
+ private final val Metric = new 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 95cdbba..ede84ad 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala
@@ -6,34 +6,40 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class HammingMetricSpec extends ScalaTest {
+ import HammingMetricSpec._
+
"HammingMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- HammingMetric.compare("", "").isDefined should be (false)
- HammingMetric.compare("abc", "").isDefined should be (false)
- HammingMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"equal arguments" should returns {
"0" in {
- HammingMetric.compare("abc", "abc").get should be (0)
- HammingMetric.compare("123", "123").get should be (0)
+ Metric.compare("abc", "abc").get should be (0)
+ Metric.compare("123", "123").get should be (0)
}
}
"unequal arguments" should returns {
"Int indicating distance" in {
- HammingMetric.compare("abc", "xyz").get should be (3)
- HammingMetric.compare("123", "456").get should be (3)
+ Metric.compare("abc", "xyz").get should be (3)
+ Metric.compare("123", "456").get should be (3)
}
}
"valid arguments" should returns {
"Int indicating distance" in {
- HammingMetric.compare("toned", "roses").get should be (3)
- HammingMetric.compare("1011101", "1001001").get should be (2)
- HammingMetric.compare("2173896", "2233796").get should be (3)
+ Metric.compare("toned", "roses").get should be (3)
+ Metric.compare("1011101", "1001001").get should be (2)
+ Metric.compare("2173896", "2233796").get should be (3)
}
}
}
}
-} \ No newline at end of file
+}
+
+object HammingMetricSpec {
+ private final val Metric = new HammingMetric
+}
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 e9440e4..5b99619 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala
@@ -6,48 +6,54 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class JaroMetricSpec extends ScalaTest {
+ import JaroMetricSpec._
+
"JaroMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- JaroMetric.compare("", "").isDefined should be (false)
- JaroMetric.compare("abc", "").isDefined should be (false)
- JaroMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"equal arguments" should returns {
"1" in {
- JaroMetric.compare("a", "a").get should be (1)
- JaroMetric.compare("abc", "abc").get should be (1)
- JaroMetric.compare("123", "123").get should be (1)
+ Metric.compare("a", "a").get should be (1)
+ Metric.compare("abc", "abc").get should be (1)
+ Metric.compare("123", "123").get should be (1)
}
}
"unequal arguments" should returns {
"0" in {
- JaroMetric.compare("abc", "xyz").get should be (0)
- JaroMetric.compare("123", "456").get should be (0)
+ Metric.compare("abc", "xyz").get should be (0)
+ Metric.compare("123", "456").get should be (0)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- 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("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("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
+ 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
}
}
}
}
-} \ No newline at end of file
+}
+
+object JaroMetricSpec {
+ private final val Metric = new 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 c2ad5eb..d9fe4b7 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala
@@ -6,48 +6,54 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class JaroWinklerMetricSpec extends ScalaTest {
+ import JaroWinklerMetricSpec._
+
"JaroWinklerMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- JaroWinklerMetric.compare("", "").isDefined should be (false)
- JaroWinklerMetric.compare("abc", "").isDefined should be (false)
- JaroWinklerMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"equal arguments" should returns {
"1" in {
- JaroWinklerMetric.compare("a", "a").get should be (1)
- JaroWinklerMetric.compare("abc", "abc").get should be (1)
- JaroWinklerMetric.compare("123", "123").get should be (1)
+ Metric.compare("a", "a").get should be (1)
+ Metric.compare("abc", "abc").get should be (1)
+ Metric.compare("123", "123").get should be (1)
}
}
"unequal arguments" should returns {
"0" in {
- JaroWinklerMetric.compare("abc", "xyz").get should be (0)
- JaroWinklerMetric.compare("123", "456").get should be (0)
+ Metric.compare("abc", "xyz").get should be (0)
+ Metric.compare("123", "456").get should be (0)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- 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("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("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
+ 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
}
}
}
}
-} \ No newline at end of file
+}
+
+object JaroWinklerMetricSpec {
+ private final val Metric = new 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 4f78643..ac45a21 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala
@@ -6,47 +6,53 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class LevenshteinMetricSpec extends ScalaTest {
+ import LevenshteinMetricSpec._
+
"LevenshteinMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- LevenshteinMetric.compare("", "").isDefined should be (false)
- LevenshteinMetric.compare("abc", "").isDefined should be (false)
- LevenshteinMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"equal arguments" should returns {
"0" in {
- LevenshteinMetric.compare("abc", "abc").get should be (0)
- LevenshteinMetric.compare("123", "123").get should be (0)
+ Metric.compare("abc", "abc").get should be (0)
+ Metric.compare("123", "123").get should be (0)
}
}
"unequal arguments" should returns {
"Int indicating distance" in {
- LevenshteinMetric.compare("abc", "xyz").get should be (3)
- LevenshteinMetric.compare("123", "456").get should be (3)
+ Metric.compare("abc", "xyz").get should be (3)
+ Metric.compare("123", "456").get should be (3)
}
}
"valid arguments" should returns {
"Int indicating distance" in {
- 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)
+ 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)
}
}
}
}
-} \ No newline at end of file
+}
+
+object LevenshteinMetricSpec {
+ private final val Metric = new LevenshteinMetric
+}
diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala
index b41f37c..ffeefb0 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala
@@ -6,41 +6,41 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class NGramAlgorithmSpec extends ScalaTest {
+ import NGramAlgorithmSpec._
+
"NGramAlgorithm" should provide {
"compute method" when passed {
"empty argument" should returns {
"None" in {
- NGramAlgorithm.compute("")(1).isDefined should be (false)
+ Algorithm.compute("")(1).isDefined should be (false)
}
}
"invalid n argument" should throws {
"IllegalArgumentException" in {
evaluating {
- NGramAlgorithm.compute("")(0).isDefined should be (false)
+ Algorithm.compute("")(0).isDefined should be (false)
} should produce [IllegalArgumentException]
evaluating {
- NGramAlgorithm.compute("")(-1).isDefined should be (false)
+ Algorithm.compute("")(-1).isDefined should be (false)
} should produce [IllegalArgumentException]
}
}
"valid argument" should returns {
"Array[String]" in {
- NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(1).get should equal (
+ Algorithm.compute("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"
)
)
-
- NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(2).get should equal (
+ Algorithm.compute("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"
)
)
-
- NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(3).get should equal (
+ Algorithm.compute("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"
@@ -50,4 +50,8 @@ final class NGramAlgorithmSpec extends ScalaTest {
}
}
}
-} \ No newline at end of file
+}
+
+object NGramAlgorithmSpec {
+ private final val Algorithm = new NGramAlgorithm
+}
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 a46f103..0f09ab1 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala
@@ -6,57 +6,63 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class NGramMetricSpec extends ScalaTest {
+ import NGramMetricSpec._
+
"NGramMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- NGramMetric.compare("", "")(1).isDefined should be (false)
- NGramMetric.compare("abc", "")(1).isDefined should be (false)
- NGramMetric.compare("", "xyz")(1).isDefined should be (false)
+ Metric.compare("", "")(1).isDefined should be (false)
+ Metric.compare("abc", "")(1).isDefined should be (false)
+ Metric.compare("", "xyz")(1).isDefined should be (false)
}
}
"equal arguments" should returns {
"1" in {
- NGramMetric.compare("abc", "abc")(1).get should be (1)
- NGramMetric.compare("abc", "abc")(2).get should be (1)
- NGramMetric.compare("abc", "abc")(3).get should be (1)
+ 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)
}
}
"unequal arguments" should returns {
"0" in {
- NGramMetric.compare("abc", "xyz")(1).get should be (0)
- NGramMetric.compare("abc", "xyz")(2).get should be (0)
- NGramMetric.compare("abc", "xyz")(3).get should be (0)
+ 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)
}
}
"invalid arguments" should returns {
"None" in {
- NGramMetric.compare("n", "naght")(2).isDefined should be (false)
- NGramMetric.compare("night", "n")(2).isDefined should be (false)
- NGramMetric.compare("ni", "naght")(3).isDefined should be (false)
- NGramMetric.compare("night", "na")(3).isDefined should be (false)
+ 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)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- NGramMetric.compare("night", "nacht")(1).get should be (0.6)
- NGramMetric.compare("night", "naght")(1).get should be (0.8)
- NGramMetric.compare("context", "contact")(1).get should be (0.7142857142857143)
+ 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.compare("night", "nacht")(2).get should be (0.25)
- NGramMetric.compare("night", "naght")(2).get should be (0.5)
- NGramMetric.compare("context", "contact")(2).get should be (0.5)
- NGramMetric.compare("contextcontext", "contact")(2).get should be (0.23076923076923078)
- NGramMetric.compare("context", "contactcontact")(2).get should be (0.23076923076923078)
- NGramMetric.compare("ht", "nacht")(2).get should be (0.25)
- NGramMetric.compare("xp", "nacht")(2).get should be (0)
- NGramMetric.compare("ht", "hththt")(2).get should be (0.2)
+ 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.compare("night", "nacht")(3).get should be (0)
- NGramMetric.compare("night", "naght")(3).get should be (0.3333333333333333)
- NGramMetric.compare("context", "contact")(3).get should be (0.4)
+ 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)
}
}
}
}
-} \ No newline at end of file
+}
+
+object NGramMetricSpec {
+ private final val Metric = new NGramMetric
+}
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 e1ff9cf..d6a8d45 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala
@@ -6,37 +6,44 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class RatcliffObershelpMetricSpec extends ScalaTest {
+ import RatcliffObershelpMetricSpec._
+
"RatcliffObershelpMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- RatcliffObershelpMetric.compare("", "").isDefined should be (false)
- RatcliffObershelpMetric.compare("abc", "").isDefined should be (false)
- RatcliffObershelpMetric.compare("", "xyz").isDefined should be (false)
+ Metric.compare("", "").isDefined should be (false)
+ Metric.compare("abc", "").isDefined should be (false)
+ Metric.compare("", "xyz").isDefined should be (false)
}
}
"equal arguments" should returns {
"0" in {
- RatcliffObershelpMetric.compare("abc", "abc").get should be (1)
- RatcliffObershelpMetric.compare("123", "123").get should be (1)
+ Metric.compare("abc", "abc").get should be (1)
+ Metric.compare("123", "123").get should be (1)
}
}
"unequal arguments" should returns {
"Double indicating distance" in {
- RatcliffObershelpMetric.compare("abc", "xyz").get should be (0)
- RatcliffObershelpMetric.compare("123", "456").get should be (0)
+ Metric.compare("abc", "xyz").get should be (0)
+ Metric.compare("123", "456").get should be (0)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- 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)
+ 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)
}
}
}
}
}
+
+object RatcliffObershelpMetricSpec {
+ private final val Metric = new 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 d819d48..5665d7c 100755
--- a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala
@@ -6,45 +6,45 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
final class WeightedLevenshteinMetricSpec extends ScalaTest {
- import WeightedLevenshteinMetricSpec.Options
+ import WeightedLevenshteinMetricSpec._
"WeightedLevenshteinMetric" should provide {
"compare method" when passed {
"empty arguments" should returns {
"None" in {
- WeightedLevenshteinMetric.compare("", "")(Options).isDefined should be (false)
- WeightedLevenshteinMetric.compare("abc", "")(Options).isDefined should be (false)
- WeightedLevenshteinMetric.compare("", "xyz")(Options).isDefined should be (false)
+ Metric.compare("", "")(Options).isDefined should be (false)
+ Metric.compare("abc", "")(Options).isDefined should be (false)
+ Metric.compare("", "xyz")(Options).isDefined should be (false)
}
}
"equal arguments" should returns {
"0" in {
- WeightedLevenshteinMetric.compare("abc", "abc")(Options).get should be (0)
- WeightedLevenshteinMetric.compare("123", "123")(Options).get should be (0)
+ Metric.compare("abc", "abc")(Options).get should be (0)
+ Metric.compare("123", "123")(Options).get should be (0)
}
}
"unequal arguments" should returns {
"Double indicating distance" in {
- WeightedLevenshteinMetric.compare("abc", "xyz")(Options).get should be (3)
- WeightedLevenshteinMetric.compare("123", "456")(Options).get should be (3)
+ Metric.compare("abc", "xyz")(Options).get should be (3)
+ Metric.compare("123", "456")(Options).get should be (3)
}
}
"valid arguments" should returns {
"Double indicating distance" in {
- WeightedLevenshteinMetric.compare("az", "z")(Options).get should be (10)
- WeightedLevenshteinMetric.compare("z", "az")(Options).get should be (0.1)
- WeightedLevenshteinMetric.compare("a", "z")(Options).get should be (1)
- WeightedLevenshteinMetric.compare("z", "a")(Options).get should be (1)
- WeightedLevenshteinMetric.compare("ab", "yz")(Options).get should be (2)
- WeightedLevenshteinMetric.compare("yz", "ab")(Options).get should be (2)
- WeightedLevenshteinMetric.compare("0", "0123456789")(Options).get should be (0.9)
- WeightedLevenshteinMetric.compare("0123456789", "0")(Options).get should be (90)
- WeightedLevenshteinMetric.compare("book", "back")(Options).get should be (2)
- WeightedLevenshteinMetric.compare("back", "book")(Options).get should be (2)
- WeightedLevenshteinMetric.compare("hosp", "hospital")(Options).get should be (0.4)
- WeightedLevenshteinMetric.compare("hospital", "hosp")(Options).get should be (40)
- WeightedLevenshteinMetric.compare("clmbs blvd", "columbus boulevard")(Options).get should be (0.8)
- WeightedLevenshteinMetric.compare("columbus boulevard", "clmbs blvd")(Options).get should be (80)
+ 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)
}
}
}
@@ -53,4 +53,5 @@ final class WeightedLevenshteinMetricSpec extends ScalaTest {
object WeightedLevenshteinMetricSpec {
private final val Options = Tuple3[BigDecimal, BigDecimal, BigDecimal](10, 0.1, 1)
+ private final val Metric = new WeightedLevenshteinMetric
}