### Install pybmoore using uv Source: https://github.com/amenezes/pybmoore/blob/master/README.md Installs the pybmoore package using the 'uv' package manager. This command requires 'gcc' to be available on the system for Cython compilation. ```bash uv pip install pybmoore ``` -------------------------------- ### Build pybmoore locally (Bash) Source: https://github.com/amenezes/pybmoore/blob/master/README.md Commands to build the pybmoore project locally. It first requires installing development dependencies and then uses 'make' targets. The build can be performed with or without Cython, with an option to clean previous builds. ```bash make build # without Cython make build USE_CYTHON=1 # with Cython ``` ```bash # in some cases it's necesary run `make clean` before `make build`. ``` ```bash make ``` -------------------------------- ### search - Single Pattern Search Source: https://context7.com/amenezes/pybmoore/llms.txt Searches for a single pattern within a given text and returns all occurrences as a list of tuples, where each tuple represents the start and end positions of a match. This search is case-sensitive. ```APIDOC ## POST /search ### Description Searches for a single pattern in a text and returns all occurrences as a list of tuples containing start and end positions. The search is case-sensitive. ### Method POST ### Endpoint /search ### Parameters #### Request Body - **pattern** (string) - Required - The pattern string to search for. - **text** (string) - Required - The text string to search within. ### Request Example ```json { "pattern": "string", "text": "The Boyer-Moore string-search algorithm is an efficient string-searching algorithm." } ``` ### Response #### Success Response (200) - **matches** (list of tuples) - A list where each tuple contains the start and end index of a match. Example: `[(16, 22), (57, 63)]` #### Response Example ```json { "matches": [ [16, 22], [57, 63] ] } ``` ``` -------------------------------- ### Search Single Pattern with pybmoore.search Source: https://context7.com/amenezes/pybmoore/llms.txt Demonstrates the basic usage of the `pybmoore.search` function to find all occurrences of a single pattern within a given text. The search is case-sensitive and returns a list of (start, end) position tuples. Handles empty patterns and multi-word patterns. ```python import pybmoore # Basic usage - search for a word in text TEXT = """The Boyer-Moore string-search algorithm is an efficient string-searching algorithm that is the standard benchmark for practical string-search literature.""" # Find all occurrences of 'string' matches = pybmoore.search('string', TEXT) print(f"Occurrences: {len(matches)}") # Output: Occurrences: 3 print(matches) # Output: [(16, 22), (57, 63), (130, 136)] # Extract matched substrings using positions for start, end in matches: print(f"Position ({start},{end}): '{TEXT[start:end]}'") # Output: # Position (16,22): 'string' # Position (57,63): 'string' # Position (130,136): 'string' # Case sensitivity demonstration result_lower = pybmoore.search('algorithm', TEXT) print(f"'algorithm' found: {len(result_lower)} times") # Output: 'algorithm' found: 1 times result_upper = pybmoore.search('Algorithm', TEXT) print(f"'Algorithm' found: {len(result_upper)} times") # Output: 'Algorithm' found: 0 times # Empty pattern returns empty list empty_result = pybmoore.search('', TEXT) print(f"Empty pattern result: {empty_result}") # Output: Empty pattern result: [] # Multi-word pattern search multiword = pybmoore.search('string-search', TEXT) print(f"'string-search' positions: {multiword}") # Output: 'string-search' positions: [(16, 29), (130, 143)] ``` -------------------------------- ### Search for a single term in text (Python) Source: https://github.com/amenezes/pybmoore/blob/master/README.md Demonstrates how to use the pybmoore.search function to find all occurrences of a single term within a text. The function returns a list of tuples, where each tuple represents the start and end index of a match. The search is case-sensitive. ```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]}") ``` ```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: [] ``` -------------------------------- ### Search Multiple Patterns in US Constitution with ProcessPoolExecutor Source: https://context7.com/amenezes/pybmoore/llms.txt Demonstrates searching for multiple patterns ('Congress', 'United States', 'freedom') within a large text (US Constitution) using `pybmoore.search_m` with `ProcessPoolExecutor` for parallel processing. It iterates through the results to print the count of matches for each pattern. ```python import pybmoore from concurrent.futures import ProcessPoolExecutor us_constitution = """We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America. Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech...""" results = pybmoore.search_m( ['Congress', 'United States', 'freedom'], us_constitution, ProcessPoolExecutor, max_workers=3 ) for pattern, positions in results.items(): print(f"'{pattern}': {len(positions)} match(es)") ``` -------------------------------- ### Handle NotImplementedError for Unsupported Pattern Types Source: https://context7.com/amenezes/pybmoore/llms.txt Illustrates error handling in `pybmoore` by attempting to search with various unsupported data types (integers, floats, None, booleans, dictionaries). It uses a try-except block to catch `NotImplementedError` and prints a message indicating the unsupported pattern and its type. This demonstrates the library's input validation for the `search` and `search_m` functions. ```python import pybmoore from concurrent.futures import ThreadPoolExecutor # Unsupported pattern types raise NotImplementedError unsupported_types = [123, 45.67, None, True, False, {}, -1] for pattern in unsupported_types: try: pybmoore.search(pattern, "sample text") except NotImplementedError as e: print(f"Pattern {pattern!r} ({type(pattern).__name__}): NotImplementedError raised") # Same behavior for search_m try: pybmoore.search_m(12345, "sample text", ThreadPoolExecutor) except NotImplementedError as e: print(f"search_m with int pattern: {e}") ``` -------------------------------- ### search_m - Multi-Pattern Concurrent Search Source: https://context7.com/amenezes/pybmoore/llms.txt Searches for multiple patterns concurrently within a given text. It supports different executor types (ProcessPoolExecutor, ThreadPoolExecutor) and returns a dictionary mapping each pattern to its list of occurrence positions. ```APIDOC ## POST /search_m ### Description Searches for multiple patterns concurrently using either `ProcessPoolExecutor` or `ThreadPoolExecutor`. Returns a dictionary mapping each pattern to its list of occurrence tuples. Accepts patterns as list, set, tuple, or single string. ### Method POST ### Endpoint /search_m ### Parameters #### Request Body - **patterns** (list, set, tuple, or string) - Required - The pattern(s) to search for. - **text** (string) - Required - The text string to search within. - **executor** (class) - Required - The concurrent executor class to use (e.g., `ProcessPoolExecutor`, `ThreadPoolExecutor`). - **max_workers** (integer) - Optional - The maximum number of workers to use for the executor. ### Request Example ```json { "patterns": ["brute-force", "Boyer-Moore", "algorithm"], "text": "The Boyer-Moore algorithm searches for occurrences of P in T by performing explicit character comparisons.", "executor": "ProcessPoolExecutor", "max_workers": 4 } ``` ### Response #### Success Response (200) - **results** (dictionary) - A dictionary where keys are the patterns searched for, and values are lists of tuples representing the start and end positions of each match. Example: `{"brute-force": [[146, 157]], "Boyer-Moore": [[4, 15], [214, 225]]}` #### Response Example ```json { "results": { "brute-force": [ [146, 157] ], "Boyer-Moore": [ [4, 15], [214, 225] ], "algorithm": [ [16, 25] ] } } ``` ``` -------------------------------- ### Search for multiple terms with different executors (Python) Source: https://github.com/amenezes/pybmoore/blob/master/README.md Illustrates using pybmoore.search_m to find occurrences of multiple terms. This function supports different concurrency executors like ProcessPoolExecutor and ThreadPoolExecutor for parallel searching. It can accept patterns as a list, set, or tuple, and allows specifying max_workers. ```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)]} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.