symspell_rs/lib.rs
1/*!
2
3Spelling correction & Fuzzy search based on Symmetric Delete spelling correction algorithm.
4
5#### Usage of SymSpell Library
6
7Single word spelling correction
8```rust
9use symspell_rs::{SymSpell, Verbosity};
10use std::path::Path;
11
12let max_edit_distance_dictionary = 2; //maximum edit distance per dictionary precalculation
13let mut symspell: SymSpell = SymSpell::new(max_edit_distance_dictionary,None, 7, 1);
14
15// single term dictionary
16let term_index = 0; //column of the term in the dictionary text file
17let count_index = 1; //column of the term frequency in the dictionary text file
18symspell.load_dictionary(Path::new("data/frequency_dictionary_en_82_765.txt"), term_index, count_index, " ");
19
20//lookup suggestions for single-word input strings
21let input_term = "hous";
22let suggestion_verbosity = Verbosity::Closest;//Top, Closest, All
23let max_edit_distance_lookup = 1; //max edit distance per lookup (maxEditDistanceLookup<=maxEditDistanceDictionary)
24let suggestions = symspell.lookup(input_term, suggestion_verbosity, max_edit_distance_lookup,&None,None,false);
25//display suggestions, edit distance and term frequency
26println!("{:?}", suggestions);
27```
28
29Compound aware multi-word spelling correction
30```rust
31use symspell_rs::{SymSpell, Verbosity};
32use std::path::Path;
33
34let max_edit_distance_dictionary = 2; //maximum edit distance per dictionary precalculation
35let mut symspell = SymSpell::new(max_edit_distance_dictionary, None,7, 1);
36
37// single term dictionary
38let term_index = 0; //column of the term in the dictionary text file
39let count_index = 1; //column of the term frequency in the dictionary text file
40symspell.load_dictionary(Path::new("data/frequency_dictionary_en_82_765.txt"), term_index, count_index, " ");
41// bigram dictionary
42symspell.load_bigram_dictionary(Path::new("data/frequency_bigramdictionary_en_243_342.txt"),0,2, " ",
43);
44
45//lookup suggestions for multi-word input strings (supports compound splitting & merging)
46let input_sentence = "whereis th elove hehad dated forImuch of thepast who couqdn'tread in sixtgrade and ins pired him";
47let max_edit_distance_lookup = 2; //max edit distance per lookup (per single word, not per whole input string)
48let compound_suggestions = symspell.lookup_compound(input_sentence, max_edit_distance_lookup,&None,false);
49//display suggestions, edit distance and term frequency
50println!("{:?}", compound_suggestions);
51```
52
53Word Segmentation of noisy text
54```rust
55use symspell_rs::{SymSpell, Verbosity};
56use std::path::Path;
57
58let max_edit_distance_dictionary = 0; //maximum edit distance per dictionary precalculation
59let mut symspell = SymSpell::new(max_edit_distance_dictionary, None,7, 1);
60
61// single term dictionary
62let term_index = 0; //column of the term in the dictionary text file
63let count_index = 1; //column of the term frequency in the dictionary text file
64symspell.load_dictionary(Path::new("data/frequency_dictionary_en_82_765.txt"), term_index, count_index, " ");
65
66//word segmentation and correction for multi-word input strings with/without spaces
67let input_sentence = "thequickbrownfoxjumpsoverthelazydog";
68let max_edit_distance_lookup = 0;
69let result = symspell.word_segmentation(input_sentence, max_edit_distance_lookup);
70//display term and edit distance
71println!("{:?}", result.segmented_string);
72```
73
74Word Segmentation of Chinese text
75```rust
76use symspell_rs::{SymSpell, Verbosity};
77use std::path::Path;
78
79let max_edit_distance_dictionary = 0; //maximum edit distance per dictionary precalculation
80let mut symspell = SymSpell::new(max_edit_distance_dictionary,None, 7, 1);
81
82// single term dictionary
83let term_index = 0; //column of the term in the dictionary text file
84let count_index = 1; //column of the term frequency in the dictionary text file
85symspell.load_dictionary(Path::new("data/frequency_dictionary_zh_cn_349_045.txt"), term_index, count_index, " ");
86
87//word segmentation and correction for multi-word input strings with/without spaces
88let input_sentence = "部分居民生活水平";
89let max_edit_distance_lookup = 0;
90let result = symspell.word_segmentation(input_sentence, max_edit_distance_lookup);
91//display term and edit distance
92println!("{:?}", result.segmented_string);
93```
94
95*/
96
97#[doc = include_str!("../README.md")]
98#[cfg(doctest)]
99pub struct ReadmeDoctests;
100
101mod symspell;
102mod test;
103pub use symspell::{Suggestion, SymSpell, Verbosity, damerau_levenshtein_osa};