Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sodascience/regexmodel
Using regex to learn the structure of strings
https://github.com/sodascience/regexmodel
graph-model python regex strings
Last synced: about 2 months ago
JSON representation
Using regex to learn the structure of strings
- Host: GitHub
- URL: https://github.com/sodascience/regexmodel
- Owner: sodascience
- License: mit
- Created: 2023-08-22T08:38:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-17T08:36:43.000Z (4 months ago)
- Last Synced: 2024-09-17T11:06:43.370Z (4 months ago)
- Topics: graph-model, python, regex, strings
- Language: Python
- Homepage:
- Size: 1.37 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```bash
pip install regexmodel
```If you want the latest version of git, use:
```bash
pip install git+https://github.com/sodascience/regexmodel.git
```If you want to run the benchmarks, you should also install the faker package:
```bash
pip install faker
```## Using regexmodel
Fitting the regexmodel is as simple as:
```python
from regexmodel import RegexModelmodel = 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:
```python
model.draw()
```## Serialization
The regex model can be serialized so that it can be stored in for example a JSON file:
```python
import json
with open(some_file, "w") as handle:
json.dump(model.serialize(), handle)
```And deserialized:
```python
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)](https://odissei-data.nl/nl/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](https://github.com/qubixes).