UNPKG

cmpstr

Version:

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

51 lines (50 loc) 1.93 kB
/** * Metaphone Phonetic Algorithm * src/phonetic/Metaphone.ts * * @see https://en.wikipedia.org/wiki/Metaphone * * Metaphone is a phonetic algorithm for indexing words by their English pronunciation. * It encodes words into a string of consonant symbols, allowing for the comparison of * words based on their pronunciation rather than their spelling. Metaphone is more * accurate than Soundex for English and is widely used in search, spell-checking, * and fuzzy matching. * * This implementation uses a mapping and a comprehensive ruleset to efficiently * transform input words into their Metaphone code. The algorithm drops or transforms * letters according to context-sensitive rules, and only retains vowels at the start. * * @module Phonetic/Metaphone * @author Paul Köhler (komed3) * @license MIT */ import type { PhoneticOptions } from '../utils/Types'; import { Phonetic } from './Phonetic'; /** * Metaphone class extends the Phonetic class to implement the Metaphone phonetic algorithm. */ export declare class Metaphone extends Phonetic { protected static default: PhoneticOptions; /** * Constructor for the Metaphone class. * * Initializes the Metaphone phonetic algorithm with the mapping and options. * * @param {PhoneticOptions} [opt] - Options for the Metaphone phonetic algorithm */ constructor(opt?: PhoneticOptions); /** * Generates the Metaphone code for a given word. * * @param {string} word - The input word to be converted into a Metaphone code * @returns {string} - The generated Metaphone code */ protected encode(word: string): string; /** * Adjusts the Metaphone code by removing vowels except for the first letter. * * @param {string} code - The Metaphone code to be adjusted * @returns {string} - The adjusted Metaphone code */ protected adjustCode(code: string): string; }