diff options
author | Rocky Madden <git@rockymadden.com> | 2013-12-28 18:39:04 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-12-28 18:39:04 -0700 |
commit | c42768673de38cf835f249f692a471456dedc75b (patch) | |
tree | b869f0668ad58cc316d85e451fd756d2bad84617 /core/source/main/scala/com | |
parent | 75d6fbe5e3fcea28754e9c2fc4b0bcefcf512665 (diff) | |
download | stringmetric-c42768673de38cf835f249f692a471456dedc75b.tar.gz stringmetric-c42768673de38cf835f249f692a471456dedc75b.tar.bz2 stringmetric-c42768673de38cf835f249f692a471456dedc75b.zip |
Added convenience objects.
Diffstat (limited to 'core/source/main/scala/com')
4 files changed, 79 insertions, 1 deletions
diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala b/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala index 5acb9f3..cb0d9cc 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Algorithm.scala @@ -9,4 +9,23 @@ object Algorithm { trait StringAlgorithm extends Algorithm[Array[Char]] { def compute(a: String): Option[String] } + + + object StringAlgorithm { + val Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneAlgorithm + val Nysiis = com.rockymadden.stringmetric.phonetic.NysiisAlgorithm + val RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisAlgorithm + val RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexAlgorithm + val Soundex = com.rockymadden.stringmetric.phonetic.SoundexAlgorithm + + def computeWithMetaphone(charArray: Array[Char]) = Metaphone.compute(charArray) + + def computeWithNysiis(charArray: Array[Char]) = Nysiis.compute(charArray) + + def computeWithRefinedNysiis(charArray: Array[Char]) = RefinedNysiis.compute(charArray) + + def computeWithRefinedSoundex(charArray: Array[Char]) = RefinedSoundex.compute(charArray) + + def computeWithSoundex(charArray: Array[Char]) = Soundex.compute(charArray) + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala b/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala index 5423d4d..ea70b9c 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Metric.scala @@ -9,4 +9,53 @@ object Metric { trait StringMetric[A] extends Metric[Array[Char], A] { def compare(a: String, b: String): Option[A] } + + + object StringMetric { + final val DiceSorensen = com.rockymadden.stringmetric.similarity.DiceSorensenMetric + final val Hamming = com.rockymadden.stringmetric.similarity.HammingMetric + final val Jaccard = com.rockymadden.stringmetric.similarity.JaccardMetric + final val Jaro = com.rockymadden.stringmetric.similarity.JaroMetric + final val JaroWinkler = com.rockymadden.stringmetric.similarity.JaroWinklerMetric + final val Levenshtein = com.rockymadden.stringmetric.similarity.LevenshteinMetric + final val Metaphone = com.rockymadden.stringmetric.phonetic.MetaphoneMetric + final val NGram = com.rockymadden.stringmetric.similarity.NGramMetric + final val Nysiis = com.rockymadden.stringmetric.phonetic.NysiisMetric + final val Overlap = com.rockymadden.stringmetric.similarity.OverlapMetric + final val RefinedNysiis = com.rockymadden.stringmetric.phonetic.RefinedNysiisMetric + final val RefinedSoundex = com.rockymadden.stringmetric.phonetic.RefinedSoundexMetric + final val Soundex = com.rockymadden.stringmetric.phonetic.SoundexMetric + final val WeightedLevenshtein = com.rockymadden.stringmetric.similarity.WeightedLevenshteinMetric + + def compareWithDiceSorensen(n: Int)(a: Array[Char], b: Array[Char]) = DiceSorensen(n).compare(a, b) + + def compareWithHamming(a: Array[Char], b: Array[Char]) = Hamming.compare(a, b) + + def compareWithJaccard(n: Int)(a: Array[Char], b: Array[Char]) = Jaccard(n).compare(a, b) + + def compareWithJaro(a: Array[Char], b: Array[Char]) = Jaro.compare(a, b) + + def compareWithJaroWinkler(a: Array[Char], b: Array[Char]) = JaroWinkler.compare(a, b) + + def compareWithLevenshtein(a: Array[Char], b: Array[Char]) = Levenshtein.compare(a, b) + + def compareWithMetaphone(a: Array[Char], b: Array[Char]) = Metaphone.compare(a, b) + + def compareWithNGram(n: Int)(a: Array[Char], b: Array[Char]) = NGram(n).compare(a, b) + + def compareWithNysiis(a: Array[Char], b: Array[Char]) = Nysiis.compare(a, b) + + def compareWithOverlap(n: Int)(a: Array[Char], b: Array[Char]) = Overlap(n).compare(a, b) + + def compareWithRefinedNysiis(a: Array[Char], b: Array[Char]) = RefinedNysiis.compare(a, b) + + def compareWithRefinedSoundex(a: Array[Char], b: Array[Char]) = RefinedSoundex.compare(a, b) + + def compareWithSoundex(a: Array[Char], b: Array[Char]) = Soundex.compare(a, b) + + def compareWithWeightedLevenshtein(delete: BigDecimal, insert: BigDecimal, substitute: BigDecimal) + (a: Array[Char], b: Array[Char]) = + + WeightedLevenshtein(delete, insert, substitute).compare(a, b) + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala b/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala index 7053f98..ed012d4 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/Tokenizer.scala @@ -9,4 +9,11 @@ object Tokenizer { trait StringTokenizer extends Tokenizer[Array[Char]] { def tokenize(a: String): Option[Array[String]] } + + + object StringTokenizer { + val NGram = com.rockymadden.stringmetric.tokenize.NGramTokenizer + + def tokenizeWithNGram(n: Int)(charArray: Array[Char]) = NGram(n).tokenize(charArray) + } } diff --git a/core/source/main/scala/com/rockymadden/stringmetric/package.scala b/core/source/main/scala/com/rockymadden/stringmetric/package.scala index 6752f4d..377fa7e 100755 --- a/core/source/main/scala/com/rockymadden/stringmetric/package.scala +++ b/core/source/main/scala/com/rockymadden/stringmetric/package.scala @@ -1,7 +1,10 @@ package com.rockymadden package object stringmetric { - type CompareTuple[T] = (Array[T], Array[T]) + import scala.language.implicitConversions + type CompareTuple[T] = (Array[T], Array[T]) type MatchTuple[T] = (Array[T], Array[T]) + + implicit def stringToArrayOfChar(s: String): Array[Char] = s.toCharArray } |