![Build Status](https://github.com/amenezes/pybmoore/actions/workflows/ci.yml/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/amenezes/pybmoore/branch/master/graph/badge.svg)](https://codecov.io/gh/amenezes/pybmoore)
[![PyPI version](https://badge.fury.io/py/pybmoore.svg)](https://badge.fury.io/py/pybmoore)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pybmoore)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
# pybmoore
Python/Cython implementation of [Boyer-Moore string-search algorithm](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm).
## Installing
Install and update using uv:
````bash
uv pip install pybmoore
````
> notice: `gcc` must be available on the system.
## Usage
### Single term
The search method in the `pybmoore` module will return a list of tuples with all occurrences, where the tuple have the initial and final position. For example:
```python
import pybmoore
TEXT = """The Boyer–Moore string-search algorithm is
an efficient string-searching algorithm that is the
standard benchmark for practical string-search literature.
"""
matches = pybmoore.search('string', TEXT)
print(f"Occurrences: {len(matches)}")
# output: Occurrences: 3
print(matches)
# output: [(16, 22), (57, 63), (130, 136)]
for x, y in matches:
print(f"({x},{y}) - {TEXT[x:y]}")
```
> notice: search method it's case sensitive.
```python
import pybmoore
TEXT = """The algorithm preprocesses the string being searched for (the pattern),
but not the string being searched in (the text). It is thus well-suited for
applications in which the pattern is much shorter than the text or where it
persists across multiple searches.
"""
pybmoore.search('algorithm', TEXT)
# output: [(4, 13)]
pybmoore.search('Algorithm', TEXT)
# output: []
```
### Multiple terms
```python
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
import pybmoore
TEXT = """The Boyer-Moore algorithm searches for occurrences of P in T by
performing explicit character comparisons at different alignments. Instead of a
brute-force search of all alignments (of which there are m − n + 1, Boyer-Moore
uses information gained by preprocessing P to skip as many alignments as possible.
"""
# Using a list of patterns
pybmoore.search_m(['brute-force', 'Boyer-Moore'], TEXT, ProcessPoolExecutor)
# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}
# Using a set of patterns
pybmoore.search_m({'brute-force', 'Boyer-Moore'}, TEXT, ThreadPoolExecutor)
# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}
# Using a tuple of patterns
pybmoore.search_m(('brute-force', 'Boyer-Moore'), TEXT, ThreadPoolExecutor, max_workers=4)
# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}
```
> Details
For granular control of the pool, use the parameters listed in the module documentation. For example:
## Development
To build **pybmoore** locally first install `requirements-dev.txt` dependencies and run:
```bash
make build # without Cython
make build USE_CYTHON=1 # with Cython
```
> in some cases it's necesary run `make clean` before `make build`.
Type `make` in the command line to see all available targets.
## Links
- License: [Apache License](https://choosealicense.com/licenses/apache-2.0/)
- Code: [https://github.com/amenezes/pybmoore](https://github.com/amenezes/pybmoore)
- Issue tracker: [https://github.com/amenezes/pybmoore/issues](https://github.com/amenezes/pybmoore/issues)
Raw data
{
"_id": null,
"home_page": "https://github.com/amenezes/pybmoore",
"name": "pybmoore",
"maintainer": null,
"docs_url": null,
"requires_python": ">3.8",
"maintainer_email": null,
"keywords": "\"search\", \"boyer-moore\", \"text-search\"",
"author": "Alexandre Menezes",
"author_email": "alexandre.fmenezes@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d3/f8/bd82f73a54e490348309b86f7ce440d529997486526cf87d768965857411/pybmoore-2.0.2.tar.gz",
"platform": "macOS",
"description": "![Build Status](https://github.com/amenezes/pybmoore/actions/workflows/ci.yml/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/amenezes/pybmoore/branch/master/graph/badge.svg)](https://codecov.io/gh/amenezes/pybmoore)\n[![PyPI version](https://badge.fury.io/py/pybmoore.svg)](https://badge.fury.io/py/pybmoore)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pybmoore)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n# pybmoore\n\nPython/Cython implementation of [Boyer-Moore string-search algorithm](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm).\n\n## Installing\n\nInstall and update using uv:\n\n````bash\nuv pip install pybmoore\n````\n\n> notice: `gcc` must be available on the system.\n\n## Usage\n\n### Single term\n\nThe search method in the `pybmoore` module will return a list of tuples with all occurrences, where the tuple have the initial and final position. For example:\n\n```python\nimport pybmoore\n\n\nTEXT = \"\"\"The Boyer\u2013Moore string-search algorithm is \nan efficient string-searching algorithm that is the \nstandard benchmark for practical string-search literature.\n\"\"\"\n\nmatches = pybmoore.search('string', TEXT)\nprint(f\"Occurrences: {len(matches)}\")\n# output: Occurrences: 3\n\nprint(matches)\n# output: [(16, 22), (57, 63), (130, 136)]\n\nfor x, y in matches:\n print(f\"({x},{y}) - {TEXT[x:y]}\")\n```\n\n> notice: search method it's case sensitive.\n\n\n```python\nimport pybmoore\n\n\nTEXT = \"\"\"The algorithm preprocesses the string being searched for (the pattern), \nbut not the string being searched in (the text). It is thus well-suited for \napplications in which the pattern is much shorter than the text or where it \npersists across multiple searches.\n\"\"\"\n\npybmoore.search('algorithm', TEXT)\n# output: [(4, 13)]\n\npybmoore.search('Algorithm', TEXT)\n# output: []\n```\n\n### Multiple terms\n\n```python\nfrom concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor\n\nimport pybmoore\n\n\nTEXT = \"\"\"The Boyer-Moore algorithm searches for occurrences of P in T by \nperforming explicit character comparisons at different alignments. Instead of a \nbrute-force search of all alignments (of which there are m \u2212 n + 1, Boyer-Moore \nuses information gained by preprocessing P to skip as many alignments as possible.\n\"\"\"\n\n# Using a list of patterns\npybmoore.search_m(['brute-force', 'Boyer-Moore'], TEXT, ProcessPoolExecutor)\n# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}\n\n# Using a set of patterns\npybmoore.search_m({'brute-force', 'Boyer-Moore'}, TEXT, ThreadPoolExecutor)\n# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}\n\n# Using a tuple of patterns\npybmoore.search_m(('brute-force', 'Boyer-Moore'), TEXT, ThreadPoolExecutor, max_workers=4)\n# output: {'brute-force': [(146, 157)], 'Boyer-Moore': [(4, 15), (214, 225)]}\n```\n\n> Details\n\nFor granular control of the pool, use the parameters listed in the module documentation. For example:\n\n## Development\n\nTo build **pybmoore** locally first install `requirements-dev.txt` dependencies and run:\n\n```bash\nmake build # without Cython\n\nmake build USE_CYTHON=1 # with Cython\n```\n\n> in some cases it's necesary run `make clean` before `make build`.\n\nType `make` in the command line to see all available targets.\n\n## Links\n\n- License: [Apache License](https://choosealicense.com/licenses/apache-2.0/)\n- Code: [https://github.com/amenezes/pybmoore](https://github.com/amenezes/pybmoore)\n- Issue tracker: [https://github.com/amenezes/pybmoore/issues](https://github.com/amenezes/pybmoore/issues)\n",
"bugtrack_url": null,
"license": " Apache-2.0",
"summary": "Python/Cython Boyer-Moore string-search algorithm",
"version": "2.0.2",
"project_urls": {
"Code": "https://github.com/amenezes/pybmoore",
"Documentation": "https://github.com/amenezes/pybmoore",
"Homepage": "https://github.com/amenezes/pybmoore",
"Issue tracker": "https://github.com/amenezes/pybmoore/issues"
},
"split_keywords": [
"\"search\"",
" \"boyer-moore\"",
" \"text-search\""
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d3f8bd82f73a54e490348309b86f7ce440d529997486526cf87d768965857411",
"md5": "cdb84f3407c4a8e3544f4cf39aeee0b3",
"sha256": "43505fe152a04d8f8d71a4173c325e39732ecd5c956687b8e149a3372e2df84f"
},
"downloads": -1,
"filename": "pybmoore-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "cdb84f3407c4a8e3544f4cf39aeee0b3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.8",
"size": 66803,
"upload_time": "2024-11-27T16:30:19",
"upload_time_iso_8601": "2024-11-27T16:30:19.167814Z",
"url": "https://files.pythonhosted.org/packages/d3/f8/bd82f73a54e490348309b86f7ce440d529997486526cf87d768965857411/pybmoore-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-27 16:30:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "amenezes",
"github_project": "pybmoore",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "pybmoore"
}