ahocorasick

package module
v0.0.0-...-45c8304 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: MIT Imports: 1 Imported by: 2

README

ahocorasick

Aho-Corasick string matching algorithm for golang

package main

import (
	"fmt"
	"github.com/gansidui/ahocorasick"
)

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

	dictionary := []string{"hello", "world", "世界", "google", "golang", "c++", "love"}

	ac.Build(dictionary)

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

	for _, term := range ret {
		fmt.Printf("%d %s\n", term.EndPosition-len(dictionary[term.Index])+1, dictionary[term.Index])
	}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

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

func BuildNewMatcher

func BuildNewMatcher(dictionary []string) *Matcher

func NewMatcher

func NewMatcher() *Matcher

func (*Matcher) Build

func (m *Matcher) Build(dictionary []string)

initialize the ahocorasick

func (*Matcher) GetMatchResultSize

func (m *Matcher) GetMatchResultSize(s string) int

just return the number of len(Match(s))

func (*Matcher) Match

func (m *Matcher) Match(s string) []*Term

string match search return all strings matched as indexes into the original dictionary and their positions on matched string

type Term

type Term struct {
	Index       int
	EndPosition int
}

Jump to

Keyboard shortcuts

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