高性能的 Go 敏感词过滤器 go-wordsfilter

码农软件 · 软件分类 · 其他开发相关 · 2019-10-16 09:59:25

软件介绍

go-wordsfilter 是一个高性能的 Go 敏感词过滤器,通过预先读取敏感词源并构建树状结构数据的方式来高效地检测和替换敏感词。采用 MIT 开源协议。

下载安装

go get github.com/syyongx/go-wordsfilter

快速开始

import (
    "github.com/syyongx/go-wordsfilter"
)

func main() {
    texts := []string{
        "Miyamoto Musashi",
        "妲己",
        "アンジェラ",
        "ความรุ่งโรจน์",
    }
    wf := wordsfilter.New()

    // Generate
    root := wf.Generate(texts)
    // Generate with file
    // root := wf.GenerateWithFile(path)

    // Contains
    c1 := wf.Contains("アン", root)
    // c1: false
    c2 := wf.Contains("アンジェラ", root)
    // c2: true

    // Remove
    wf.Remove("アンジェラ", root)
    c3 := wf.Contains("アンジェラ", root)
    // c3: false

    // Replace
    r1 := wf.Replace("Game ความรุ่งโรจน์ i like 妲己 heroMiyamotoMusashi", root)
    // r1: Game*************ilike**hero***************
}

Apis

New() *WordsFilter
Generate(texts []string) map[string]*Node
GenerateWithFile(path string) (map[string]*Node, error)
Add(text string, root map[string]*Node)
Replace(text string, root map[string]*Node) string
Contains(text string, root map[string]*Node) bool
Remove(text string, root map[string]*Node)

本文地址:https://codercto.com/soft/d/16868.html

数据结构与算法经典问题解析

数据结构与算法经典问题解析

纳拉辛哈·卡鲁曼希 / 骆嘉伟 / 机械工业出版社 / 2016-6-1 / CNY 79.00

本书是一本数据结构方面的优秀教材,以Java为描述语言,介绍了计算机编程中使用的数据结构和算法。本书强调问题及其分析,而非理论阐述,共分为21章,讲述了基本概念、递归和回溯、链表、栈、队列、树、优先队列和堆、并查集DAT、图算法、排序、查找、选择算法(中位数)、符号表、散列、字符串算法、算法设计技术、贪婪算法、分治算法、动态规划算法、复杂度类型等内容。每章首先阐述必要的理论基础,然后给出问题集。全......一起来看看 《数据结构与算法经典问题解析》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试