pybmoore


Namepybmoore JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/amenezes/pybmoore
SummaryPython/Cython Boyer-Moore string-search algorithm
upload_time2024-02-12 02:47:17
maintainer
docs_urlNone
authorAlexandre Menezes
requires_python>=3.8
license Apache-2.0
keywords "search" "boyer-moore" "text-search"
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ![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 pip:

````bash
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": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "\"search\",\"boyer-moore\",\"text-search\"",
    "author": "Alexandre Menezes",
    "author_email": "alexandre.fmenezes@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d3/a9/fbc1c1afc1f56473132d03de4fc195fa0d1eb060a195e49a892d1f14077f/pybmoore-2.0.0.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 pip:\n\n````bash\npip 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.0",
    "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": "d3a9fbc1c1afc1f56473132d03de4fc195fa0d1eb060a195e49a892d1f14077f",
                "md5": "999dd479f784d2d93bdc0d989376310e",
                "sha256": "b03038779b3955824e32c62cdf07140217eaaf22a4a3b47d009e7a13ef334645"
            },
            "downloads": -1,
            "filename": "pybmoore-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "999dd479f784d2d93bdc0d989376310e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 66846,
            "upload_time": "2024-02-12T02:47:17",
            "upload_time_iso_8601": "2024-02-12T02:47:17.786306Z",
            "url": "https://files.pythonhosted.org/packages/d3/a9/fbc1c1afc1f56473132d03de4fc195fa0d1eb060a195e49a892d1f14077f/pybmoore-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-12 02:47:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "amenezes",
    "github_project": "pybmoore",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "pybmoore"
}
        
Elapsed time: 0.22162s