Giter Site home page Giter Site logo

xlxwalex / patternpiece Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 86 KB

PatternPiece is a light pattern matching package based on Aho-Corasick automaton with Cython.

Home Page: https://patternpiece.readthedocs.io/en/latest/

License: Apache License 2.0

Makefile 1.19% Python 27.39% Shell 1.79% Cython 69.63%
aho-corasick automation cython-library trie

patternpiece's Introduction

PatternPiece

GitHub Documentation Status

English | 简体中文

PatternPiece is a extended, lightweight Aho-Corasick sequence multi-pattern, multi-element matching algorithm library, serving as the initial design for the matching method.

PatternPiece is implemented in Cython and tested on Python 3.8 and up. It works on 64 bits Linux, macOS and Windows. The license is Apache-2.0.

Download and source code

You can fetch PatternPiece from:

The documentation is published at https://patternpiece.readthedocs.io/en/latest/

Quick start

This module is written in Cython. You need a C compiler installed to compile native extensions. In addition, due to the requirements for parallel computing, you also need to have OpenMP installed. To install:

pip install patternpiece

Or you can also install from source, first clone the repository:

git clone https://github.com/xlxwalex/PatternPiece.git
cd PatternPiece
pip install -e .

Firstly, we can construct a toy pattern dicts.

>>> patterns = {(1, 200, 30) : 1} # (key -> pattern tuple, value -> pattern index)

Then create an PatternPiece:

>>> from patternpiece import PatternPiece
>>> matcher = PatternPiece(patterns)

It will automatically convert the patterns from a trie to an Aho-Corasick automaton to enable Aho-Corasick search, and then you can match the patterns in sequences:

>>> sequences = [[(1, 10, 100), (2, 20, 200), (3, 30, 300)]]
>>> results = matcher.match(sequences)

Note: you can input multiple sequences, and they will be matched in parallel.

Finally, you can get the results:

results:
[[(1, 0, 3)]]  # (Index, start, end)

License

This library is licensed under very liberal Apache-2.0 license.

patternpiece's People

Contributors

dependabot[bot] avatar xlxwalex avatar

Stargazers

 avatar

Watchers

 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.