tokmd_analysis_types/
topics.rs1use std::collections::BTreeMap;
7
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct TopicClouds {
12 pub per_module: BTreeMap<String, Vec<TopicTerm>>,
13 pub overall: Vec<TopicTerm>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct TopicTerm {
18 pub term: String,
19 pub score: f64,
20 pub tf: u32,
21 pub df: u32,
22}
23
24#[cfg(test)]
25mod tests {
26 use super::TopicTerm;
27
28 #[test]
29 fn topic_term_serde_roundtrip() -> Result<(), Box<dyn std::error::Error>> {
30 let term = TopicTerm {
31 term: "async".into(),
32 score: 0.95,
33 tf: 10,
34 df: 3,
35 };
36 let json = serde_json::to_string(&term)?;
37 let back: TopicTerm = serde_json::from_str(&json)?;
38 assert_eq!(back.term, "async");
39 assert_eq!(back.tf, 10);
40 Ok(())
41 }
42}