GithubHelp home page GithubHelp logo

aho-corasick-optimized's Introduction

aho-corasick-optimized

Implementation of the Aho-Corasick string matching algorithm, which supposed to be Garbage Collector friendly. The automaton implemented using only the primitive data types in order to avoid Autoboxing and Unboxing conversions.

Usage

This implementation is self-sufficient. You can directly copy this class to your project: https://github.com/lagodiuk/aho-corasick-optimized/blob/master/src/main/java/com/lahodiuk/ahocorasick/AhoCorasickOptimized.java

public class Example {

	public static void main(String[] args) {
	
		// Construction of the the automaton
		AhoCorasickOptimized ac = new AhoCorasickOptimized("he", "she", "his", "hers");

		// The same automaton can be used for matching inside different texts
		String text1 = "ushers";
		System.out.println("\n Matching inside text 1: " + text1);
		// In case, when the pattern is found - the callback will be activated:
		ac.match(text1, (start, end, found) -> System.out.printf("%s: [%d..%d]%n", found, start, end));

		// Example of finding substrings inside another text
		String text2 = "ushers ushers ushers ushers ushers abc 123 xyz he she";
		System.out.println("\n Matching inside text 2: " + text2);
		ac.match(text2, (start, end, found) -> System.out.printf("%s: [%d..%d]%n", found, start, end));

		// The structure of automaton can be visualized using Graphviz format
		System.out.println("\n Graphviz structure of automaton:");
		System.out.println(ac.generateGraphvizAutomatonRepresentation(false))
	}
}

The generated automaton can be visualized using Graphviz software

Graphviz structure of automaton

Reference

The Aho-Corasick string matching algorithm, described in the paper: "Efficient String Matching: An Aid to Bibliographic Search", Alfred V. Aho, Margaret J. Corasick, Bell Laboratories, 1975

aho-corasick-optimized's People

Contributors

lagodiuk avatar

Watchers

 avatar  avatar

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.