Skip to main content

Basics to strtree

strtree is a Python package for strings binary classification, based on regular expressions put in a decision tree.

Github repo: stretree

With strtree you can:

  • Do a binary classification of your strings using automatically extracted regular expressions
  • Find shortest regular expressions which covers strings with positive labels in the most accurate way

Look at a quick example.

Example

Firstly, let's build a tree from strings and their labels.

import strtree


strings = ['Samsung X-500', 'Samsung SM-10', 'Samsung X-1100', 'Samsung F-10', 'Samsung X-2200',
           'AB Nokia 1', 'DG Nokia 2', 'THGF Nokia 3', 'SFSD Nokia 4', 'Nokia XG', 'Nokia YO']
labels = [1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0]

tree = StringTree()
tree.build(strings, labels, min_precision=0.75, min_token_length=1)

Let's see what regular expressions were extracted.

for leaf in tree.leaves:
    print(leaf)

# Output:
# PatternNode(".+ .+a.+", right=None, left=PatternNode(.+0.+), n_strings=11, precision=1.0, recall=0.57)
# PatternNode(".+0.+", right=None, left=None, n_strings=7, precision=1.0, recall=1.0)

You may need to check the precision and recall of the whole tree for a given set of strings and true labels.

print('Precision: {}'.format(tree.precision_score(strings, labels)))
# Precision: 1.0

print('Recall: {}'.format(tree.precision_score(strings, labels)))
# Recall: 1.0

Finally, you can pass any strings you want and see if they match to extracted regular expressions or not.

matches = tree.match(other_strings)

# You will receive a vector of the same size as other_strings containing 0's (no match) or 1's (match)

Installing

  1. Use PyPI: pip install strtree
  2. Use a distribution file located in the dist folder: pip install strtree-0.1.0-py3-none-any.whl

Contribution

You are very welcome to participate in the project. You may solve the current issues or add new functionality - it is up to you to.

Metadata

Release files for strtree 0.2.0

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

Source distribution (sdist)

Source distribution for strtree 0.2.0
File Size Uploaded Provenance Actions
strtree-0.2.0.tar.gz 10.5 kB Without provenance Details for strtree-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.9 kB

Release files / strtree-0.2.0.tar.gz

Download URL strtree-0.2.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d08f82fda856926de7cb18c1e2188f579b37ddef731259e782e18126fa0b5e92
BLAKE2b-256 checksum
How to use checksums
35729144122bc19f6da03b48e4e2f1dc7b12932213d8e95bdba7148a4a580313
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release files / strtree-0.2.0-py3-none-any.whl

Download URL strtree-0.2.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1d341955334273473baa99ae39fde9d13f5fcbba6c41dec94c5dbe724a2f449
BLAKE2b-256 checksum
How to use checksums
9d40732535b37308f901e8d7535c1665286be507516359ffc0fafed9be7afbe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Security for strtree 0.2.0

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