Skip to content

Instantly share code, notes, and snippets.

@darkfrog26
Created June 8, 2015 18:32
Show Gist options
  • Save darkfrog26/b10a4ca9158ae681ea75 to your computer and use it in GitHub Desktop.
Save darkfrog26/b10a4ca9158ae681ea75 to your computer and use it in GitHub Desktop.
private def link(l1: List[String], l2: List[String]) = {
def findClosest(v: String) = l2.foldLeft((Int.MaxValue, ""))((current, item) => LevenshteinMetric.compare(v, item).getOrElse(Int.MaxValue) match {
case i if i <= current._1 => (i, item)
case _ => current
})
var items = Map.empty[String, String]
l1.foreach(v1 => findClosest(v1) match {
case (score, v2) => {
if (items.valuesIterator.contains(v2)) {
throw new RuntimeException(s"Duplicate matching of $v2 for both $v1 and ${items.find(t => t._2 == v1)}")
} else {
items += v1 -> v2
}
}
})
items
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment