Coder Social home page Coder Social logo

nim-aho-corasick's Introduction

nim-aho-corasick

Aho–Corasick string matching algorithm

On why, see: http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm

or read about its use by Cloudflare as explained @nginx-conf 2014, where John Graham Cumming discusses its use in Cloudflare WAF, together with Lua and Nginx.

http://www.scalescale.com/scaling-cloudflares-massive-waf/

On how:

Create the tree and initialize it

  var ac = AhoCorasick(rootValue: "")
  ac.initialize()

Create a dictionary of words and build it

  for w in @["a", "ab", "bc", "bca", "c", "caa"]:
    ac.add(w)
  ac.build()

Search for matches

  var matches: seq[string] = ac.match("abccab")
  if matches == @["a", "ab", "bc", "c", "c", "a", "ab"]:
    echo("success")

Simple search, example

  # Dictionary built with words:
    @["monkey", "was", "time", "lava"], 
  # Will return matches:
    @["time", "was", "monkey"], 
  # If searched with phrase
    "In the time of chimpanzees I was a monkey."

nim-aho-corasick's People

Contributors

a-zb avatar

Stargazers

Luc Alapini avatar Emre Şafak avatar Nazeeruddin Ikram 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.