mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-28 01:57:25 +08:00
120 lines
5.6 KiB
TypeScript
120 lines
5.6 KiB
TypeScript
/**
|
|
* 停用词表
|
|
* 用于过滤无意义的高频词
|
|
*/
|
|
|
|
/** 中文停用词 */
|
|
export const CHINESE_STOPWORDS = new Set([
|
|
// 代词
|
|
'我', '你', '他', '她', '它', '我们', '你们', '他们', '她们', '它们',
|
|
'自己', '别人', '大家', '谁', '什么', '哪', '哪里', '哪儿', '这', '那',
|
|
'这个', '那个', '这些', '那些', '这里', '那里', '这儿', '那儿', '这样', '那样',
|
|
// 助词
|
|
'的', '地', '得', '了', '着', '过', '吗', '呢', '吧', '啊',
|
|
'呀', '哇', '哦', '嗯', '噢', '喔', '呃', '唉', '哎', '嘛',
|
|
// 介词
|
|
'在', '从', '到', '向', '往', '把', '被', '给', '跟', '和',
|
|
'与', '对', '比', '为', '因', '由', '以', '按', '用', '让',
|
|
// 连词
|
|
'和', '与', '或', '或者', '而', '并', '并且', '但', '但是', '可是',
|
|
'然而', '不过', '只是', '如果', '要是', '假如', '虽然', '尽管', '即使', '所以',
|
|
'因此', '于是', '那么', '因为', '由于', '既然', '为了', '以便',
|
|
// 副词
|
|
'不', '没', '没有', '很', '太', '最', '更', '也', '都', '就',
|
|
'才', '又', '再', '还', '却', '只', '只是', '已', '已经', '曾',
|
|
'曾经', '正', '正在', '将', '将要', '会', '能', '可以', '可能', '应该',
|
|
'必须', '一定', '大概', '也许', '或许', '其实', '确实', '真的', '当然', '一直',
|
|
'总是', '经常', '常常', '往往', '偶尔', '几乎', '差不多', '简直', '反正', '终于',
|
|
// 量词
|
|
'个', '只', '条', '件', '位', '种', '些', '点', '下', '次',
|
|
// 数词
|
|
'一', '二', '三', '四', '五', '六', '七', '八', '九', '十',
|
|
'百', '千', '万', '亿', '两', '几', '多', '少', '第', '每',
|
|
// 动词(常见无实意动词)
|
|
'是', '有', '在', '做', '去', '来', '说', '看', '想', '要',
|
|
'能', '会', '让', '给', '叫', '用', '打', '把', '被', '到',
|
|
// 其他常见词
|
|
'上', '下', '前', '后', '里', '外', '中', '内', '左', '右',
|
|
'东', '南', '西', '北', '时', '时候', '现在', '今天', '明天', '昨天',
|
|
'年', '月', '日', '号', '点', '分', '秒', '周', '星期',
|
|
// 网络聊天常见无意义词
|
|
'好', '好的', '行', '可以', '嗯嗯', '哈', '呵', '额', '恩', '昂',
|
|
'ok', 'OK', '好吧', '知道', '知道了', '谢谢', '感谢', '抱歉', '不好意思',
|
|
// 语气词和程度词(虽然词性是名词/动词,但在聊天中无实际意义)
|
|
'感觉', '有点', '可能', '应该', '好像', '觉得', '认为', '看看', '看到',
|
|
'说', '问', '找', '弄', '搞', '搞定', '整', '干', '做', '来', '去',
|
|
'有', '没有', '没', '是不是', '有没有', '能不能', '会不会', '要不要',
|
|
'怎样', '如何', '为何', '为什么', '怎么', '怎么样', '怎么办',
|
|
'东西', '事情', '事', '问题', '时候', '地方', '情况', '样子', '意思',
|
|
'一下', '一点', '一些', '一样', '一起', '一直', '一般', '一定', '差不多',
|
|
])
|
|
|
|
/** 英文停用词 */
|
|
export const ENGLISH_STOPWORDS = new Set([
|
|
// Articles
|
|
'a', 'an', 'the',
|
|
// Pronouns
|
|
'i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves',
|
|
'you', 'your', 'yours', 'yourself', 'yourselves',
|
|
'he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself',
|
|
'it', 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves',
|
|
'what', 'which', 'who', 'whom', 'this', 'that', 'these', 'those',
|
|
// Prepositions
|
|
'in', 'on', 'at', 'by', 'for', 'with', 'about', 'against', 'between',
|
|
'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to',
|
|
'from', 'up', 'down', 'out', 'off', 'over', 'under', 'again', 'further',
|
|
// Conjunctions
|
|
'and', 'but', 'or', 'nor', 'so', 'yet', 'both', 'either', 'neither',
|
|
'not', 'only', 'own', 'same', 'than', 'too', 'very', 'just',
|
|
// Be verbs
|
|
'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
// Have verbs
|
|
'have', 'has', 'had', 'having',
|
|
// Do verbs
|
|
'do', 'does', 'did', 'doing',
|
|
// Modal verbs
|
|
'will', 'would', 'shall', 'should', 'can', 'could', 'may', 'might', 'must',
|
|
// Other common words
|
|
'if', 'then', 'else', 'when', 'where', 'why', 'how', 'all', 'each',
|
|
'every', 'both', 'few', 'more', 'most', 'other', 'some', 'such', 'no',
|
|
'any', 'now', 'here', 'there', 'of', 'as',
|
|
// Contractions (without apostrophe)
|
|
'dont', 'doesnt', 'didnt', 'wont', 'wouldnt', 'cant', 'couldnt',
|
|
'shouldnt', 'isnt', 'arent', 'wasnt', 'werent', 'havent', 'hasnt', 'hadnt',
|
|
// Chat common words
|
|
'ok', 'okay', 'yes', 'no', 'yeah', 'yep', 'nope', 'sure', 'thanks',
|
|
'thank', 'please', 'sorry', 'hi', 'hello', 'hey', 'bye', 'goodbye',
|
|
'well', 'like', 'know', 'think', 'want', 'need', 'get', 'got', 'go',
|
|
'going', 'come', 'coming', 'make', 'made', 'take', 'took', 'see', 'saw',
|
|
'look', 'looking', 'say', 'said', 'tell', 'told', 'ask', 'asked',
|
|
'let', 'put', 'keep', 'give', 'gave', 'find', 'found', 'try', 'tried',
|
|
// Time words
|
|
'today', 'tomorrow', 'yesterday', 'now', 'then', 'always', 'never',
|
|
'sometimes', 'often', 'usually', 'still', 'already', 'soon', 'later',
|
|
])
|
|
|
|
/**
|
|
* 获取停用词集合
|
|
* @param locale 语言
|
|
* @returns 停用词集合
|
|
*/
|
|
export function getStopwords(locale: string): Set<string> {
|
|
if (locale === 'zh-CN') {
|
|
return CHINESE_STOPWORDS
|
|
}
|
|
return ENGLISH_STOPWORDS
|
|
}
|
|
|
|
/**
|
|
* 判断是否为停用词
|
|
* @param word 词语
|
|
* @param locale 语言
|
|
* @returns 是否为停用词
|
|
*/
|
|
export function isStopword(word: string, locale: string): boolean {
|
|
const stopwords = getStopwords(locale)
|
|
// 英文统一转小写比较
|
|
const normalizedWord = locale === 'en-US' ? word.toLowerCase() : word
|
|
return stopwords.has(normalizedWord)
|
|
}
|