pub struct SentimentAnalyzer {
pub config: SentimentConfig,
pub lexicon: HashMap<String, LexiconEntry>,
}Expand description
Lexicon-based sentiment analysis engine with aspect-level detection.
The analyser operates entirely in-process; no external model or network call
is required. Accuracy is limited by the quality of the built-in (or
user-supplied) lexicon — for high-stakes applications consider augmenting
the lexicon via with_lexicon_entry.
Fields§
§config: SentimentConfigRuntime configuration.
lexicon: HashMap<String, LexiconEntry>Word-to-entry lookup table.
Implementations§
Source§impl SentimentAnalyzer
impl SentimentAnalyzer
Sourcepub fn new(config: SentimentConfig) -> Self
pub fn new(config: SentimentConfig) -> Self
Build a new analyser seeded with the built-in lexicon.
Sourcepub fn with_lexicon_entry(self, entry: LexiconEntry) -> Self
pub fn with_lexicon_entry(self, entry: LexiconEntry) -> Self
Add or replace a single lexicon entry (builder pattern).
Sourcepub fn analyze(&self, text_id: String, text: &str) -> SentimentResult
pub fn analyze(&self, text_id: String, text: &str) -> SentimentResult
Analyse a single document and return a SentimentResult.
Sourcepub fn batch_analyze(&self, texts: &[(String, String)]) -> Vec<SentimentResult>
pub fn batch_analyze(&self, texts: &[(String, String)]) -> Vec<SentimentResult>
Analyse a batch of (text_id, text) pairs.
Sourcepub fn top_positive<'a>(
&self,
results: &'a [SentimentResult],
n: usize,
) -> Vec<&'a SentimentResult>
pub fn top_positive<'a>( &self, results: &'a [SentimentResult], n: usize, ) -> Vec<&'a SentimentResult>
Return the top n results ordered by compound score (most positive first).
Sourcepub fn top_negative<'a>(
&self,
results: &'a [SentimentResult],
n: usize,
) -> Vec<&'a SentimentResult>
pub fn top_negative<'a>( &self, results: &'a [SentimentResult], n: usize, ) -> Vec<&'a SentimentResult>
Return the n most negative results (lowest compound score first).
Sourcepub fn aggregate_sentiment(&self, results: &[SentimentResult]) -> SentimentScore
pub fn aggregate_sentiment(&self, results: &[SentimentResult]) -> SentimentScore
Compute the mean SentimentScore across a slice of results.
Returns SentimentScore::zero() for an empty slice.
Sourcepub fn stats(&self, results: &[SentimentResult]) -> SentimentAnalyzerStats
pub fn stats(&self, results: &[SentimentResult]) -> SentimentAnalyzerStats
Compute aggregate statistics for a collection of results.
Auto Trait Implementations§
impl Freeze for SentimentAnalyzer
impl RefUnwindSafe for SentimentAnalyzer
impl Send for SentimentAnalyzer
impl Sync for SentimentAnalyzer
impl Unpin for SentimentAnalyzer
impl UnsafeUnpin for SentimentAnalyzer
impl UnwindSafe for SentimentAnalyzer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.