
com.github.vickumar1981.stringdistance.impl.sound.SoundexImpl.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stringdistance_2.12 Show documentation
Show all versions of stringdistance_2.12 Show documentation
A fuzzy matching string distance library for Scala and Java.
The newest version!
package com.github.vickumar1981.stringdistance.impl.sound
import com.github.vickumar1981.stringdistance.interfaces.sound.CommonSoundAlgo._
import com.github.vickumar1981.stringdistance.interfaces.sound.SoundexAlgo
private[stringdistance] trait SoundexImpl {
private def compare(a: String, b: String): Option[Boolean] =
if (a.length == 0 || !isAlpha(a.head) || b.length == 0 || !isAlpha(b.head)) None
else if (a.head.toLower != b.head.toLower) Some(false)
else
SoundexAlgo.compute(a).filter(_.length > 0).flatMap { se1 =>
SoundexAlgo.compute(b).filter(_.length > 0).map(se1.sameElements(_))
}
protected def soundex(a: String, b: String): Boolean =
compare(a, b).getOrElse(false)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy