diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-09 14:56:37 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-09 14:56:37 -0700 |
commit | 5ab7c2fb4ad21454de703c75b77b94cc6ef11355 (patch) | |
tree | 26455288c3130e56571cd324a5e8ef794d16bb97 /core | |
parent | 77d0cefc76a69c026970c0e03822b71e2ecdfdbf (diff) | |
download | stringmetric-5ab7c2fb4ad21454de703c75b77b94cc6ef11355.tar.gz stringmetric-5ab7c2fb4ad21454de703c75b77b94cc6ef11355.tar.bz2 stringmetric-5ab7c2fb4ad21454de703c75b77b94cc6ef11355.zip |
Created N-Gram convienience methods.
Diffstat (limited to 'core')
-rwxr-xr-x | core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala | 9 | ||||
-rwxr-xr-x | core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala b/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala index 5c90152..d736458 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringAlgorithm.scala @@ -1,6 +1,7 @@ package org.hashtree.stringmetric import org.hashtree.stringmetric.phonetic.{ MetaphoneAlgorithm, NysiisAlgorithm, RefinedSoundexAlgorithm, SoundexAlgorithm } +import org.hashtree.stringmetric.similarity.NGramAlgorithm /** Marks those which leverage traits of a string based [[org.hashtree.stringmetric.Algorithm]]. */ trait StringAlgorithm extends Algorithm[String] { @@ -15,6 +16,12 @@ object StringAlgorithm { def computeMetaphone(string: String)(implicit stringFilter: StringFilter): Option[String] = MetaphoneAlgorithm.compute(string)(stringFilter) + def computeNGram(charArray: Array[Char])(n: Int)(implicit stringFilter: StringFilter): Option[Array[Array[Char]]] = + NGramAlgorithm.compute(charArray)(n)(stringFilter) + + def computeNGram(string: String)(n: Int)(implicit stringFilter: StringFilter): Option[Array[String]] = + NGramAlgorithm.compute(string)(n)(stringFilter) + def computeNysiis(charArray: Array[Char])(implicit stringFilter: StringFilter): Option[Array[Char]] = NysiisAlgorithm.compute(charArray)(stringFilter) @@ -35,6 +42,8 @@ object StringAlgorithm { def metaphone: MetaphoneAlgorithm.type = MetaphoneAlgorithm + def nGram: NGramAlgorithm.type = NGramAlgorithm + def nysiis: NysiisAlgorithm.type = NysiisAlgorithm def refinedSoundex: RefinedSoundexAlgorithm.type = RefinedSoundexAlgorithm diff --git a/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala b/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala index ccc1ced..9cabb82 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/StringMetric.scala @@ -1,7 +1,7 @@ package org.hashtree.stringmetric import org.hashtree.stringmetric.phonetic.{ MetaphoneMetric, NysiisMetric, RefinedSoundexMetric, SoundexMetric } -import org.hashtree.stringmetric.similarity.{ DiceSorensenMetric, HammingMetric, JaroMetric, JaroWinklerMetric, LevenshteinMetric, WeightedLevenshteinMetric } +import org.hashtree.stringmetric.similarity._ /** Marks those which leverage traits of a string based [[org.hashtree.stringmetric.Metric]]. */ trait StringMetric extends Metric[String] { @@ -46,6 +46,12 @@ object StringMetric { def compareMetaphone(string1: String, string2: String)(implicit stringFilter: StringFilter): Option[Boolean] = MetaphoneMetric.compare(string1, string2)(stringFilter) + def compareNGram(charArray1: Array[Char], charArray2: Array[Char])(n: Int)(implicit stringFilter: StringFilter): Option[Double] = + NGramMetric.compare(charArray1, charArray2)(n)(stringFilter) + + def compareNGram(string1: String, string2: String)(n: Int)(implicit stringFilter: StringFilter): Option[Double] = + NGramMetric.compare(string1, string2)(n)(stringFilter) + def compareNysiis(charArray1: Array[Char], charArray2: Array[Char])(implicit stringFilter: StringFilter): Option[Boolean] = NysiisMetric.compare(charArray1, charArray2)(stringFilter) @@ -84,6 +90,8 @@ object StringMetric { def metaphone: MetaphoneMetric.type = MetaphoneMetric + def nGram: NGramMetric.type = NGramMetric + def nysiis: NysiisMetric.type = NysiisMetric def refinedSoundex: RefinedSoundexMetric.type = RefinedSoundexMetric |