@@ -252,6 +252,47 @@ impl<S: BuildHasher> Dictionary<S> {
252252 self . words . insert ( word, flagset) ;
253253 Ok ( ( ) )
254254 }
255+
256+ /// Removes the given stem from the dictionary.
257+ ///
258+ /// Once removed, `check` will return `false` for all conjugations of the stem. For example
259+ /// "adventuring" in the `en_US` dictionary is based on the stem "adventure" with the "ing"
260+ /// suffix applied. Removing "adventuring" does nothing while removing "adventure" removes
261+ /// "adventuring", "adventured", etc..
262+ ///
263+ /// This function returns `true` if any stem in the dictionary is removed, otherwise `false`.
264+ ///
265+ /// # Example
266+ ///
267+ /// ```
268+ /// let aff = std::fs::read_to_string("./vendor/en_US/en_US.aff").unwrap();
269+ /// let dic = std::fs::read_to_string("./vendor/en_US/en_US.dic").unwrap();
270+ /// let mut dict = spellbook::Dictionary::new(&aff, &dic).unwrap();
271+ ///
272+ /// assert!(dict.check("adventure"));
273+ /// assert!(dict.check("adventuring"));
274+ ///
275+ /// // `remove` only works on stems.
276+ /// assert!(!dict.remove_stem("adventuring"));
277+ /// assert!(dict.check("adventure"));
278+ /// assert!(dict.check("adventuring"));
279+ /// // Removing the stem removes all conjugations.
280+ /// assert!(dict.remove_stem("adventure"));
281+ /// assert!(!dict.check("adventure"));
282+ /// assert!(!dict.check("adventuring"));
283+ /// // Once removed, removing the same stem again is a no-op.
284+ /// assert!(!dict.remove_stem("adventure"));
285+ /// ```
286+ pub fn remove_stem ( & mut self , word : & str ) -> bool {
287+ let mut did_remove = false ;
288+ for flags in self . words . get_mut ( word) {
289+ if !flags. contains ( & self . aff_data . options . forbidden_word_flag ) {
290+ did_remove = true ;
291+ * flags = flags. with_flag ( self . aff_data . options . forbidden_word_flag ) ;
292+ }
293+ }
294+ did_remove
295+ }
255296}
256297
257298impl fmt:: Debug for Dictionary {
0 commit comments