closewords
Version:
A library for finding the most similar word from a list of words, supporting Japanese (including kanji). / 最も似た単語を単語群から検索する日本語(漢字含む)対応のライブラリ
47 lines • 2.14 kB
text/typescript
//#region src/types.d.ts
/**
* An alphabetic string type (only A-Z, a-z, and hyphens are accepted).
* アルファベット文字列型(A-Z, a-z, ハイフンのみ許容)
*/
type AlphabeticString = string & {
__alphabeticBrand?: never;
};
/**
* A candidate object for similarity search.
* 類似度検索の候補オブジェクト
*/
interface Candidate {
/** The candidate word. / 候補単語 */
word: string;
/** Optional pronunciation hint in alphabetic form. / 任意のアルファベット読み仮名 */
pronounce?: AlphabeticString;
}
/**
* The result of a similarity comparison.
* 類似度比較の結果
*/
interface CloseWordsResult {
/** The candidate word. / 候補単語 */
word: string;
/** Similarity score from 0 to 1. / 類似度スコア(0〜1) */
score: number;
}
//#endregion
//#region src/index.d.ts
type WordInput = string | Candidate;
/**
* Finds the closest word(s) from candidates to the given reference word.
* Supports Japanese (including kanji via morphological analysis) and alphabetic strings.
*
* 与えられた単語に最も近い候補単語を返します。
* 日本語(漢字を含む形態素解析)およびアルファベット文字列に対応しています。
*
* @param word - Reference word or candidate object. / 比較対象の単語またはオブジェクト
* @param candidates - List of candidate words or objects. / 候補リスト
* @param raw - If true, returns all candidates with scores sorted descending. Default: false. / true のとき全候補をスコア降順で返す。デフォルト: false
* @returns When raw is false: word(s) with the highest score. When raw is true: all candidates with scores. / raw が false のとき最高スコアの単語配列、true のとき全候補のスコア付き配列
*/
declare function closeWords(word: WordInput, candidates: WordInput[], raw?: false): Promise<string[]>;
declare function closeWords(word: WordInput, candidates: WordInput[], raw: true): Promise<CloseWordsResult[]>;
//#endregion
export { type AlphabeticString, type Candidate, type CloseWordsResult, closeWords };