wordsfilter

package module
v0.0.0-...-74232c7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: MIT Imports: 6 Imported by: 0

README

go-wordsfilter

A high performance text filter.

Download & Install

go get github.com/syyongx/go-wordsfilter

Quick Start

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)

LICENSE

go-wordsfilter source code is licensed under the MIT Licence.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlaceholder = "*"
View Source
var DefaultStripSpace = true

Functions

This section is empty.

Types

type Node

type Node struct {
	Child        map[string]*Node
	Placeholders string
}

func NewNode

func NewNode(child map[string]*Node, placeholders string) *Node

New creates a node.

type WordsFilter

type WordsFilter struct {
	Placeholder string
	StripSpace  bool
	// contains filtered or unexported fields
}

func New

func New() *WordsFilter

New creates a words filter.

func (*WordsFilter) Add

func (wf *WordsFilter) Add(text string, root map[string]*Node)

Add sensitive words to specified sensitive words Map.

func (*WordsFilter) Contains

func (wf *WordsFilter) Contains(text string, root map[string]*Node) bool

Whether the string contains sensitive words.

func (*WordsFilter) Generate

func (wf *WordsFilter) Generate(texts []string) map[string]*Node

Convert sensitive text lists into sensitive word tree nodes

func (*WordsFilter) GenerateWithFile

func (wf *WordsFilter) GenerateWithFile(path string) (map[string]*Node, error)

Convert sensitive text from file into sensitive word tree nodes. File content format, please wrap every sensitive word.

func (*WordsFilter) Remove

func (wf *WordsFilter) Remove(text string, root map[string]*Node)

Remove specified sensitive words from sensitive word map.

func (*WordsFilter) Replace

func (wf *WordsFilter) Replace(text string, root map[string]*Node) string

Replace sensitive words in strings and return new strings.

Jump to

Keyboard shortcuts

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