lad

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 15 Imported by: 2

README

🪜 lad lad

一个敏感词过滤包,使用它你可以:

  • 判断文本中是否包含敏感词。
  • 查找文本中包含了哪些敏感词。
  • 将查找到的敏感词替换为指定的字符串。

目前支持中英文,后续打算添加对多音词支持。

特点

  • 目前保持0依赖的纯净模式 以后尽量保持

安装

go get github.com/23233/lad  

快速开始

添加模式串

machine := lad.New()
machine.Add("hello")
machine.Add("world")
machine.Build()

从文件中加载模式串,格式为一行一个词组

machine := lad.New()
if err := machine.Load("data path"); err != nil {
    t.Error(err)
}
machine.Build()

从文件夹中加载所有数据文件 仅支持.txt .data .dict后缀的文件 一行一个词组

//go:embed data/*
var folder embed.FS
machine := lad.New()
err := machine.LoadOfFolder(folder)
if err != nil {
    t.Fatal(err)
}
machine.Build()

匹配字符串

machine.Match(text)

查找字符串

machine.Find(text)

替换字符串

machine.Replacee(text,target)

性能

2017版macbook pro,2核8gb,1k个模式串,文本长度100个字符,benchmark结果如下。

goos: darwin
goarch: amd64
pkg: lad
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkAcMachine_Find
BenchmarkAcMachine_Find/find
BenchmarkAcMachine_Find/find-4         	  322304	      3736 ns/op

Todos

  • 添加模式串,构建ac自动机
  • 从文件中加载模式串,构建ac自动机
  • 匹配字符串
  • 支持英文
  • 支持多音字
  • 词组支持

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GetRemoteFail = errors.New("获取远程文件失败")
)

Functions

func New

func New() *acMachine

func NewAcNode

func NewAcNode(raw string) *acNode

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL