8000 GitHub - BlackRabbitt/mspm: Multi-String Pattern Matching Algorithm Using TrieNode · GitHub
[go: up one dir, main page]

Skip to content
BlackRabbittPublic

About

Multi-String Pattern Matching Algorithm Using TrieNode

Topics

Resources

Stars

30 stars

Watchers

2 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mspm

mspm is a Go library for matching a set of literal byte-string patterns in a document and counting the matches. It uses a trie and is inspired by the Aho–Corasick algorithm.

Status: This project is being revived. The current implementation is small and has known limitations; review the behavior below before using it for production workloads.

Requirements

  • Go 1.27 or newer

Install

go get github.com/BlackRabbitt/mspm

The matcher API currently lives in the search package:

import "github.com/BlackRabbitt/mspm/search"

Example

package main

import (
	"fmt"
	"strings"

	"github.com/BlackRabbitt/mspm/search"
)

func main() {
	model := search.NewModel("keywords")
	model.Build(strings.NewReader("mspm\npattern\nsearch\n"))

	counts, err := model.MultiTermMatch(strings.NewReader("mspm pattern search mspm"))
	if err != nil {
		panic(err)
	}

	fmt.Println(counts["mspm"])    // 2
	fmt.Println(counts["pattern"]) // 1
	fmt.Println(counts["search"])  // 1
}

Patterns are supplied one per line to Build. Matching is case-sensitive. MultiTermMatch 63B7 reads the document and returns counts keyed by the matched pattern.

Current behavior and limitations

  • The implementation works on bytes, so it does not provide Unicode-aware character matching.
  • Matches are consumed as the scan proceeds; overlapping matches are not all reported.
  • The matcher is trie-based, but does not currently implement the failure links used by the full Aho–Corasick algorithm.
  • Build does not return scanner errors, so unusually long pattern lines may not be reported to the caller.

These constraints are part of the current implementation and may change as the project is improved.

Development

Run the package tests with:

go test ./...

License

BSD-3-Clause. See LICENSE.

About

Multi-String Pattern Matching Algorithm Using TrieNode

Topics

Resources

Stars

30 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages

0