UNPKG

fuzzy-rater

Version:

Tooling for fuzzily rating text according to some query

71 lines 2.8 kB
import { INormalizedNFANode } from "./_types/INormalizedNFANode"; import { INormalizedNFATemplate } from "./_types/INormalizedNFATemplate"; import { INormalizedNFATransition } from "./_types/INormalizedNFATransition"; import { INFATrace } from "./_types/INFATrace"; export declare const emptyCode = "et"; /** * A class to represent non-deterministic finite automata and their operations */ export declare class NFA<N, T> { protected nodes: INormalizedNFANode<N, T>[]; protected transitions: Record<string, number[]>[]; protected traceTransitions: Record<string, { state: number; metadata: T; }[]>[]; protected initial: number[]; /** * Creates a new nfa according to the given specification * @param template The nfa template */ constructor(template: INormalizedNFATemplate<N, T>); /** * Retrieves the character code of a given transition * @param transition The transition to get a code for the transition character for * @returns The character code */ protected getCharacterCode(transition: INormalizedNFATransition<T>): string; /** * Initializes the NFA structure * @param template The NFA template */ protected initialize(template: INormalizedNFATemplate<N, T>): void; /** * Executes the NFA on the given input, and returns the metadata of the final node, if any * @param input The input to execute the NFA on * @returns The metadata of the states teh automaton finished in */ execute(input: string): N[]; /** * Follows empty transitions from a node, and adds * @param nodes The indices of the nodes for which to follow the empty transitions * @returns The indices of all nodes reachable in 0 steps */ protected followEmptyTransitions(nodes: number[]): number[]; /** * Executes the NFA on the given input, and returns the metadata of the trace. * If multiple paths to the same final state exist, only a single path is returned * @param input The input to execute the NFA on * @returns The metadata of the states teh automaton finished in */ executeTraced(input: string): INFATrace<N, T>[]; /** * Follows empty transitions from a node, and adds * @param nodes The indices of the nodes for which to follow the empty transitions * @returns The indices of all nodes reachable in 0 steps */ protected followEmptyTransitionsTraced(nodes: { node: number; path: { node: number; transition: T; }[]; }[]): { node: number; path: { node: number; transition: T; }[]; }[]; } //# sourceMappingURL=NFA.d.ts.map