trie

package
v1.4.17 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Zlib Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Empty = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	No    string
	Text  string `xml:"text" json:"text"`
	Index int    `xml:"index" json:"index"`
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) Add

func (node *Node) Add(r rune, n *Node) *Node

func (*Node) Get

func (node *Node) Get(r rune) (*Node, bool)

func (*Node) IsLeaf

func (node *Node) IsLeaf() bool

IsLeaf 是否叶子节点

func (*Node) IsPathEnd

func (node *Node) IsPathEnd() bool

IsPathEnd 某个路径的结束

func (*Node) IsRoot

func (node *Node) IsRoot() bool

IsRoot 是否为根节点

func (*Node) SoftDel

func (node *Node) SoftDel()

SoftDel 置软删除状态

type Trie

type Trie struct {
	Root *Node
}

func NewTrie

func NewTrie() *Trie

func (*Trie) Add

func (tree *Trie) Add(word string) (no string)

Add 添加, return no 唯一的编号

func (*Trie) Del

func (tree *Trie) Del(word string)

func (*Trie) Filter

func (tree *Trie) Filter(text string) string

Filter 直接过滤掉字符串中的敏感词

func (*Trie) FindAll

func (tree *Trie) FindAll(text string) []*Group

FindAll 找有所有包含在词库中的词

func (*Trie) FindIn

func (tree *Trie) FindIn(text string) (bool, string)

func (*Trie) FindInReturnNo added in v1.1.29

func (tree *Trie) FindInReturnNo(text string) (bool, string, string)

FindInReturnNo 判断text中是否含有词库中的词

func (*Trie) Replace

func (tree *Trie) Replace(text string, character rune) string

Replace 词语替换

func (*Trie) Validate

func (tree *Trie) Validate(text string) (bool, string)

func (*Trie) ValidateReturnNo added in v1.1.29

func (tree *Trie) ValidateReturnNo(text string) (bool, string, string)

ValidateReturnNo 验证字符串是否合法,如不合法则返回false和检测到 的第一个敏感词

Jump to

Keyboard shortcuts

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