Debian Codegraph @

src/main.rs

raw symbols SCIP
1 use rust_fuzzy_search::*;
2
3 fn main() {
4 fuzzy_compare("kolbaso", "kolbasobulko");
5 }
6
7 #[allow(dead_code)]
8 fn simple_search() {
9 let s = "bulko";
10 let list: Vec<&str> = vec!["kolbasobulko", "sandviĉo"];
11 let res = fuzzy_search(&s, &list);
12 for x in res {
13 println!("{:?}", x)
14 }
15 }
16
17 #[allow(dead_code)]
18 fn search_through_file() {
19 use std::fs::File;
20 use std::io::Read;
21
22 // string to search in the file
23 let input = "colos";
24
25 // filename
26 let filename = "src/example_file.txt";
27
28 // creates a buffer and reads the file
29 let mut buffer = String::new();
30 File::open(filename)
31 .unwrap()
32 .read_to_string(&mut buffer)
33 .unwrap();
34
35 // split the string in the buffer in words
36 let dict: Vec<&str> = buffer.split(' ').collect();
37
38 // gets the n (10usize) best matches
39 let ress = fuzzy_search_best_n(&input, &dict, 10usize);
40
41 // prints all the matches
42 for (x, d) in ress {
43 println!("word : {:?} \t\t\t\t score : {:?}", x, d);
44 }
45 }
46
47 #[allow(dead_code)]
48 fn repl_compare() {
49 use std::io;
50 loop {
51 println!("write 2 lines:");
52
53 // creates 2 buffers to read from stdin
54 let mut buffer1 = String::new();
55 let mut buffer2 = String::new();
56
57 // reads 2 lines from stdin
58 io::stdin().read_line(&mut buffer1).unwrap();
59 io::stdin().read_line(&mut buffer2).unwrap();
60
61 // test quit instruction (user typed something similar to "quit")
62 if fuzzy_compare(&buffer1, &"quit") > 0.9 {
63 println!("quit : quitting");
64 break;
65 }
66
67 // compares strings and prints the score
68 let distance = fuzzy_compare(&buffer1, &buffer2);
69 println!("distance is {:?}", distance);
70 }
71 }
72
73 #[allow(dead_code)]
74 fn simple_searches() {
75 println!(
76 "bulubulu - bulubulu : {:?}",
77 fuzzy_compare(&"bulubulu".to_string(), &"bulubulu".to_string())
78 );
79 println!(
80 "sandviĉo - sandviĉo : {:?}",
81 fuzzy_compare(&"sandviĉo".to_string(), &"sandviĉo".to_string())
82 );
83 println!(
84 "sandviĉo - kolbasobulko : {:?}",
85 fuzzy_compare(&"sandviĉo".to_string(), &"kolbasobulko".to_string())
86 );
87 println!(
88 "varma vetero - vetero : {:?}",
89 fuzzy_compare(&"varma vetero".to_string(), &"vetero".to_string())
90 );
91 }