UNPKG

cmpstr

Version:

CmpStr is a lightweight, fast and well performing package for calculating string similarity

51 lines (50 loc) 1.94 kB
/** * Levenshtein Distance * src/metric/Levenshtein.ts * * @see https://en.wikipedia.org/wiki/Levenshtein_distance * * The Levenshtein distance is a classic metric for measuring the minimum number * of single-character edits (insertions, deletions, or substitutions) required * to change one string into another. * * It is widely used in approximate string matching, spell checking, and natural * language processing. * * @module Metric/LevenshteinDistance * @author Paul Köhler (komed3) * @license MIT */ import type { MetricInput, MetricOptions, MetricCompute } from '../utils/Types'; import { Metric } from './Metric'; export interface LevenshteinRaw { dist: number; maxLen: number; } /** * LevenshteinDistance class extends the Metric class to implement the Levenshtein distance algorithm. */ export declare class LevenshteinDistance extends Metric<LevenshteinRaw> { /** * Constructor for the Levenshtein class. * * Initializes the Levenshtein metric with two input strings * or arrays of strings and optional options. * * @param {MetricInput} a - First input string or array of strings * @param {MetricInput} b - Second input string or array of strings * @param {MetricOptions} [opt] - Options for the metric computation */ constructor(a: MetricInput, b: MetricInput, opt?: MetricOptions); /** * Calculates the Levenshtein distance between two strings. * * @param {string} a - First string * @param {string} b - Second string * @param {number} m - Length of the first string * @param {number} n - Length of the second string * @param {number} maxLen - Maximum length of the strings * @return {MetricCompute<LevenshteinRaw>} - Object containing the similarity result and raw distance */ protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<LevenshteinRaw>; }