@@ -115,15 +115,13 @@ where
115
115
/// Quickly, stably dedupe strings by fuzzily comparing them to each other.
116
116
/// Delegates to [dedupe_full].
117
117
pub fn dedupe < ' a > ( items : & [ & ' a str ] , threshold : Score ) -> Vec < & ' a str > {
118
- // TODO: use a better default scorer
119
- let temp_scorer = |a : & & str , b : & & str | wratio ( a, b, true , true ) . try_into ( ) . unwrap ( ) ;
120
- // TODO: extract this default sorter
118
+ let scorer = |a : & & str , b : & & str | wratio ( a, b, true , true ) . try_into ( ) . unwrap ( ) ;
121
119
let sorter = |a : & & str , b : & & str | match a. len ( ) . cmp ( & b. len ( ) ) {
122
120
Ordering :: Less => Ordering :: Less ,
123
121
Ordering :: Greater => Ordering :: Greater ,
124
122
Ordering :: Equal => a. cmp ( b) ,
125
123
} ;
126
- dedupe_full ( items, threshold, temp_scorer , sorter, true )
124
+ dedupe_full ( items, threshold, scorer , sorter, true )
127
125
. into_iter ( )
128
126
. map ( |s| * s)
129
127
. collect ( )
@@ -152,6 +150,7 @@ pub fn dedupe<'a>(items: &[&'a str], threshold: Score) -> Vec<&'a str> {
152
150
/// # use core::cmp::Ordering;
153
151
/// # use core::convert::TryInto;
154
152
/// # use fuzzywuzzy::primitives::{Match, Score};
153
+ /// # use fuzzywuzzy::fuzzywuzzy_compatible::fuzz::wratio;
155
154
/// # use fuzzywuzzy::fuzzywuzzy_compatible::process::{ default_processor, default_scorer, dedupe_full };
156
155
/// let frodo_baggin = "Frodo Baggin";
157
156
/// let frodo_baggins = "Frodo Baggins";
@@ -164,23 +163,16 @@ pub fn dedupe<'a>(items: &[&'a str], threshold: Score) -> Vec<&'a str> {
164
163
/// let expected_stable = vec![&frodo_baggins, &samwise, &gandalf, &bilbo];
165
164
/// // ... but not when we don't require `stable`.
166
165
/// let expected_unstable = vec![&samwise, &gandalf, &frodo_baggins, &bilbo];
167
- /// # // TODO: fix temp scorer
168
- /// let temp_scorer = |a: &&str, b: &&str| {
169
- /// if a.chars().next() == b.chars().next() {
170
- /// 100u8.try_into().unwrap()
171
- /// } else {
172
- /// 0u8.try_into().unwrap()
173
- /// }
174
- /// };
166
+ /// let scorer = |a: &&str, b: &&str| wratio(a, b, true, true).try_into().unwrap();
175
167
/// let sorter = |a: &&str, b: &&str| {
176
168
/// match a.len().cmp(&b.len()) {
177
169
/// Ordering::Less => Ordering::Less,
178
170
/// Ordering::Greater => Ordering::Greater,
179
171
/// Ordering::Equal => a.cmp(b),
180
172
/// }
181
173
/// };
182
- /// assert_eq!(dedupe_full(&contains_dupes, 70.try_into().unwrap(), temp_scorer , sorter, true), expected_stable);
183
- /// assert_eq!(dedupe_full(&contains_dupes, 70.try_into().unwrap(), temp_scorer , sorter, false), expected_unstable);
174
+ /// assert_eq!(dedupe_full(&contains_dupes, 70.try_into().unwrap(), scorer , sorter, true), expected_stable);
175
+ /// assert_eq!(dedupe_full(&contains_dupes, 70.try_into().unwrap(), scorer , sorter, false), expected_unstable);
184
176
/// ```
185
177
pub fn dedupe_full < ' a , A : ' a + Eq + Ord > (
186
178
items : & ' a [ A ] ,
0 commit comments