fuzzy-rater
Version:
Tooling for fuzzily rating text according to some query
59 lines • 2.54 kB
TypeScript
import { IFuzzyNodeData } from "./_types/IFuzzyNodeData";
import { IFuzzyTransitionData } from "./_types/IFuzzyTransitionData";
import { IFuzzyWordMatch } from "./_types/IFuzzyWordMatch";
import { NFADFA } from "../DFA/NFADFA/NFADFA";
import { INFADFATrace } from "../DFA/NFADFA/_types/INFADFATrace";
/**
* 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 FuzzyMultiWordMatcher {
protected NFA: NFADFA<IFuzzyNodeData, IFuzzyTransitionData, IFuzzyNodeData>;
/**
* 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): {
endIndex: number;
distance: number;
}[];
/**
* Retrieves the best NFA trace given a DFA match
* @param nfaDfaTrace The simplified NFA-DFA trace to obtain the best NFA trace in (text matches with lowest distance)
* @returns The NFA trace
*/
protected getBestTrace(nfaDfaTrace: INFADFATrace<IFuzzyNodeData, IFuzzyTransitionData, IFuzzyNodeData>): {
fromNode: IFuzzyNodeData;
transition: IFuzzyTransitionData;
}[] | undefined;
/**
* 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 The distances from the query word, for each match (no distances = no matches), and how the text differed
*/
getMatchData(text: string): {
distances: number[];
alterations: IFuzzyWordMatch[];
};
}
//# sourceMappingURL=FuzzyMultiWordMatcher.d.ts.map