UNPKG

mstf-kit

Version:

一个现代化的 JavaScript/TypeScript 工具库,提供了丰富的常用工具函数

84 lines (83 loc) 2.68 kB
/** * 语言检测工具函数 */ /** * 判断文本是否为维吾尔语 * * @param text 要检测的文本 * @param threshold 判定为维吾尔语的字符比例阈值,默认0.4(40%) * @returns 是否为维吾尔语 * * @example * ```typescript * // 检查文本是否为维吾尔语 * const text = 'ياخشىمۇسىز، قانداق ئەھۋالىڭىز؟'; * const isUyghur = isUyghurText(text); * console.log(isUyghur); // true * * // 检查非维吾尔语文本 * const nonUyghurText = 'Hello, how are you?'; * console.log(isUyghurText(nonUyghurText)); // false * ``` */ export declare function isUyghurText(text: string, threshold?: number): boolean; /** * 从文本中提取维吾尔语部分 * * @param text 可能包含维吾尔语的混合文本 * @returns 提取出的维吾尔语文本数组 * * @example * ```typescript * // 提取混合文本中的维吾尔语部分 * const mixedText = '这段文字包含一些维吾尔语: ياخشىمۇسىز 和一些其他语言'; * const uyghurParts = extractUyghurText(mixedText); * console.log(uyghurParts); // ['ياخشىمۇسىز'] * ``` */ export declare function extractUyghurText(text: string): string[]; /** * 比较文本中维吾尔语和中文的字符比例 * * @param text 要分析的文本 * @param threshold 判定维吾尔语明显多于中文的比例阈值,默认1.5表示维吾尔语字符数量至少为中文的1.5倍 * @returns 分析结果对象 * * @example * ```typescript * // 比较中文和维吾尔语比例 * const mixedText = 'ياخشىمۇسىز 你好,这是一个测试'; * const result = compareUyghurAndChineseRatio(mixedText); * console.log(result); * // { * // uyghurCharCount: 10, * // chineseCharCount: 8, * // ratio: 1.25, * // isUyghurDominant: false, * // dominantScript: 'Balanced' * // } * ``` */ export declare function compareUyghurAndChineseRatio(text: string, threshold?: number): { uyghurCharCount: number; chineseCharCount: number; ratio: number; isUyghurDominant: boolean; dominantScript: 'Uyghur' | 'Chinese' | 'Balanced'; }; /** * 检测文本是否以维吾尔语为主 * * @param text 要检测的文本 * @param ratio 判定阈值,默认为1.5表示维吾尔语字符至少是中文字符的1.5倍 * @returns 是否以维吾尔语为主 * * @example * ```typescript * // 检查文本是否以维吾尔语为主 * const text = 'ياخشىمۇسىز، قانداق ئەھۋالىڭىز؟ 你好'; * const result = isUyghurDominant(text); * console.log(result); // true * ``` */ export declare function isUyghurDominant(text: string, ratio?: number): boolean;