CmpStr - v3.2.1
    Preparing search index...

    Class PhoneticAbstract

    Abstract class representing a phonetic algorithm.

    The protected methods applyRules, encode, mapChar, equalLen, word2Chars, exitEarly, adjustCode, loop and loopAsync can be overridden in subclasses to implement specific phonetic algorithms.

    Hierarchy (View Summary)

    Index

    Constructors

    • Constructor for the Phonetic class.

      Initializes the phonetic algorithm with the specified options and mapping. Options hierarchy: User input > mapping options > default

      Parameters

      • algo: string

        The name of the algorithm (e.g. 'soundex')

      • Optionalopt: PhoneticOptions = {}

        Options for the phonetic algorithm

      Returns Phonetic

      • If the requested mapping is not declared

    Properties

    algo: string

    Phonetic algorithm name for identification

    Phonetic map and options for the algorithm

    optKey: string
    cache: HashTable<string, string> = ...

    Cache for indexed words to avoid redundant calculations

    Default phonetic options.

    This object contains default settings for phonetic algorithms, implemented in the subclass.

    Methods

    • Adjusts the phonetic code.

      Parameters

      • code: string

        The phonetic code to be adjusted

      • chars: string[]

        Characters to be removed from the code

      Returns string

      • The adjusted phonetic code
    • Applies patterns to a word based on the phonetic map.

      This method processes the word by applying all defined patterns in the phonetic map. It replaces occurrences of specified patterns with their corresponding replacements.

      Parameters

      • word: string

        The input word to be processed

      Returns string

      • The modified word after applying all patterns
    • Applies phonetic rules to a character in a word context.

      This method is designed to be generic and efficient for all phonetic algorithms. It checks all rule types (prev, next, prevNot, nextNot, position, etc.) and returns either the appropriate code (string) or undefined.

      Parameters

      • char: string

        The current character

      • i: number

        The current position within the word

      • chars: string[]

        The word as an array of characters

      • charLen: number

        The total length of the word

      Returns string | undefined

      • The rule code or undefined if no rule applies
    • Generates the phonetic code for a given word.

      This method processes the word character by character, applying phonetic rules and mappings to generate a phonetic code.

      Parameters

      • word: string

        The input word to be converted into a phonetic code

      Returns string

      • The generated phonetic code
    • Ensures the phonetic code has a fixed length by padding or truncating.

      Parameters

      • input: string

        The input string to be adjusted

      Returns string

      • The adjusted string with fixed length
    • Determines whether to exit early based on the current phonetic code length.

      Parameters

      • code: string

        The current phonetic code

      • i: number

        The current index in the word

      Returns boolean

      • True if the code length exceeds the specified limit, false otherwise
    • Get the name of the phonetic algorithm.

      Returns string

      • The name of the algorithm
    • Generates a phonetic index for the given input string.

      Parameters

      • input: string

        The input string to be indexed

      Returns string[]

      • An array of phonetic indices for the input words
    • Asynchronously generates a phonetic index for the given input string.

      Parameters

      • input: string

        The input string to be indexed

      Returns Promise<string[]>

      • A promise that resolves to an array of phonetic indices for the input words
    • Processes an array of words to generate their phonetic indices.

      This method iterates over each word, generates its phonetic code, and ensures that the resulting codes are of equal length.

      Parameters

      • words: string[]

        An array of words to be processed

      Returns string[]

      • An array of phonetic indices for the input words
    • Asynchronously processes an array of words to generate their phonetic indices.

      This method iterates over each word, generates its phonetic code asynchronously, and ensures that the resulting codes are of equal length.

      Parameters

      • words: string[]

        An array of words to be processed

      Returns Promise<string[]>

      • A promise that resolves to an array of phonetic indices for the input words
    • Converts a character to its phonetic code based on the mapping and rules.

      Parameters

      • char: string

        The current character

      • i: number

        The current position within the word

      • chars: string[]

        The word as an array of characters

      • charLen: number

        The total length of the word

      • lastCode: string | null

        The last code generated (to avoid duplicates)

      • map: Record<string, string>

        The phonetic mapping

      Returns string | undefined

      • The phonetic code or undefined if no code applies
    • Converts a word into an array of characters.

      Parameters

      • word: string

        The input word to be converted

      Returns string[]

      • An array of characters from the input word