diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-02 08:22:33 -0600 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-02 08:22:33 -0600 |
commit | 962c54ecedb81dd6db177ce743b8724e15f4ad8a (patch) | |
tree | 443be43f2a85bde9775d62c8abf11d71c02aa175 /core | |
parent | faf482718de0716951f01eacd8d9b9601426e666 (diff) | |
download | stringmetric-962c54ecedb81dd6db177ce743b8724e15f4ad8a.tar.gz stringmetric-962c54ecedb81dd6db177ce743b8724e15f4ad8a.tar.bz2 stringmetric-962c54ecedb81dd6db177ce743b8724e15f4ad8a.zip |
Created convenience objects.
Diffstat (limited to 'core')
3 files changed, 136 insertions, 0 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala index c6bb499..0878ea2 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala @@ -1,6 +1,35 @@ package org.hashtree.stringmetric +import org.hashtree.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm } + /** Marks those which leverage traits of a string based [[org.hashtree.stringmetric.Algorithm]]. */ trait StringAlgorithm extends Algorithm[String, StringFilter] { def compute(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] +} + +/** Convenience object for those extending [[org.hashtree.stringmetric.StringAlgorithm]]. */ +object StringAlgorithm { + def computeMetaphone(charArray: Array[Char]): Option[Array[Char]] = MetaphoneAlgorithm.compute(charArray) + + def computeMetaphone(string: String): Option[String] = MetaphoneAlgorithm.compute(string) + + def computeNysiis(charArray: Array[Char]): Option[Array[Char]] = NysiisAlgorithm.compute(charArray) + + def computeNysiis(string: String): Option[String] = NysiisAlgorithm.compute(string) + + def computeRefinedSoundex(charArray: Array[Char]): Option[Array[Char]] = RefinedSoundexAlgorithm.compute(charArray) + + def computeRefinedSoundex(string: String): Option[String] = RefinedSoundexAlgorithm.compute(string) + + def computeSoundex(charArray: Array[Char]): Option[Array[Char]] = SoundexAlgorithm.compute(charArray) + + def computeSoundex(string: String): Option[String] = SoundexAlgorithm.compute(string) + + def metaphone: MetaphoneAlgorithm.type = MetaphoneAlgorithm + + def nysiis: NysiisAlgorithm.type = NysiisAlgorithm + + def refinedSoundex: RefinedSoundexAlgorithm.type = RefinedSoundexAlgorithm + + def soundex: SoundexAlgorithm.type = SoundexAlgorithm }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringFilter.scala b/core/source/core/scala/org/hashtree/stringmetric/StringFilter.scala index 6d2b532..6f45b02 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringFilter.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringFilter.scala @@ -1,6 +1,35 @@ package org.hashtree.stringmetric +import org.hashtree.stringmetric.filter._ + /** Marks those which leverage traits of a string based [[org.hashtree.stringmetric.Filter]]. */ trait StringFilter extends Filter[String] { def filter(charArray: Array[Char]): Array[Char] +} + +/** Convenience object for those extending [[org.hashtree.stringmetric.StringFilter]]. */ +object StringFilter { + def asciiControl = new StringFilterDelegate with AsciiControlStringFilter + + def asciiControlOnly = new StringFilterDelegate with AsciiControlOnlyStringFilter + + def asciiLetterCase = new StringFilterDelegate with AsciiLetterCaseStringFilter + + def asciiLetterNumber = new StringFilterDelegate with AsciiLetterNumberStringFilter + + def asciiLetterNumberOnly = new StringFilterDelegate with AsciiLetterNumberOnlyStringFilter + + def asciiLetter = new StringFilterDelegate with AsciiLetterStringFilter + + def asciiLetterOnly = new StringFilterDelegate with AsciiLetterOnlyStringFilter + + def asciiNumber = new StringFilterDelegate with AsciiNumberStringFilter + + def asciiNumberOnly = new StringFilterDelegate with AsciiNumberOnlyStringFilter + + def asciiSpace = new StringFilterDelegate with AsciiSpaceStringFilter + + def asciiSymbol = new StringFilterDelegate with AsciiSymbolStringFilter + + def asciiSymbolOnly = new StringFilterDelegate with AsciiSymbolOnlyStringFilter }
\ No newline at end of file diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala index 5d4d68b..5cd5f69 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala @@ -1,6 +1,84 @@ package org.hashtree.stringmetric +import org.hashtree.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric } +import org.hashtree.stringmetric.similarity.{ DiceSorensenMetric, HammingMetric, JaroMetric, JaroWinklerMetric, LevenshteinMetric } + /** Marks those which leverage traits of a string based [[org.hashtree.stringmetric.Metric]]. */ trait StringMetric extends Metric[String, StringFilter] { def compare(charArray1: Array[Char], charArray2: Array[Char])(implicit stringFilter: StringFilter): Option[AnyVal] +} + +/** Convenience object for those extending [[org.hashtree.stringmetric.StringMetric]]. */ +object StringMetric { + def compareDiceSorensen(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = + DiceSorensenMetric.compare(charArray1, charArray2) + + def compareDiceSorensen(string1: String, string2: String): Option[Double] = + DiceSorensenMetric.compare(string1, string2) + + def compareHamming(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = + HammingMetric.compare(charArray1, charArray2) + + def compareHamming(string1: String, string2: String): Option[Int] = + HammingMetric.compare(string1, string2) + + def compareJaro(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = + JaroMetric.compare(charArray1, charArray2) + + def compareJaro(string1: String, string2: String): Option[Double] = + JaroMetric.compare(string1, string2) + + def compareJaroWinkler(charArray1: Array[Char], charArray2: Array[Char]): Option[Double] = + JaroWinklerMetric.compare(charArray1, charArray2) + + def compareJaroWinkler(string1: String, string2: String): Option[Double] = + JaroWinklerMetric.compare(string1, string2) + + def compareLevenshtein(charArray1: Array[Char], charArray2: Array[Char]): Option[Int] = + LevenshteinMetric.compare(charArray1, charArray2) + + def compareLevenshtein(string1: String, string2: String): Option[Int] = + LevenshteinMetric.compare(string1, string2) + + def compareMetaphone(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = + MetaphoneMetric.compare(charArray1, charArray2) + + def compareMetaphone(string1: String, string2: String): Option[Boolean] = + MetaphoneMetric.compare(string1, string2) + + def compareNysiis(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = + NysiisMetric.compare(charArray1, charArray2) + + def compareNysiis(string1: String, string2: String): Option[Boolean] = + NysiisMetric.compare(string1, string2) + + def compareRefinedSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = + RefinedSoundexMetric.compare(charArray1, charArray2) + + def compareRefinedSoundex(string1: String, string2: String): Option[Boolean] = + RefinedSoundexMetric.compare(string1, string2) + + def compareSoundex(charArray1: Array[Char], charArray2: Array[Char]): Option[Boolean] = + SoundexMetric.compare(charArray1, charArray2) + + def compareSoundex(string1: String, string2: String): Option[Boolean] = + SoundexMetric.compare(string1, string2) + + 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 nysiis: NysiisMetric.type = NysiisMetric + + def refinedSoundex: RefinedSoundexMetric.type = RefinedSoundexMetric + + def soundex: SoundexMetric.type = SoundexMetric }
\ No newline at end of file |