Levenshtein algorithm. The Levenshtein algorithm is a method for finding the minimum number of operations needed to transform a string into another string. The allowed operations are insertion, deletion, and substitution.

Implements

Constructors

Properties

options: LevenshteinOptions = ...

Methods

  • Calculate the Levenshtein distance between the start and end strings.

    Parameters

    • start: string

      The initial string.

    • end: string

      The resulting string.

    • dp: number[][]

      The matrix to store the distances.

    • path: undefined | Position[][] = undefined

      The matrix to store the path.

    Returns void

  • Calculate the matrix with the Levenshtein distance between the start and end strings.

    Parameters

    • start: string

      The initial string.

    • end: string

      The resulting string.

    • calculatePath: boolean = false

      Whether to calculate the path or not.

    Returns {
        dp: number[][];
        path?: Position[][];
    }

    The matrix with the distances and the path.

    • dp: number[][]
    • Optional path?: Position[][]
  • Compact the solution to merge the operations that can be done in a single step.

    Parameters

    • subSolution: Operation[]

      The list of operations to compact.

    Returns Operation[]

    The compacted list of operations.

  • Calculate differences between start string and end string and return the transformations list

    Parameters

    • startText: string

      The initial string.

    • endText: string

      The resulting string.

    Returns Operation[]

    The list of operations to transform the start string into the end string.

  • Utilize the Levenshtein algorithm to compute the distance between the start and end strings.

    Parameters

    • startText: string

      The initial string.

    • endText: string

      The resulting string.

    Returns number

    The Levenshtein distance between the two strings.