Skip to main content

Add your description here

Project description

gap-mapper

PyPI version License: MIT

A simple Python utility to find a "gapped" or "sparse" string within a text and return its original offsets.

This is useful when you need to find a string that has had extra, arbitrary spaces inserted into it.

Installation

Install the package from PyPI:

pip install gap-mapper

Usage

The main function is gapmap().

It takes an original_text (the haystack) and a spaced_needle (the gapped string to find). It finds the needle (ignoring its spaces) within the original text (also ignoring its spaces) and returns the correct (start, end) offsets of the match in the original text.

import gap_mapper

# The full text to search within
haystack = "Hello, world! This is the main text."

# The string to find, which has extra, inconsistent spaces
needle = "w   o r l   d"

# Find the offsets
offsets = gap_mapper.gapmap(haystack, needle)

if offsets:
    print(f"Match found at offsets: {offsets}")
    
    start, end = offsets
    print(f"Matched string: '{haystack[start:end]}'")
else:
    print("No match found.")

Match found at offsets: (7, 12) Matched string: 'world'

As you can see, gapmap correctly located "world" in the haystack and returned its true offsets (7, 12), even though the needle was "w o r l d".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gap_mapper-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gap_mapper-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file gap_mapper-0.1.0.tar.gz.

File metadata

  • Download URL: gap_mapper-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gap_mapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1cacae3ab6b88d18c501a8959a19dc297fd454656088b45d5780e2e26a8cb5e1
MD5 8dec7fba54f9a094ebe50ac135bb0329
BLAKE2b-256 00437bad1d0b03a383bba2d39e4d7469726663d4e133c7b0f87afbe8287454b9

See more details on using hashes here.

File details

Details for the file gap_mapper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gap_mapper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for gap_mapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d78492a3c4d159bede8f09ae17218a5d06d975888e7dd1ab2485eb50ed6d942
MD5 775fc128a11c3d65900987a6dd05ffb6
BLAKE2b-256 9c6874e2f53aab5a90abb9c6ae66a8175dfaf2b91779296bfe8e85d5e0fef38d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page