Skip to main content

Build Status PyPI Codacy Badge

re-map

Package for managing multiple regext pattern replacement change location map.

May be usefull when there is a necesity to have original text, text altered using regex pattern replacements and a map of said replacements. One scenario where this may proove usefull is machine learning "text2text# problems (e.g. translation, text normalization, etc.).

install

$ pip install re-map

example

Code

from re_map import Processor

numbers = {5: 'five', 8: 'eight', 10: 'ten'}
orginal_numbers = {1: 'first', 2: 'second'}

modifiers = [
    ( r'der (G\.) Be',  { 1: 'Graham'} ),
    ( r' (&) ',  { 1: 'and'} ),
    ( r' (etc)\.',  { 1: 'et cetera'} ),
    ( r' ((\d+)((st)|(nd)|(rd)|(th))) ',  { 2: lambda x: orginal_numbers[int(x)], 3: '' } ),
    ( r' (\d+) ',  { 1: lambda x: numbers[int(x)] } ),
]

text = 'Alexander G. Bell ate 10 apples & 8 cucumbers. The 1st apple was rotten, the 2nd was too, also the third, fourth etc.'

with Processor(text) as procesor:
    for pattern, replacement_map in modifiers:
        procesor.process(pattern, replacement_map)

decorated_text, decorated_processed_text = procesor.decorate()

print (text)
print (decorated_text)
print (procesor.processed_text)
print (decorated_processed_text)
print (procesor.span_map)

Output

Alexander G. Bell ate 10 apples & 8 cucumbers. The 1st apple was rotten, the 2nd was too, also the third, fourth etc.
Alexander 00 Bell ate 11 apples 2 3 cucumbers. The 455 apple was rotten, the 677 was too, also the third, fourth 888.
Alexander Graham Bell ate ten apples and eight cucumbers. The first apple was rotten, the second was too, also the third, fourth et cetera.
Alexander 000000 Bell ate 111 apples 222 33333 cucumbers. The 44444 apple was rotten, the 666666 was too, also the third, fourth 888888888.
[((10, 12), (10, 16)), ((22, 24), (26, 29)), ((32, 33), (37, 40)), ((34, 35), (41, 46)), ((51, 52), (62, 67)), ((52, 54), (67, 67)), ((77, 78), (90, 96)), ((78, 80), (96, 96)), ((113, 116), (129, 138))]

Metadata

Release files for re-map 0.4.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for re-map 0.4.6
File Size Uploaded Provenance
re_map-0.4.6.tar.gz 7.3 kB Without provenance Details

Release files / re_map-0.4.6.tar.gz

Download URL re_map-0.4.6.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4fa2fdc5c5fb127ced9fd82d636008901f63d84799afd0c231e7a656ceef1a58
BLAKE2b-256 checksum
How to use checksums
2b166435f738286e5a119d72dd2a803c3e7c21ba577442dbac6f575858a013c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.7

Security for re-map 0.4.6

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page