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