GithubHelp home page GithubHelp logo

petar-dambovaliev / aho-corasick Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 10.0 689 KB

efficient string matching in Golang via the aho-corasick algorithm.

License: MIT License

Go 100.00%
aho-corasick string-matching golang-library text-search substring-search text-processing finate-state-machine

aho-corasick's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aho-corasick's Issues

Provide methods that accept `[]byte`.

Hi,

I really like the implementation but would love to have a FindAll(haystack []byte) and also a Build(patterns [][]byte). I saw that all patterns and haystacks are converted to []byte internally. What do you think about accepting []byte by default and have the string methods call these? E.g. FindAllByte(haystack []byte) and then FindAll(haystack string) { FindAllByte([]byte(haystack)) }.

go.mod request

could you please build a go.mod file so that I could download and manage it efficiently?

High memory usage compared to other implementation

Hi, I found this while looking for a lower memory usage alternative to anknown/ahocorasick.

I have a dataset of around 6 million strings. The total memory usage, as shown by pprof, after building the automaton is just over 30GB, compared to 6.5GB for the anknown version.

Do you have any tips for working out why it's using so much more RAM?

Thanks in advance.

Should Opts structs fields be exported ?

Hi, thanks for the work on this. I'm having a few issues with the Opts struct (I'm relatively new to Go). I seem to get an exported issue with it, so wondering if the fields should be in caps ?

Incorrect results when using overlapping patterns

I experience incorrect results when some of the patterns are overlapping in characters.
It only happens when the MatchOnlyWholeWords is option is true. (if set to true combined with matchKind standard, it results in only one match)
I expect the below test to pass.

func TestOverlappingPatterns(t *testing.T) {
	trieBuilder := aho_corasick.NewAhoCorasickBuilder(aho_corasick.Opts{
		MatchOnlyWholeWords: true,
		MatchKind: aho_corasick.LeftMostLongestMatch,
		DFA: false,
	})

	patterns := []string{"phonebook", "the phone"}

	trie := trieBuilder.Build(patterns)
	result := trie.FindAll("I'll look into the phonebook")
	if len(result) == 0 {
		t.Error("Did not find match in string")
		t.FailNow()
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.