简体   繁体   中英

Metaphone or Soundex for Scala

I have found Apache's impelementation of Soundex and Metaphone in Java but I would prefer to keep the text comparison libraries I am using in Scala only if possible. Google searches have yielded me nothing useful in finding either of these algorithms in Scala.

Worst case scenario I can translate these algorithms into Scala but that is less than ideal.

http://commons.apache.org/codec/

Not to answer my own question or anything but a viable option would be to utilize a Java library and create some companion objects in scala to help expose them more appropriately and to allow to code to document itself more effectively.

//Metaphone companion object for org.apache.commons.codec.language.Metaphone in /lib/commons-codec-1.7
object Metaphone {
  val metaphone = new Metaphone
  metaphone setMaxCodeLen 5

  def encode(str:String) : String = {
    metaphone encode str
  }
}

Implementation:

val str_meta = Metaphone encode "Starbucks"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM