Created
June 8, 2015 18:32
-
-
Save darkfrog26/b10a4ca9158ae681ea75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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