Commit 32ec660b authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

wip: Handle syllable counting edge cases

parent 4a9a2b8a
Loading
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
use crate::constants::{IRREGULAR_NOUNS, IRREGULAR_NOUNS_INVERTED, NON_ALPHABETIC, SAME_SINGULAR_PLURAL};
use crate::constants::{IRREGULAR_NOUNS, IRREGULAR_NOUNS_INVERTED, NEED_TO_BE_FIXED, NON_ALPHABETIC, PROBLEMATIC_WORDS, SAME_SINGULAR_PLURAL};
use console::Emoji;
use data_encoding::HEXUPPER;
use derive_more::Display;
@@ -443,7 +443,32 @@ pub fn get_syllable_count(text: &str) -> usize {
        NON_ALPHABETIC.replace_all(value, "").to_lowercase()
    }
    fn get_syllables(word: String) -> usize {
        word.len()
        let singular = get_singular_form(&word);
        match word.as_str() {
            | "" => 0,
            | value if value.len() < 3 => 1,
            | value if NEED_TO_BE_FIXED.contains_key(value) => match NEED_TO_BE_FIXED.get(value) {
                | Some(x) => *x,
                | None => 0,
            },
            | value if PROBLEMATIC_WORDS.contains_key(value) => match PROBLEMATIC_WORDS.get(value) {
                | Some(x) => *x,
                | None => 0,
            },
            | _ if NEED_TO_BE_FIXED.contains_key(&singular.as_str()) => match NEED_TO_BE_FIXED.get(singular.as_str()) {
                | Some(x) => *x,
                | None => 0,
            },
            | _ if PROBLEMATIC_WORDS.contains_key(&singular.as_str()) => match PROBLEMATIC_WORDS.get(singular.as_str()) {
                | Some(x) => *x,
                | None => 0,
            },
            | _ => {
                let mut count = 0;
                count += 1;
                count
            }
        }
    }
    let tokens = text.split_whitespace().map(sanitize).collect::<Vec<String>>();
    tokens.into_iter().map(get_syllables).sum()
+12 −1
Original line number Diff line number Diff line
@@ -61,9 +61,20 @@ fn test_get_singular_form() {
    assert_eq!("vertex", get_singular_form("vertices"));
}
#[test]
fn test_get_syllable_count() {
fn test_get_syllable_count_simple() {
    assert_eq!(0, get_syllable_count(""));
    assert_eq!(1, get_syllable_count("a"));
    assert_eq!(1, get_syllable_count("and"));
    assert_eq!(1, get_syllable_count("is"));
    assert_eq!(1, get_syllable_count("of"));
    assert_eq!(1, get_syllable_count("the"));
    assert_eq!(1, get_syllable_count("wine"));
    // assert_eq!(2, get_syllable_count("hello"));
    // assert_eq!(2, get_syllable_count("pizza"));
    // assert_eq!(2, get_syllable_count("bottle"));
    // assert_eq!(2, get_syllable_count("project"));
    // assert_eq!(3, get_syllable_count("syllable"));
    // assert_eq!(4, get_syllable_count("innovation"));
}
#[test]
fn test_is_ip6() {}