UNPKG

fuzzy-rater

Version:

Tooling for fuzzily rating text according to some query

50 lines 2.35 kB
import { IWordOrderMatchInput } from "./_types/IWordOrderMatchInput"; import { IWordOrderQueryWordInput } from "./_types/IWordOrderQueryWordInput"; import { IWordOrderMatch } from "./_types/IWordOrderMatch"; import { IWordOrderNode } from "./_types/IWordOrderNode"; /** * A class that can judge how well the matches match the order and spacing of the input query. * Uses an approach similar to the dynamic programming approach for computing levenshtein distance. */ export declare class WordOrderMatcher { protected words: IWordOrderQueryWordInput[]; protected table: IWordOrderNode[][]; /** * Creates a new word matcher * @param words The sequence of words to match, and how important each of them is */ constructor(words: IWordOrderQueryWordInput[]); /** * Creates a new word matcher * @param words The sequence of words to match * @param penalty How bad missing 1 word from the match is, in comparison to words being `penalty` characters apart * - penalty = Infinity: always prefer having all words present in sequence, no matter how far apart * - penalty = 0: always prefer having consecutive words, no matter if words are missing */ constructor(words: string[], penalty?: number); /** * Rates how well the given sequence of words matches the input sequence * @param matches The sequence of word matches * @returns How well the given input order matches */ getMatch(matches: IWordOrderMatchInput[]): number; /** * Rates how well the given sequence of words matches the input sequence * @param matches The sequence of word matches * @returns How well the given input order matches, and what the last considered word was */ protected findMatch(matches: IWordOrderMatchInput[]): { lastMatchIndex: number; distance: number; }; /** * Rates how well the given sequence of words matches the input sequence, and returns which were matched * @param matches The sequence of word matches * @returns How well the given input order matches, and the used matches */ getMatchData(matches: IWordOrderMatchInput[]): { distance: number; matches: IWordOrderMatch[]; }; } //# sourceMappingURL=WordOrderMatcher.d.ts.map