sentiment-basic 0.1.0

Simple, deterministic positive/negative word-count sentiment scoring with built-in word lists — pure, zero-dependency, no network.
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented2 out of 7 items with examples
  • Size
  • Source code size: 15.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 357.47 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • theluckystrike

sentiment-basic

crates.io Documentation

Simple, deterministic positive/negative word-count sentiment scoring with built-in word lists. Pure Rust, zero dependencies, no network, no model downloads — the same lightweight signal the BeLikeNative AI writing assistant uses for a fast first-pass tone read.

What this is

A lexicon scorer, not a machine-learning model. It counts matches against two small, hand-curated lists of unambiguous positive and negative words and reports the balance. That makes it:

  • fast — microsecond-scale, suitable for hot paths and huge corpora;
  • fully deterministic — identical input always yields identical output;
  • auditable — the entire "model" is two &[&str] constants you can read;
  • offline — no API keys, no network, no runtime downloads.

The trade-off is that it does not understand negation ("not good"), sarcasm, intensifiers, or context. For nuanced analysis, pair it with a real model. For a stable, inspectable baseline — word counts, dashboards, gating, A/B signal — it is exactly right.

Install

[dependencies]
sentiment-basic = "0.1"

Quick start

use sentiment_basic::score;

let r = score("I love this bright happy day. It is awful and terrible though.");
println!("label:    {}", r.label());        // positive | negative | neutral
println!("net:      {}", r.net());          // i64, +positive - negative
println!("compare:  {:.2}", r.comparison()); // -1.0..=1.0
println!("pos share:{:.2}", r.positive_share()); // 0.0..=1.0

API

score(&str) returns a Sentiment:

field meaning
positive_hits count of positive lexicon words matched
negative_hits count of negative lexicon words matched
tokens total word tokens scanned
net() positive_hits - negative_hits as i64
comparison() (pos - neg) / (pos + neg), in -1.0..=1.0
positive_share() fraction of polarity tokens that are positive
label() "positive", "negative", or "neutral"

Matching is case-insensitive, whole-word, and punctuation-safe. The lexicons are exported as POSITIVE_WORDS and NEGATIVE_WORDS if you want to extend or inspect them.

Determinism & safety

No randomness, no global state, no unsafe. Safe to call from multiple threads. Empty input returns a zero-hit "neutral" result.

License

MIT. Built for BeLikeNative.