UNPKG

cmpstr

Version:

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

51 lines (50 loc) 1.91 kB
/** * Longest Common Subsequence (LCS) * src/metric/LCS.ts * * @see https://en.wikipedia.org/wiki/Longest_common_subsequence * * The Longest Common Subsequence (LCS) metric measures the length of the longest * subsequence common to both strings. Unlike substrings, the characters of a * subsequence do not need to be contiguous, but must appear in the same order. * * The LCS is widely used in diff tools, bioinformatics, and approximate string * matching. * * @module Metric/LCS * @author Paul Köhler (komed3) * @license MIT */ import type { MetricInput, MetricOptions, MetricCompute } from '../utils/Types'; import { Metric } from './Metric'; export interface LCSRaw { lcs: number; maxLen: number; } /** * LCSMetric class extends the Metric class to implement the Longest Common Subsequence algorithm. */ export declare class LCSMetric extends Metric<LCSRaw> { /** * Constructor for the LCSMetric class. * * Initializes the LCS 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 LCS similarity 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<LCSRaw>} - Object containing the similarity result and raw LCS length */ protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<LCSRaw>; }