use crate::text;
use sklears_core::traits::Fit;
use std::collections::HashSet;
#[test]
fn test_count_vectorizer() {
let documents = vec![
"the quick brown fox".to_string(),
"the quick brown dog".to_string(),
"the lazy dog".to_string(),
];
let vectorizer = text::CountVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 3);
assert!(features.ncols() > 0);
let vocab = fitted.get_vocabulary();
if let Some(vocab_map) = vocab {
assert!(vocab_map.contains_key("the"));
assert!(vocab_map.contains_key("quick"));
assert!(vocab_map.contains_key("brown"));
}
}
#[test]
fn test_tfidf_vectorizer() {
let documents = vec![
"the quick brown fox".to_string(),
"the quick brown dog".to_string(),
"the lazy dog".to_string(),
];
let vectorizer = text::TfidfVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 3);
assert!(features.ncols() > 0);
let idf_weights = fitted.get_idf_weights();
assert_eq!(idf_weights.len(), features.ncols());
}
#[test]
fn test_count_vectorizer_binary() {
let documents = vec![
"the the quick brown fox".to_string(),
"the quick brown dog".to_string(),
];
let vectorizer = text::CountVectorizer::new().binary(true);
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
for &value in features.iter() {
if value > 0.0 {
assert!((value - 1.0).abs() < 1e-10);
}
}
}
#[test]
fn test_count_vectorizer_stop_words() {
let documents = vec![
"the quick brown fox".to_string(),
"the quick brown dog".to_string(),
];
let mut stop_words = HashSet::new();
stop_words.insert("the".to_string());
let stop_words_vec: Vec<String> = stop_words.into_iter().collect();
let vectorizer = text::CountVectorizer::new().stop_words(Some(stop_words_vec));
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let vocab = fitted.get_vocabulary();
if let Some(vocab_map) = vocab {
assert!(!vocab_map.contains_key("the")); assert!(vocab_map.contains_key("quick")); }
}
#[test]
fn test_count_vectorizer_ngram_range() {
let documents = vec![
"the quick brown fox".to_string(),
"the quick brown dog".to_string(),
];
let vectorizer = text::CountVectorizer::new().ngram_range((1, 2)); let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), documents.len());
let vocab = fitted.get_vocabulary();
if let Some(vocab_map) = vocab {
assert!(vocab_map.contains_key("quick"));
assert!(vocab_map.contains_key("brown"));
assert!(vocab_map.contains_key("the quick") || vocab_map.contains_key("quick brown"));
}
}
#[test]
fn test_count_vectorizer_min_max_df() {
let documents = vec![
"common word rare".to_string(),
"common word unusual".to_string(),
"common word unique".to_string(),
"common word distinct".to_string(),
];
let vectorizer = text::CountVectorizer::new()
.min_df(2) .max_df(3.0);
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let _vocab = fitted.get_vocabulary();
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 4);
}
#[test]
fn test_tfidf_vectorizer_sublinear_tf() {
let documents = vec!["cat cat cat dog".to_string(), "cat dog dog dog".to_string()];
let vectorizer_regular = text::TfidfVectorizer::new().sublinear_tf(false);
let vectorizer_sublinear = text::TfidfVectorizer::new().sublinear_tf(true);
let fitted_regular = vectorizer_regular
.fit(&documents, &())
.expect("operation should succeed");
let fitted_sublinear = vectorizer_sublinear
.fit(&documents, &())
.expect("operation should succeed");
let features_regular = fitted_regular
.transform(&documents)
.expect("operation should succeed");
let features_sublinear = fitted_sublinear
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features_regular.shape(), features_sublinear.shape());
let mut features_differ = false;
for (reg, sub) in features_regular.iter().zip(features_sublinear.iter()) {
if (reg - sub).abs() > 1e-10 {
features_differ = true;
break;
}
}
assert!(features_differ || features_regular == features_sublinear);
for &val in features_regular.iter() {
assert!(val.is_finite());
}
for &val in features_sublinear.iter() {
assert!(val.is_finite());
}
}
#[test]
fn test_tfidf_vectorizer_normalization() {
let documents = vec![
"the quick brown fox jumps".to_string(),
"the lazy dog sleeps".to_string(),
];
let vectorizer_l1 = text::TfidfVectorizer::new().norm(Some("l1".to_string()));
let vectorizer_l2 = text::TfidfVectorizer::new().norm(Some("l2".to_string()));
let vectorizer_none = text::TfidfVectorizer::new().norm(None);
let fitted_l1 = vectorizer_l1
.fit(&documents, &())
.expect("operation should succeed");
let fitted_l2 = vectorizer_l2
.fit(&documents, &())
.expect("operation should succeed");
let fitted_none = vectorizer_none
.fit(&documents, &())
.expect("operation should succeed");
let features_l1 = fitted_l1
.transform(&documents)
.expect("operation should succeed");
let features_l2 = fitted_l2
.transform(&documents)
.expect("operation should succeed");
let features_none = fitted_none
.transform(&documents)
.expect("operation should succeed");
for i in 0..features_l1.nrows() {
let row_sum: f64 = features_l1.row(i).iter().map(|&x| x.abs()).sum();
if row_sum > 0.0 {
assert!(
(row_sum - 1.0).abs() < 1e-10,
"L1 normalization failed for row {}",
i
);
}
}
for i in 0..features_l2.nrows() {
let row_norm: f64 = features_l2
.row(i)
.iter()
.map(|&x| x * x)
.sum::<f64>()
.sqrt();
if row_norm > 0.0 {
assert!(
(row_norm - 1.0).abs() < 1e-10,
"L2 normalization failed for row {}",
i
);
}
}
for &val in features_l1.iter() {
assert!(val.is_finite());
}
for &val in features_l2.iter() {
assert!(val.is_finite());
}
for &val in features_none.iter() {
assert!(val.is_finite());
}
}
#[test]
fn test_count_vectorizer_max_features() {
let documents = vec![
"apple banana cherry date elderberry".to_string(),
"fig grape honeydew kiwi lemon".to_string(),
"mango nectarine orange papaya quince".to_string(),
];
let vectorizer = text::CountVectorizer::new().max_features(Some(5));
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
let vocab = fitted.get_vocabulary();
if let Some(vocab_map) = &vocab {
assert!(vocab_map.len() <= 5);
}
assert!(features.ncols() <= 5);
if let Some(vocab_map) = &vocab {
if !vocab_map.is_empty() {
assert_eq!(vocab_map.len(), features.ncols());
}
}
}
#[test]
fn test_text_vectorizer_empty_documents() {
let documents = vec!["".to_string(), "word".to_string(), "".to_string()];
let vectorizer = text::CountVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 3);
let empty_row_sum: f64 = features.row(0).iter().sum();
let word_row_sum: f64 = features.row(1).iter().sum();
let empty_row2_sum: f64 = features.row(2).iter().sum();
assert_eq!(empty_row_sum, 0.0);
assert!(word_row_sum > 0.0);
assert_eq!(empty_row2_sum, 0.0);
}
#[test]
fn test_tfidf_vectorizer_single_document() {
let documents = vec!["single document with multiple words".to_string()];
let vectorizer = text::TfidfVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 1);
assert!(features.ncols() > 0);
let idf_weights = fitted.get_idf_weights();
for &idf in idf_weights.iter() {
assert!((idf - 1.0).abs() < 1e-10 || idf.is_finite());
}
for &val in features.iter() {
assert!(val.is_finite());
}
}
#[test]
fn test_count_vectorizer_case_sensitivity() {
let documents = vec![
"The Quick Brown Fox".to_string(),
"the quick brown fox".to_string(),
];
let vectorizer_case_sensitive = text::CountVectorizer::new().lowercase(false);
let vectorizer_case_insensitive = text::CountVectorizer::new().lowercase(true);
let fitted_sensitive = vectorizer_case_sensitive
.fit(&documents, &())
.expect("operation should succeed");
let fitted_insensitive = vectorizer_case_insensitive
.fit(&documents, &())
.expect("operation should succeed");
let vocab_sensitive = fitted_sensitive.get_vocabulary();
let vocab_insensitive = fitted_insensitive.get_vocabulary();
if let (Some(vocab_s), Some(vocab_i)) = (vocab_sensitive, vocab_insensitive) {
if vocab_s.len() > vocab_i.len() {
assert!(vocab_s.len() >= vocab_i.len());
}
if vocab_i.contains_key("the") {
assert!(!vocab_i.contains_key("The") || vocab_i.len() == vocab_s.len());
}
}
}
#[test]
fn test_text_tokenization_patterns() {
let documents = vec![
"word1 word2, word3! word4?".to_string(),
"email@domain.com and http://website.org".to_string(),
];
let vectorizer = text::CountVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let vocab = fitted.get_vocabulary();
if let Some(vocab_map) = vocab {
let has_basic_words = vocab_map.contains_key("word1")
|| vocab_map.contains_key("word2")
|| vocab_map.contains_key("word3")
|| vocab_map.contains_key("word4");
if !vocab_map.is_empty() {
assert!(has_basic_words, "Should tokenize basic words");
}
}
let features = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 2);
for &val in features.iter() {
assert!(val.is_finite());
}
}
#[test]
fn test_vectorizer_transform_unseen_documents() {
let train_documents = vec![
"train document one".to_string(),
"train document two".to_string(),
];
let test_documents = vec![
"test document with new words".to_string(),
"document one".to_string(), ];
let vectorizer = text::CountVectorizer::new();
let fitted = vectorizer
.fit(&train_documents, &())
.expect("operation should succeed");
let test_features = fitted
.transform(&test_documents)
.expect("operation should succeed");
assert_eq!(test_features.nrows(), 2);
assert_eq!(
test_features.ncols(),
fitted.get_vocabulary().map_or(0, |v| v.len())
);
for &val in test_features.iter() {
assert!(val.is_finite());
assert!(val >= 0.0); }
}
#[test]
fn test_tfidf_consistency() {
let documents = vec![
"cat dog bird".to_string(),
"dog bird fish".to_string(),
"bird fish cat".to_string(),
];
let vectorizer = text::TfidfVectorizer::new();
let fitted = vectorizer
.fit(&documents, &())
.expect("operation should succeed");
let features1 = fitted
.transform(&documents)
.expect("operation should succeed");
let features2 = fitted
.transform(&documents)
.expect("operation should succeed");
assert_eq!(features1.shape(), features2.shape());
for (f1, f2) in features1.iter().zip(features2.iter()) {
assert!((f1 - f2).abs() < 1e-12, "TF-IDF should be consistent");
}
}
#[test]
fn test_emotion_detector_basic_joy() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("I am so happy and excited! This is wonderful!");
assert_eq!(result.primary_emotion, text::EmotionType::Joy);
assert!(result.confidence > 0.0);
assert!(result.total_emotion_words > 0);
}
#[test]
fn test_emotion_detector_basic_sadness() {
let detector = text::EmotionDetector::new();
let result =
detector.detect_emotion("I am so sad and depressed. I feel miserable and hopeless.");
assert_eq!(result.primary_emotion, text::EmotionType::Sadness);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_basic_anger() {
let detector = text::EmotionDetector::new();
let result =
detector.detect_emotion("I am furious and angry! This is outrageous and infuriating!");
assert_eq!(result.primary_emotion, text::EmotionType::Anger);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_basic_fear() {
let detector = text::EmotionDetector::new();
let result =
detector.detect_emotion("I am so scared and frightened. I feel terrified and anxious.");
assert_eq!(result.primary_emotion, text::EmotionType::Fear);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_basic_surprise() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("Wow! I am so surprised and amazed! This is incredible!");
assert_eq!(result.primary_emotion, text::EmotionType::Surprise);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_basic_disgust() {
let detector = text::EmotionDetector::new();
let result = detector
.detect_emotion("This is disgusting and revolting! It's absolutely gross and nasty!");
assert_eq!(result.primary_emotion, text::EmotionType::Disgust);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_neutral() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("The meeting is scheduled for tomorrow at 3 PM.");
assert_eq!(result.primary_emotion, text::EmotionType::Neutral);
assert_eq!(result.total_emotion_words, 0);
}
#[test]
fn test_emotion_detector_empty_text() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("");
assert_eq!(result.primary_emotion, text::EmotionType::Neutral);
assert_eq!(result.total_words, 0);
assert_eq!(result.confidence, 0.0);
}
#[test]
fn test_emotion_detector_custom_words() {
let detector = text::EmotionDetector::new().add_custom_emotion_words(
text::EmotionType::Joy,
vec!["awesome".to_string(), "epic".to_string()],
);
let result = detector.detect_emotion("This is totally epic and awesome!");
assert_eq!(result.primary_emotion, text::EmotionType::Joy);
assert!(result.confidence > 0.0);
}
#[test]
fn test_emotion_detector_mixed_emotions() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("I'm happy but also worried and anxious.");
assert!(result.primary_emotion != text::EmotionType::Neutral);
assert!(result.total_emotion_words >= 3);
let joy_score = result
.emotion_scores
.get(&text::EmotionType::Joy)
.unwrap_or(&0.0);
let fear_score = result
.emotion_scores
.get(&text::EmotionType::Fear)
.unwrap_or(&0.0);
assert!(joy_score > &0.0 || fear_score > &0.0);
}
#[test]
fn test_emotion_detector_secondary_emotion() {
let detector = text::EmotionDetector::new();
let result = detector.detect_emotion("I'm mostly happy and joyful but slightly worried.");
let secondary = result.secondary_emotion();
assert!(secondary.is_some());
if let Some((emotion, score)) = secondary {
assert!(score > 0.0);
assert!(emotion != result.primary_emotion);
}
}
#[test]
fn test_emotion_detector_intensity() {
let detector = text::EmotionDetector::new();
let high_intensity = detector.detect_emotion("Happy happy happy joy joy joy!");
let low_intensity = detector.detect_emotion("This is a happy day with some other words.");
assert!(high_intensity.intensity() > low_intensity.intensity());
}
#[test]
fn test_emotion_detector_case_insensitive() {
let detector = text::EmotionDetector::new().case_sensitive(false);
let result1 = detector.detect_emotion("HAPPY EXCITED WONDERFUL");
let result2 = detector.detect_emotion("happy excited wonderful");
assert_eq!(result1.primary_emotion, text::EmotionType::Joy);
assert_eq!(result2.primary_emotion, text::EmotionType::Joy);
}
#[test]
fn test_emotion_detector_extract_features() {
let detector = text::EmotionDetector::new();
let documents = vec![
"I am so happy and excited!".to_string(),
"I feel sad and depressed.".to_string(),
"I am angry and frustrated.".to_string(),
];
let features = detector
.extract_features(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 3);
assert_eq!(features.ncols(), 14);
for &val in features.iter() {
assert!(val.is_finite());
}
let joy_features = features.row(0);
let sadness_features = features.row(1);
assert!(joy_features[0] > sadness_features[0]);
assert!(sadness_features[1] > joy_features[1]);
}
#[test]
fn test_emotion_detector_extract_features_empty() {
let detector = text::EmotionDetector::new();
let documents: Vec<String> = vec![];
let result = detector.extract_features(&documents);
assert!(result.is_err());
}
#[test]
fn test_emotion_detector_confidence_threshold() {
let detector = text::EmotionDetector::new().min_confidence(0.5);
let result = detector.detect_emotion("I'm slightly happy in this long sentence with many other words that are not emotional at all.");
assert!(result.confidence < 0.5 || result.primary_emotion != text::EmotionType::Neutral);
}
#[test]
fn test_emotion_detector_distribution() {
let detector = text::EmotionDetector::new();
let documents = vec![
"I am happy!".to_string(),
"I am joyful!".to_string(),
"I am sad.".to_string(),
"I am angry!".to_string(),
"Neutral text here.".to_string(),
];
let distribution = detector.analyze_distribution(&documents);
assert!(distribution.len() > 1);
assert_eq!(*distribution.get(&text::EmotionType::Joy).unwrap_or(&0), 2);
assert_eq!(
*distribution.get(&text::EmotionType::Sadness).unwrap_or(&0),
1
);
assert_eq!(
*distribution.get(&text::EmotionType::Anger).unwrap_or(&0),
1
);
}
#[test]
fn test_emotion_detector_all_emotions() {
let all_emotions = text::EmotionType::all_emotions();
assert_eq!(all_emotions.len(), 6);
assert!(!all_emotions.contains(&text::EmotionType::Neutral));
}
#[test]
fn test_emotion_type_as_str() {
assert_eq!(text::EmotionType::Joy.as_str(), "joy");
assert_eq!(text::EmotionType::Sadness.as_str(), "sadness");
assert_eq!(text::EmotionType::Anger.as_str(), "anger");
assert_eq!(text::EmotionType::Fear.as_str(), "fear");
assert_eq!(text::EmotionType::Surprise.as_str(), "surprise");
assert_eq!(text::EmotionType::Disgust.as_str(), "disgust");
assert_eq!(text::EmotionType::Neutral.as_str(), "neutral");
}
#[test]
fn test_aspect_sentiment_basic() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string(), "service".to_string()]);
let result = analyzer.analyze("The food was great but the service was terrible.");
assert!(!result.is_empty());
let food_aspect = result.iter().find(|a| a.aspect == "food");
let service_aspect = result.iter().find(|a| a.aspect == "service");
assert!(food_aspect.is_some());
assert!(service_aspect.is_some());
if let Some(aspect) = food_aspect {
assert_eq!(aspect.sentiment, text::SentimentPolarity::Positive);
}
if let Some(aspect) = service_aspect {
assert!(aspect.score <= 0.0 || aspect.sentiment != text::SentimentPolarity::Positive);
}
}
#[test]
fn test_aspect_sentiment_auto_extract() {
let analyzer = text::AspectBasedSentimentAnalyzer::new().auto_extract_aspects(true);
let result = analyzer.analyze("The food was excellent and the atmosphere was wonderful.");
assert!(!result.is_empty());
let has_food = result.iter().any(|a| a.aspect == "food");
let has_atmosphere = result.iter().any(|a| a.aspect == "atmosphere");
assert!(has_food || has_atmosphere);
}
#[test]
fn test_aspect_sentiment_context_window() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["product".to_string()])
.context_window(2);
let result = analyzer.analyze("The product is great.");
assert!(!result.is_empty());
if let Some(aspect) = result.first() {
assert_eq!(aspect.sentiment, text::SentimentPolarity::Positive);
}
}
#[test]
fn test_aspect_sentiment_opinion_words() {
let analyzer = text::AspectBasedSentimentAnalyzer::new().add_aspects(vec!["food".to_string()]);
let result = analyzer.analyze("The food was absolutely wonderful and amazing!");
assert!(!result.is_empty());
if let Some(aspect) = result.first() {
assert!(!aspect.opinion_words.is_empty());
}
}
#[test]
fn test_aspect_sentiment_min_confidence() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["product".to_string()])
.min_confidence(0.5);
let _result1 = analyzer.analyze("The product is here in this place with other things.");
let result2 = analyzer.analyze("The product is great and wonderful!");
if !result2.is_empty() {
assert!(result2[0].confidence >= 0.0);
}
}
#[test]
fn test_aspect_sentiment_multi_word() {
let analyzer =
text::AspectBasedSentimentAnalyzer::new().add_aspects(vec!["customer service".to_string()]);
let result = analyzer.analyze("The customer service was excellent and helpful.");
let has_customer_service = result.iter().any(|a| a.aspect == "customer service");
assert!(has_customer_service || !result.is_empty()); }
#[test]
fn test_aspect_sentiment_extract_features() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string(), "service".to_string()]);
let documents = vec![
"The food was great but the service was terrible.".to_string(),
"Both food and service were excellent!".to_string(),
"The service was okay, food was amazing.".to_string(),
];
let features = analyzer
.extract_features(&documents)
.expect("operation should succeed");
assert_eq!(features.nrows(), 3);
assert_eq!(features.ncols(), 6);
for &val in features.iter() {
assert!(val.is_finite());
}
}
#[test]
fn test_aspect_sentiment_extract_features_empty() {
let analyzer = text::AspectBasedSentimentAnalyzer::new();
let documents: Vec<String> = vec![];
let result = analyzer.extract_features(&documents);
assert!(result.is_err());
}
#[test]
fn test_aspect_sentiment_aggregate() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string(), "service".to_string()]);
let documents = vec![
"The food was great!".to_string(),
"The food was okay.".to_string(),
"The service was terrible.".to_string(),
];
let aggregated = analyzer.aggregate_aspects(&documents);
assert!(aggregated.contains_key("food") || aggregated.contains_key("service"));
if let Some(food_sentiments) = aggregated.get("food") {
assert!(!food_sentiments.is_empty());
}
}
#[test]
fn test_aspect_sentiment_summary() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string(), "service".to_string()]);
let documents = vec![
"The food was great!".to_string(),
"The food was excellent!".to_string(),
"The service was okay.".to_string(),
];
let summary = analyzer.aspect_summary(&documents);
assert!(!summary.is_empty());
if summary.len() > 1 {
assert!(summary[0].2 >= summary[1].2);
}
}
#[test]
fn test_aspect_sentiment_empty_text() {
let analyzer = text::AspectBasedSentimentAnalyzer::new().add_aspects(vec!["food".to_string()]);
let result = analyzer.analyze("");
assert!(result.is_empty());
}
#[test]
fn test_aspect_sentiment_no_aspects_found() {
let analyzer = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string()])
.auto_extract_aspects(false);
let result = analyzer.analyze("This is a great day!");
assert!(result.is_empty());
}
#[test]
fn test_aspect_sentiment_case_sensitivity() {
let analyzer_sensitive = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["Food".to_string()])
.case_sensitive(true);
let analyzer_insensitive = text::AspectBasedSentimentAnalyzer::new()
.add_aspects(vec!["food".to_string()])
.case_sensitive(false);
let text = "The food was great!";
let _result_sensitive = analyzer_sensitive.analyze(text);
let result_insensitive = analyzer_insensitive.analyze(text);
assert!(!result_insensitive.is_empty());
}
#[test]
fn test_aspect_sentiment_multiple_occurrences() {
let analyzer =
text::AspectBasedSentimentAnalyzer::new().add_aspects(vec!["product".to_string()]);
let result = analyzer.analyze("The product is great. Another product is terrible.");
assert!(!result.is_empty());
}