UNPKG

fuzzy-rater

Version:

Tooling for fuzzily rating text according to some query

77 lines 2.76 kB
import { WordOrderMatcher } from "./orderMatcher/WordOrderMatcher"; 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; }[]; 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; }[]; /** * 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[]; /** * Computes all relevant match data for the given text * @param text The text to get match data for * @returns */ getMatch(text: string): IFuzzyMatch; /** * Retrieves the score for a given piece of text * @param text The text to be rated * @returns A score, where large 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