From 962c54ecedb81dd6db177ce743b8724e15f4ad8a Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Fri, 2 Nov 2012 08:22:33 -0600 Subject: Created convenience objects. --- .../hashtree/stringmetric/StringAlgorithm.scala | 29 ++++++++ .../org/hashtree/stringmetric/StringFilter.scala | 29 ++++++++ .../org/hashtree/stringmetric/StringMetric.scala | 78 ++++++++++++++++++++++ 3 files changed, 136 insertions(+) (limited to 'core') 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 -- cgit v1.2.3