# Go敏感词过滤及中文分词 **Repository Path**: demo.cloud86.cn/segmentation-sensitive-words ## Basic Information - **Project Name**: Go敏感词过滤及中文分词 - **Description**: 敏感词过滤及中文分词 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-02-12 - **Last Updated**: 2025-02-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 敏感词过滤服务 基于 AC 自动机算法的高性能敏感词过滤和sego中文分词服务。 ## 功能特点 - 基于 AC 自动机的高效敏感词过滤 - 支持中文分词 - Redis 缓存支持 - MySQL 持久化存储 - 定时更新敏感词库 - 并发安全 ## 项目结构 ``` sensitiveWords/ ├── internal/ │ ├── ac/ │ │ └── automaton.go // AC自动机实现 │ ├── api/ │ │ ├── filter.go // 敏感词过滤接口 │ │ └── segment.go // 分词接口 │ ├── model/ │ │ └── types.go // 数据结构定义 │ └── storage/ │ ├── mysql.go // MySQL 操作 │ └── redis.go // Redis 操作 ├── main.go // 主程序入口 └── config.json // 配置文件 ``` ## API 接口 ### 1. 敏感词过滤 **请求:** - URL: `/api/filter` - 方法: `POST` - Content-Type: `application/x-www-form-urlencoded` **参数:** - `text`: 要检查的文本内容 - `clear_cache`: 是否清除缓存(可选,值为1时清除) **返回:** ```json { "original_text": "原始文本", "filtered_text": "过滤后的文本", "highlight_text": "带HTML标记的文本", "has_sensitive": true } ``` ### 2. 中文分词 **请求:** - URL: `/api/segment` - 方法: `POST` - Content-Type: `application/x-www-form-urlencoded` **参数:** - `text`: 要分词的文本内容 **返回:** ```json { "text": "原始文本", "words": ["分词", "结果", "数组"] } ``` ### 3. 配置文件 ```json { "database": { "host": "localhost", "port": 3306, "username": "user", "password": "pass", "dbname": "db", "charset": "utf8mb4" }, "server": { "port": 8080, "update_interval": 300 }, "log": { "level": "info", "file": "logs/app.log" }, "redis": { "host": "localhost", "port": 6379, "password": "", "db": 0 } } ``` ### 部署说明 #### 1.编译 ``` GOOS=linux GOARCH=amd64 go build -o fenci-api ``` #### 2. 准备配置文件 - 复制 config.json 到程序所在目录 - 修改数据库和Redis配置 #### 3. 准备词典文杰 - 确保 dictionary.txt 在程序所在目录 #### 4. 运行服务 ``` ./fenci-api ```