CmpStr - v3.2.1
    Preparing search index...

    DamerauLevenshteinDistance class extends the Metric class to implement the Damerau-Levenshtein algorithm.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    options: MetricOptions

    Options for the metric computation, such as performance tracking

    optKey: string
    symmetric: boolean

    Indicates whether the metric is symmetric (same result for inputs in any order)

    Methods

    • Clear the cached results of the metric.

      This method resets the results property to undefined, effectively clearing any previously computed results. It can be useful for re-running the metric with new inputs or options.

      Returns void

    • Calculates the normalized Damerau-Levenshtein distance between two strings.

      Parameters

      • a: string

        First string (always the shorter string for memory efficiency)

      • b: string

        Second string

      • m: number

        Length of the first string (a)

      • n: number

        Length of the second string (b)

      • maxLen: number

        Maximum length of the strings

      Returns MetricCompute<DamerauRaw>

      • Object containing the similarity result and raw distance
    • Check if the inputs are in batch mode.

      This method checks if either a or b contains more than one string, indicating that the metric is being run in batch mode.

      Returns boolean

      • True if either input is an array with more than one element
    • Check if the inputs are in pairwise mode.

      This method checks if both a and b are arrays of the same length, indicating that the metric is being run on corresponding pairs of strings.

      Parameters

      • Optionalsafe: boolean = false

        If true, does not throw an error if lengths are not equal

      Returns boolean

      • True if both inputs are arrays of equal length
      • If safe is false and the lengths of a and b are not equal
    • Check if the inputs are in single mode.

      This method checks if both a and b are single strings (not arrays), indicating that the metric is being run on a single pair of strings.

      Returns boolean

      • True if both inputs are single strings
    • Check if the metric is symmetrical.

      This method returns whether the metric is symmetric, meaning it produces the same result regardless of the order of inputs (e.g., Levenshtein distance).

      Returns boolean

      • True if the metric is symmetric
    • Pre-compute the metric for two strings. This method is called before the actual computation to handle trivial cases.

      Parameters

      • a: string

        First string

      • b: string

        Second string

      • m: number

        Length of the first string

      • n: number

        Length of the second string

      Returns MetricCompute<DamerauRaw> | undefined

      • Pre-computed result or undefined if not applicable
    • Run the metric computation based on the specified mode.

      Parameters

      • Optionalmode: MetricMode

        The mode to run the metric in (optional)

      • Optionalclear: boolean = true

        Whether to clear previous results before running

      Returns void

      • If an unsupported mode is specified
    • Run the metric computation based on the specified mode asynchronously.

      Parameters

      • Optionalmode: MetricMode

        The mode to run the metric in (optional)

      • Optionalclear: boolean = true

        Whether to clear previous results before running

      Returns Promise<void>

      • A promise that resolves when the metric computation is complete
      • If an unsupported mode is specified
    • Determine which mode to run the metric in.

      This method checks the provided mode or defaults to the mode specified in options. If no mode is specified, it defaults to 'default'.

      Parameters

      • Optionalmode: MetricMode

        The mode to run the metric in (optional)

      Returns MetricMode

      • The determined mode
    • Clamps the similarity result between 0 and 1.

      Parameters

      • res: number

        The input similarity to clamp

      Returns number

      • The clamped similarity (0 to 1)
    • Swaps two strings and their lengths if the first is longer than the second.

      Parameters

      • a: string

        First string

      • b: string

        Second string

      • m: number

        Length of the first string

      • n: number

        Length of the second string

      Returns [string, string, number, number]

      • Swapped strings and lengths