Skip to main content

xls_rs/text_analysis/
types.rs

1//! Types for text analysis operations
2
3use serde::{Deserialize, Serialize};
4
5/// Text analysis statistics
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct TextStats {
8    pub word_count: usize,
9    pub character_count: usize,
10    pub sentence_count: usize,
11    pub paragraph_count: usize,
12    pub avg_word_length: f64,
13    pub avg_sentence_length: f64,
14    pub readability_score: f64,
15    pub unique_words: usize,
16    pub lexical_diversity: f64,
17}
18
19/// Sentiment analysis result
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct SentimentResult {
22    pub sentiment: Sentiment,
23    pub confidence: f64,
24    pub positive_score: f64,
25    pub negative_score: f64,
26    pub neutral_score: f64,
27}
28
29/// Sentiment classification
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub enum Sentiment {
32    Positive,
33    Negative,
34    Neutral,
35}
36
37/// Keyword extraction result
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct KeywordResult {
40    pub keywords: Vec<Keyword>,
41    pub total_keywords: usize,
42}
43
44/// Individual keyword
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct Keyword {
47    pub word: String,
48    pub score: f64,
49    pub frequency: usize,
50    pub importance: Importance,
51}
52
53/// Keyword importance level
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub enum Importance {
56    High,
57    Medium,
58    Low,
59}
60
61/// Language detection result
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct LanguageResult {
64    pub language: String,
65    pub confidence: f64,
66    pub supported_languages: Vec<String>,
67}
68
69/// Sentiment word lists
70#[derive(Debug, Clone)]
71pub struct SentimentWords {
72    pub positive: std::collections::HashSet<String>,
73    pub negative: std::collections::HashSet<String>,
74    pub neutral: std::collections::HashSet<String>,
75}