cmpstr
Version:
CmpStr is a lightweight, fast and well performing package for calculating string similarity
51 lines (50 loc) • 2.1 kB
TypeScript
/**
* Damerau-Levenshtein Distance
* src/metric/DamerauLevenshtein.ts
*
* @see https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance
*
* The Damerau-Levenshtein distance extends the classical Levenshtein algorithm by
* including transpositions (swapping of two adjacent characters) as a single edit
* operation, in addition to insertions, deletions, and substitutions.
*
* This metric is particularly useful for detecting and correcting common
* typographical errors.
*
* @module Metric/DamerauLevenshtein
* @author Paul Köhler (komed3)
* @license MIT
*/
import type { MetricInput, MetricOptions, MetricCompute } from '../utils/Types';
import { Metric } from './Metric';
export interface DamerauRaw {
dist: number;
maxLen: number;
}
/**
* DamerauLevenshteinDistance class extends the Metric class to implement the Damerau-Levenshtein algorithm.
*/
export declare class DamerauLevenshteinDistance extends Metric<DamerauRaw> {
/**
* Constructor for the DamerauLevenshteinDistance class.
*
* Initializes the Damerau-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 normalized Damerau-Levenshtein distance between two strings.
*
* @param {string} a - First string (always the shorter string for memory efficiency)
* @param {string} b - Second string
* @param {number} m - Length of the first string (a)
* @param {number} n - Length of the second string (b)
* @param {number} maxLen - Maximum length of the strings
* @return {MetricCompute<DamerauRaw>} - Object containing the similarity result and raw distance
*/
protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<DamerauRaw>;
}