| 1 | use rust_fuzzy_searchrust-analyzer cargo rust-fuzzy-search 0.1.1 crate/::*; |
| 2 | |
| 3 | fn mainrust-analyzer cargo rust-fuzzy-search 0.1.1 main().() { |
| 4 | fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().("kolbaso", "kolbasobulko"); |
| 5 | } |
| 6 | |
| 7 | #[allow(dead_code)] |
| 8 | fn simple_searchrust-analyzer cargo rust-fuzzy-search 0.1.1 simple_search().() { |
| 9 | let s = "bulko"; |
| 10 | let list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["kolbasobulko", "sandviĉo"]; |
| 11 | let res = fuzzy_searchrust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_search().(&s, &list); |
| 12 | for x in res { |
| 13 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", x) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | #[allow(dead_code)] |
| 18 | fn search_through_filerust-analyzer cargo rust-fuzzy-search 0.1.1 search_through_file().() { |
| 19 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 20 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/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 = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 30 | Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(filename) |
| 31 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 32 | .read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read_to_string().(&mut buffer) |
| 33 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 34 | |
| 35 | // split the string in the buffer in words |
| 36 | let dict: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = buffer.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 37 | |
| 38 | // gets the n (10usize) best matches |
| 39 | let ress = fuzzy_search_best_nrust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_search_best_n().(&input, &dict, 10usize); |
| 40 | |
| 41 | // prints all the matches |
| 42 | for (x, d) in ress { |
| 43 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("word : {:?} \t\t\t\t score : {:?}", x, d); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | #[allow(dead_code)] |
| 48 | fn repl_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 repl_compare().() { |
| 49 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 50 | loop { |
| 51 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("write 2 lines:"); |
| 52 | |
| 53 | // creates 2 buffers to read from stdin |
| 54 | let mut buffer1 = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 55 | let mut buffer2 = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 56 | |
| 57 | // reads 2 lines from stdin |
| 58 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut buffer1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 59 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut buffer2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 60 | |
| 61 | // test quit instruction (user typed something similar to "quit") |
| 62 | if fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&buffer1, &"quit") rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]gt().0.9 { |
| 63 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("quit : quitting"); |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | // compares strings and prints the score |
| 68 | let distance = fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&buffer1, &buffer2); |
| 69 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("distance is {:?}", distance); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | #[allow(dead_code)] |
| 74 | fn simple_searchesrust-analyzer cargo rust-fuzzy-search 0.1.1 simple_searches().() { |
| 75 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 76 | "bulubulu - bulubulu : {:?}", |
| 77 | fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&"bulubulu".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), &"bulubulu".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 78 | ); |
| 79 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 80 | "sandviĉo - sandviĉo : {:?}", |
| 81 | fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&"sandviĉo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), &"sandviĉo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 82 | ); |
| 83 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 84 | "sandviĉo - kolbasobulko : {:?}", |
| 85 | fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&"sandviĉo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), &"kolbasobulko".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 86 | ); |
| 87 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 88 | "varma vetero - vetero : {:?}", |
| 89 | fuzzy_comparerust-analyzer cargo rust-fuzzy-search 0.1.1 fuzzy_compare().(&"varma vetero".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), &"vetero".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 90 | ); |
| 91 | } |