UNPKG

fuzzy-rater

Version:

Tooling for fuzzily rating text according to some query

45 lines 1.93 kB
import { IFuzzyNodeData } from "./_types/IFuzzyNodeData"; import { IFuzzyTransitionData } from "./_types/IFuzzyTransitionData"; import { IFuzzyWordMatch } from "./_types/IFuzzyWordMatch"; import { NFADFA } from "../DFA/NFADFA/NFADFA"; /** * A fuzzy word matcher that can be used to find a word in a number of items. * Initial setup time is relatively long, but matching per string happens in linear time. */ export declare class FuzzyWordMatcher { protected NFA: NFADFA<IFuzzyNodeData, IFuzzyTransitionData>; /** * Constructs a new fuzzy word rater * @param word The word to look for * @param maxDistance The maximum error */ constructor(word: string, maxDistance: number); /** * Initializes the data structures used for rating * @param word The word to look for * @param maxDistance The maximal allowed distance */ protected initialize(word: string, maxDistance: number): void; /** * Finds the best match in a set of NFA nodes * @param matches The nodes to find the best match in * @param getNode Retrieves the node data * @returns The best match */ protected getBestMatch<M>(matches: M[], getNode: (data: M) => IFuzzyNodeData): M | undefined; /** * Retrieves the best match in the given text * @param text The text to find the query word in * @returns Whether the text matched, and the distance from the query word */ getMatch(text: string): IFuzzyNodeData; /** * Retrieves the best match in the given text, and data of how to obtain it * @param text The text to find the query word in * @returns Whether the text matched, and the distance from the query word, and how the text differed */ getMatchData(text: string): IFuzzyNodeData & { alterations: IFuzzyWordMatch[]; }; } //# sourceMappingURL=FuzzyWordMatcher.d.ts.map