Package modeling structured strings with regex.
Project description
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:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file regexmodel-0.3.5.tar.gz
.
File metadata
- Download URL: regexmodel-0.3.5.tar.gz
- Upload date:
- Size: 274.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c3ee7f2f4755e585eefba93ff2b520695cd665b84563683ef67e96c78693312 |
|
MD5 | e4778e00a9c09d5c67626c64ce77c6d9 |
|
BLAKE2b-256 | 3f22a64d2acf75a428420ca6538f2f2e8f0eeab941e92e13299f618d17db13f2 |
File details
Details for the file regexmodel-0.3.5-py3-none-any.whl
.
File metadata
- Download URL: regexmodel-0.3.5-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4bdc87a87df13f24e845964b8e3aff78e0cff44e9964fab40cb79dcf7d62a47 |
|
MD5 | d5b07bbda3c307f173bf45672771bccb |
|
BLAKE2b-256 | 2d372d8d2013c8ce7563955686d2c128140b4b280a043bb6438bf75959b4707a |