@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
45 lines (44 loc) • 1.71 kB
TypeScript
import { CandidateWithKeywords, Keyword, MatchType } from './keywords';
import { NormalizedUtterance } from './normalizer';
export declare const enum WordSimilarityAlgorithm {
LEVENSHTEIN = 0
}
export declare class WordsDistance {
readonly algorithm: WordSimilarityAlgorithm;
constructor(algorithm?: WordSimilarityAlgorithm);
distance(left: string, right: string): number;
}
export declare class SimilarWordResult<M> {
readonly candidate: M;
readonly keyword: Keyword;
readonly match: string;
readonly distance: number;
constructor(candidate: M, keyword: Keyword, match: string, distance: number);
/**
*
* @return < 0 if this is better than other
*/
compare(other: SimilarWordResult<M>): number;
}
/**
* It does not normalize case, ie. uppercase will be considered different than lowercase
*/
export declare class SimilarWordFinder<M> {
readonly wordsAreStemmed: boolean;
readonly minMatchLength: number;
private readonly candidates;
/**
* @param wordsAreStemmed see {@link StemmedExtraDistance}
* @param minMatchLength min number of characters that must match so that we tolerate non-identical matches
*/
constructor(wordsAreStemmed: boolean, minMatchLength?: number);
/**
*
* @param candidate may contain several words (eg. "buenos días")
*/
addCandidate(candidate: CandidateWithKeywords<M>): void;
private createFinder;
find(matchType: MatchType, utterance: NormalizedUtterance, maxDistance: number): SimilarWordResult<M>[];
private getLongestResultPerCandidate;
}
export declare function getMatchLength(utteranceLen: number, keywordLen: number, distance: number): number;