Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl (278.5 kB view hashes)

Uploaded CPython 3.10

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page