Skip to content

gansidui/ahocorasick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ahocorasick

Aho-Corasick string matching algorithm for golang

package main

import (
	"fmt"
	"log"

	"github.com/gansidui/ahocorasick"
)

func main() {
	ac := ahocorasick.NewMatcher()

	dictionary := []string{"hello", "world", "世界", "google", "golang", "c++", "love"}
	ac.Build(dictionary)

	s := "hello世界, hello google, i love golang!!!"
	ret := ac.Match(s)

	for i, _ := range ret {
		original := dictionary[ret[i].Index]
		matched := s[ret[i].EndPosition-len(original) : ret[i].EndPosition]
		if original != matched {
			log.Fatal()
		}
		fmt.Println(original, matched)
	}
}

LICENSE

MIT

About

Aho-Corasick string matching algorithm for golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages