PatternPiece
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.
Metadata
Release files for patternpiece 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.5+ x86-64 | Details for patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl |
Release files / patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl
| Download URL | patternpiece-1.0.1-cp310-cp310-manylinux1_x86_64.whl |
|---|---|
| Size | 278.5 kB |
| Tags | CPython 3.10 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
fd305c32db3bc75d6b4c8d780a1b73986df2daad3f9b675252d6cc9e47f23c17
|
|
BLAKE2b-256 checksum How to use checksums |
0c07c7f5717cba242b052fa5660134e583bc3a78f99e7f570c46566c7e7db38a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Security for patternpiece 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.