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 details)

Uploaded CPython 3.10

File details

Details for the file patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fd305c32db3bc75d6b4c8d780a1b73986df2daad3f9b675252d6cc9e47f23c17
MD5 8a5ee8598445c919a2b3331a0ef98cae
BLAKE2b-256 0c07c7f5717cba242b052fa5660134e583bc3a78f99e7f570c46566c7e7db38a

See more details on using hashes here.

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