Skip to main content

regexmodel

Regexmodel is a python package that uses a graph model to fit and synthesize structured strings. Structured strings are strings such as license plates, credit card numbers ip-addresses, and phone numbers. Regexmodel can infer a regex-like structure from a series of positive examples and create new samples (such as phone numbers etc.).

Features:

  • Draw new synthetic values
  • Only on the numpy and polar libraries (faker for benchmarks).
  • Fast (on average < 1 second for about 500 positive examples).
  • Can provide statistics on how good the regexmodel has fit your values using log likelihood.
  • Can be serialized and can be modified by hand.

Installation

You can install regexmodel using pip:

pip install regexmodel

If you want the latest version of git, use:

pip install git+https://github.com/sodascience/regexmodel.git

If you want to run the benchmarks, you should also install the faker package:

pip install faker

Using regexmodel

Fitting the regexmodel is as simple as:

from regexmodel import RegexModel

model = RegexModel.fit(your_values_to_fit, count_thres=10, method="accurate")

The count_thres parameter changes how detailed and time consuming the fit is. A higher threshold means a shorter time to fit, but also a worse fit.

The method parameter determines the performance/how fast the model is trained. For better looking results, the "accurate" method is advised. If the quickness of the fit is more important, then you can use the "fast" method. The "accurate" method is generally slow with very long/branching/unstructured strings.

Then synthesizing a new value is done with:

model.draw()

Serialization

The regex model can be serialized so that it can be stored in for example a JSON file:

import json
with open(some_file, "w") as handle:
    json.dump(model.serialize(), handle)

And deserialized:

with open(some_file, "r") as handle:
    model = RegexModel(json.load(handle))

Contributing

You can contribute to the regexmodel package by giving feedback in the "Issues" tab, or by creating a pull request.

To create a pull request:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contact

Regexmodel is a project by the ODISSEI Social Data Science (SoDa) team. Do you have questions, suggestions, or remarks on the technical implementation? File an issue in the issue tracker or feel free to contact Raoul Schram.

SoDa logo

Metadata

Release files for regexmodel 0.3.5

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

Source distribution (sdist)

Source distribution for regexmodel 0.3.5
File Size Uploaded
regexmodel-0.3.5.tar.gz 274.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for regexmodel 0.3.5
File Interpreter ABI Platform
regexmodel-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 293.5 kB

Release files / regexmodel-0.3.5.tar.gz

Download URL regexmodel-0.3.5.tar.gz
Size 274.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8c3ee7f2f4755e585eefba93ff2b520695cd665b84563683ef67e96c78693312
BLAKE2b-256 checksum
How to use checksums
3f22a64d2acf75a428420ca6538f2f2e8f0eeab941e92e13299f618d17db13f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.10

Release files / regexmodel-0.3.5-py3-none-any.whl

Download URL regexmodel-0.3.5-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4bdc87a87df13f24e845964b8e3aff78e0cff44e9964fab40cb79dcf7d62a47
BLAKE2b-256 checksum
How to use checksums
2d372d8d2013c8ce7563955686d2c128140b4b280a043bb6438bf75959b4707a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.10

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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