acor

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2017 License: MIT Imports: 8 Imported by: 0

README

ACOR (Aho-Corasick automation On Redis)

Golang implementation of Aho-Corasick algorithm, working on redis

Current Release Build Status godoc license

Prerequisite

  • Golang 1.7+
  • Redis 3.x+
  • (Optional) Docker

Redis docker container

If there is no redis docker image, import the image and run the docker container.

$ sh run-redis.sh

Usage

package main

import (
	"fmt"
	"github.com/skyoo2003/acor"
)

func main() {
	args := &acor.AhoCorasickArgs{
		Addr:     "localhost:6379",
		Password: "",
		DB:       0,
		Name:     "sample",
	}
	ac := acor.Create(args)
	defer ac.Close()

	keywords := []string{"he", "her", "him"}
	for _, k := range keywords {
		ac.Add(k)
	}

	matched := ac.Find("he is him")
	fmt.Println(matched)

    ac.Flush() // If you want to remove all of data 
}

Contribution

If you want to participate, you can create an issue or request a 'Pull Request'.

Welcome any and all suggestions.

License

MIT License

Documentation

Index

Constants

View Source
const (
	KeywordKey = "%s:keyword"
	PrefixKey  = "%s:prefix"
	SuffixKey  = "%s:suffix"
	OutputKey  = "%s:output"
	NodeKey    = "%s:node"
)

Key type constants

Variables

View Source
var (
	RedisAlreadyClosed = errors.New("redis client was already closed")
)

Functions

func Reverse

func Reverse(s string) string

Types

type AhoCorasick

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

func Create

func Create(args *AhoCorasickArgs) *AhoCorasick

func (*AhoCorasick) Add

func (ac *AhoCorasick) Add(keyword string) int

func (*AhoCorasick) Close

func (ac *AhoCorasick) Close() error

func (*AhoCorasick) Debug

func (ac *AhoCorasick) Debug()

func (*AhoCorasick) Find

func (ac *AhoCorasick) Find(text string) []string

func (*AhoCorasick) Flush

func (ac *AhoCorasick) Flush()

func (*AhoCorasick) Info

func (ac *AhoCorasick) Info() *AhoCorasickInfo

func (*AhoCorasick) Remove

func (ac *AhoCorasick) Remove(keyword string) int

func (*AhoCorasick) Suggest

func (ac *AhoCorasick) Suggest(input string) []string

type AhoCorasickArgs

type AhoCorasickArgs struct {
	Addr     string // redis server address (ex) localhost:6379
	Password string // redis password
	DB       int    // redis db number
	Name     string // pattern's collection name
	Debug    bool   // debug flag
}

type AhoCorasickInfo

type AhoCorasickInfo struct {
	Keywords int // Aho-Corasick keywords count
	Nodes    int //Aho-Corasick nodes count
}

Jump to

Keyboard shortcuts

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