Skip to content
/ goac Public

An Aho-Corasick string matching lib implemented in Golang

Notifications You must be signed in to change notification settings

leesper/goac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

goac --- Aho-Corasick多模式字符串匹配算法Go语言实现

An Aho-Corasick multi-pattern string matching lib written in Golang

Author:

Leesper

Inspired by: pyAhocorasick

Usage Example

package goac
import "goac"

func TestAhoCorasick(t *testing.T) {
	content := "Aho-Corasick是一种基于Trie树的确定性有穷状态自动机算法"
	ac := NewAhoCorasick()
	ac.AddPattern("树")
	ac.AddPattern("自动机")
	ac.AddPattern("Trie")
	ac.AddPattern("基于")
	ac.Build()
	results := ac.Scan(content)
	fmt.Println("内容: " + content)
	fmt.Println("匹配词: ")
	for _, result := range results {
		fmt.Println(string([]rune(content)[result.Start : result.End+1]))
	}
}

[Output]
内容: Aho-Corasick是一种基于Trie树的确定性有穷状态自动机算法
匹配词: 
基于
Trie
树
自动机
PASS
ok  	goac	0.002s

About

An Aho-Corasick string matching lib implemented in Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages