See the Wikipedia page on Edit distance

Levenshtein

See the Wikipedia page on Levenshtein distance

Imports and implicits

import org.jblas.DoubleMatrix

import cats.implicits._

import spire.implicits.IntAlgebra

import axle._
import axle.nlp._
import axle.nlp.Levenshtein
import axle.jblas._

implicit val laJblasInt = linearAlgebraDoubleMatrix[Int]
implicit val space = Levenshtein[IndexedSeq[Char], Char, DoubleMatrix, Int]()

Usage

space.distance("the quick brown fox", "the quik brown fax")
// res4: Int = 2

Usage with spire’s distance operator

Imports

import axle.algebra.wrappedStringSpace
import spire.syntax.metricSpace.metricSpaceOps

Usage

"the quick brown fox" distance "the quik brown fax"
// res5: Int = 2

"the quick brown fox" distance "the quik brown fox"
// res6: Int = 1

"the quick brown fox" distance "the quick brown fox"
// res7: Int = 0