UNPKG

fuzzy-rater

Version:

Tooling for fuzzily rating text according to some query

92 lines 3.39 kB
import { WordOrderMatcher } from "./orderMatcher/WordOrderMatcher"; import { IWordOrderMatchInput } from "./orderMatcher/_types/IWordOrderMatchInput"; import { FuzzyMultiWordMatcher } from "./wordMatcher/FuzzyMultiWordMatcher"; import { IFuzzyRateConfig } from "./_types/IFuzzyRaterConfig"; import { IFuzzyWordInput } from "./_types/IFuzzyWordsInput"; import { IFuzzyMatch } from "./_types/IFuzzyMatch"; import { IMatchGroup } from "./_types/IMatchGroup"; /** * The highest level fuzzy rater class, to rate how well text matches an input query */ export declare class FuzzyRater { protected config: Required<IFuzzyRateConfig>; protected query: Required<IFuzzyWordInput>[]; protected wordMatchers: { count: number; matcher: FuzzyMultiWordMatcher; words: Required<IFuzzyWordInput>[]; }[]; protected orderMatcher: WordOrderMatcher; /** * Creates a new fuzzy rater * @param query The query to be rate with * @param config The configuration for how to rate matches */ constructor(query: string | IFuzzyWordInput[], config?: IFuzzyRateConfig); /** * Initializes the rater's configuration * @param query The query input * @param config The config input * @returns The normalized query and config with defaults */ protected initializeInputs(query: string | IFuzzyWordInput[], config?: IFuzzyRateConfig): { query: Required<IFuzzyWordInput>[]; config: Required<IFuzzyRateConfig>; }; /** * Initializes the word matches * @returns The word matchers */ protected initializeWordMatchers(): { count: number; matcher: FuzzyMultiWordMatcher; words: Required<IFuzzyWordInput>[]; }[]; /** * Initializes the word order matcher * @returns The word matcher */ protected initializeOrderMatcher(): WordOrderMatcher; /** * Merges two match lists * @param m1 The first (sorted) match list * @param m2 The second (sorted) match list * @returns The combined, sorted, match list */ protected mergeMatches<T extends { index: number; }>(m1: T[], m2: T[]): T[]; /** * Retrieves the word matches for a given string * @param text The text to get the matches for * @returns The matches as well as some additional costs */ protected getWordMatches(text: string): { missingCost: number; extraBonus: number; matches: (IWordOrderMatchInput & { distance: number; })[]; }; /** * Computes all relevant match data for the given text * @param text The text to get match data for * @returns The fuzzy match data, including score and individual components */ getMatch(text: string): IFuzzyMatch; /** * Retrieves the score for a given piece of text * @param text The text to be rated * @returns A score, where larger is worse */ getScore(text: string): number; /** * Retrieves the match data that can be used for highlighting * @param text The text to be matched * @returns The scores including match data */ getMatchData(text: string): IFuzzyMatch & { matchGroups: IMatchGroup[]; }; } //# sourceMappingURL=FuzzyRater.d.ts.map