OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  glin-profanity:不当言论检测与内容审核库

glin-profanity:不当言论检测与内容审核库

 
  debug ·  2026-02-07 09:53:10 · 3 次点击  · 0 条评论  

名称: glin-profanity
描述: 用于脏话检测和内容审核的库,支持火星文(Leetspeak)、Unicode 同形字和基于机器学习的检测。适用于过滤用户生成内容、审核评论、检查文本是否包含脏话、屏蔽消息或在应用中集成内容审核功能。支持 24 种语言。


Glin Profanity - 内容审核库

脏话检测库,可识别规避检测的尝试,如火星文(f4cksh1t)、Unicode 欺骗(西里尔字母形似字)和混淆文本。

安装

# JavaScript/TypeScript
npm install glin-profanity

# Python
pip install glin-profanity

快速使用

JavaScript/TypeScript

import { checkProfanity, Filter } from 'glin-profanity';

// 简单检查
const result = checkProfanity("您的文本内容", {
  detectLeetspeak: true,
  normalizeUnicode: true,
  languages: ['english']
});

result.containsProfanity  // 布尔值
result.profaneWords       // 检测到的脏词数组
result.processedText      // 屏蔽后的版本

// 使用 Filter 实例
const filter = new Filter({
  replaceWith: '***',
  detectLeetspeak: true,
  normalizeUnicode: true
});

filter.isProfane("text")           // 布尔值
filter.checkProfanity("text")      // 完整结果对象

Python

from glin_profanity import Filter

filter = Filter({
    "languages": ["english"],
    "replace_with": "***",
    "detect_leetspeak": True
})

filter.is_profane("text")           # True/False
filter.check_profanity("text")      # 完整结果字典

React Hook

import { useProfanityChecker } from 'glin-profanity';

function ChatInput() {
  const { result, checkText } = useProfanityChecker({
    detectLeetspeak: true
  });

  return (
    <input onChange={(e) => checkText(e.target.value)} />
  );
}

主要特性

特性 说明
火星文检测 识别 f4cksh1t@$$ 等模式
Unicode 标准化 将西里尔字母 fսck 转换为 fuck
24 种语言支持 包括阿拉伯语、中文、俄语、印地语等
上下文白名单 支持医疗、游戏、技术等领域的特殊语境
机器学习集成 可选 TensorFlow.js 毒性检测
结果缓存 LRU 缓存提升性能

配置选项

const filter = new Filter({
  languages: ['english', 'spanish'],     // 要检查的语言
  detectLeetspeak: true,                 // 检测火星文(如 f4ck、sh1t)
  leetspeakLevel: 'moderate',            // basic(基础) | moderate(中等) | aggressive(严格)
  normalizeUnicode: true,                // 检测 Unicode 欺骗
  replaceWith: '*',                      // 替换字符
  preserveFirstLetter: false,            // f*** 与 **** 模式
  customWords: ['badword'],              // 添加自定义脏词
  ignoreWords: ['hell'],                 // 忽略(白名单)词汇
  cacheSize: 1000                        // LRU 缓存条目数
});

上下文感知分析

import { analyzeContext } from 'glin-profanity';

const result = analyzeContext("患者患有乳腺肿瘤", {
  domain: 'medical',        // medical(医疗) | gaming(游戏) | technical(技术) | educational(教育)
  contextWindow: 3,         // 匹配词周围考虑的词汇数
  confidenceThreshold: 0.7  // 标记的最小置信度
});

批量处理

import { batchCheck } from 'glin-profanity';

const results = batchCheck([
  "评论 1",
  "评论 2",
  "评论 3"
], { returnOnlyFlagged: true });

基于机器学习的检测(可选)

import { loadToxicityModel, checkToxicity } from 'glin-profanity/ml';

await loadToxicityModel({ threshold: 0.9 });

const result = await checkToxicity("你是最差的");
// { toxic: true, categories: { toxicity: 0.92, insult: 0.87 } }

常见使用模式

聊天/评论审核

const filter = new Filter({
  detectLeetspeak: true,
  normalizeUnicode: true,
  languages: ['english']
});

bot.on('message', (msg) => {
  if (filter.isProfane(msg.text)) {
    deleteMessage(msg);
    warnUser(msg.author);
  }
});

发布前内容验证

const result = filter.checkProfanity(userContent);

if (result.containsProfanity) {
  return {
    valid: false,
    issues: result.profaneWords,
    suggestion: result.processedText  // 屏蔽后的版本
  };
}

资源链接

  • 文档:https://www.typeweaver.com/docs/glin-profanity
  • 演示:https://www.glincker.com/tools/glin-profanity
  • GitHub:https://github.com/GLINCKER/glin-profanity
  • npm:https://www.npmjs.com/package/glin-profanity
  • PyPI:https://pypi.org/project/glin-profanity/
3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor