Skip to main content

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))

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

regexmodel-0.2.0.tar.gz (188.1 kB view details)

Uploaded Source

Built Distribution

regexmodel-0.2.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file regexmodel-0.2.0.tar.gz.

File metadata

  • Download URL: regexmodel-0.2.0.tar.gz
  • Upload date:
  • Size: 188.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.5

File hashes

Hashes for regexmodel-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8ccbd2429e9f504e31981e4e20914ac9029b9c855f5dd41dfa00bf3c87e2ac52
MD5 6a83b62983e19072de35046a68539b30
BLAKE2b-256 0053817b89164955f5dee960439f0eb73dcd13cfeabe7b91b82bd58ce4795023

See more details on using hashes here.

Provenance

File details

Details for the file regexmodel-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: regexmodel-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.5

File hashes

Hashes for regexmodel-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc28495a593f2b067dd9a7afb01349d1b2c147eab2b23871e9fc3e3d00a75fc
MD5 080520a174163870a0877179870ca529
BLAKE2b-256 00f93a3c4b6150452793765eb44b70fa1314841f5e7637e78a734077b123a8e2

See more details on using hashes here.

Provenance

Supported by

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