
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
strtree
Advanced tools
Python package for strings binary classification, based on regular expressions put in a decision tree.
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:
Look at a quick 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)
pip install strtreedist folder:
pip install strtree-0.1.0-py3-none-any.whlYou are very welcome to participate in the project. You may solve the current issues or add new functionality - it is up to you to.
FAQs
Python package for strings binary classification, based on regular expressions put in a decision tree.
We found that strtree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.