summarize_text

Function summarize_text 

Source
pub fn summarize_text(
    input_text: &str,
    compress_coof: f64,
) -> Result<(String, HashMap<String, usize>)>
Expand description

Summarizes input text and returns it with keywords (Summarized, Keywords)

Examples found in repository?
examples/example.rs (line 19)
3fn main() -> Result<()> {
4    let input_text = r#"
5Rust is a programming language focused on security, speed, and concurrency. 
6It helps you write fast and reliable software. Rust is especially good for system programming,
7where performance and no memory errors are important. 
8
9Most programming languages struggle with the issue of memory security. 
10Rust solves this problem by checking at the compilation stage. 
11The Rust compiler guarantees memory safety without a garbage collector.
12
13The syntax of Rust is similar to C++, but with modern features. 
14The language supports a powerful type system and memory borrowing. 
15Rust is popular for web builds, network applications, and embedded systems.
16"#;
17
18    let compress_coof = 3.0;
19    let (summary, keywords) = summarize_text(input_text, compress_coof)?;
20    
21    println!("=== Compression level: {compress_coof:.1} ===");
22    println!("=== Summary text: ===");
23    println!("{}", summary);
24    
25    println!("\n=== Keywords: ===");
26    for (word, count) in keywords {
27        println!("{}: {}", word, count);
28    }
29
30    println!("\n=== Compressed: ===");
31    let input_count = input_text.chars().count();
32    let output_count = summary.chars().count();
33    println!("Chars: -{chars} \nCoof: -{coof:.2}%",
34        chars = (input_count as i32 - output_count as i32).abs(),
35        coof = 100.0 - (output_count as f64 * 100.0 / input_count as f64),
36    );
37    
38    Ok(())
39}