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
#![allow(dead_code)]
#[macro_use]
extern crate lazy_static;
extern crate threads_pool;
mod candidate;
mod common;
mod dynamic_mode;
pub mod prelude {
pub use AutoCorrect;
pub use candidate::Candidate;
}
use candidate::Candidate;
use threads_pool::*;
static MAX_EDIT: u8 = 2;
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum SupportedLocale {
EnUs,
}
pub struct AutoCorrect {
pub max_edit: u8,
pool: ThreadPool,
locale: SupportedLocale,
}
impl AutoCorrect {
pub fn new() -> AutoCorrect {
AutoCorrect::new_with_locale(SupportedLocale::EnUs)
}
fn new_with_locale(locale: SupportedLocale) -> AutoCorrect {
let max_edit = if MAX_EDIT > 3 {
3
} else if MAX_EDIT < 1 {
1
} else {
MAX_EDIT
};
let pool = ThreadPool::new(2);
let service = AutoCorrect {
max_edit,
pool,
locale,
};
dynamic_mode::initialize(&service);
service
}
pub fn candidates(&self, word: String) -> Vec<Candidate> {
dynamic_mode::candidate(self.locale.clone(), word, 0, self.max_edit, &self.pool)
}
}