
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
A concise yet efficient implementation for computing the statistics of each tag's set of key phrases over input lines in Python 3. One of the major applications is for sentiment analysis, where each tag is a sentiment with the respective key phrases describing the sentiment.
A trie structure is constructed to index all the key phrases. Then each line is matched towards the index to compute the respective statistics. The time complexity is $O(m^2 \cdot n)$, where $m$ is the maximum number of words in each line and $n$ is the number of lines.
This package is available on PyPI. Just use pip3 install -U TagStats
to install it.
You can simply call compute(content, tagDict)
, where content
is a list of lines and tagDict
is a dictionary with each tag name as key and the respective set of key phrases as value.
from tagstats import compute
print(compute(
[
"a b c",
"b c",
"a c e"
],
{
"+": ["a b", "a c"],
"-": ["b c"]
}
))
The output is a dictionary with each tag name as key and the respective totaled frequencies for lines as value.
{'+': [1, 0, 1], '-': [1, 1, 0]}
You can change the default tokenizer, by specifying a compiled regex as separator to tagstats.tagstats.tokenizer
. You can disable the tokenizer to allow matching over word boundaries, by specifying None
.
You can pre-build the index by calling index(tagDict)
, and later reuse it more than once as an optional parameter of compute(content, tagDict, index)
.
I strongly encourage using PyPy instead of CPython to run the script for best performance.
FAQs
Statistics for each tag's set of key phrases
We found that TagStats 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.