fn generate_lookup_keys(jm_entry: &WordEntry) -> Vec<(String, u32)> {
    let mut keys = Vec::new();

    let mut end_replace_push = |word: &str, trail: &str, endings: &[&str]| {
        // If a word is usually written in kana, give the kana form a major
        // priority boost.
        let priority = if is_all_kana(word) && jm_entry.usually_kana {
            jm_entry.priority / 8
        } else {
            jm_entry.priority
        };

        // We include the katakana version for all-hiragana
        // words as well because for some reason that's how Kobo
        // looks up hiragana words.  Leaving this out causes the Kobo
        // to completely fail to find entries for all-hirigana words.
        if is_all_kana(word) {
            keys.push((hiragana_to_katakana(word), priority));
        }
        keys.push((word.into(), priority));

        if trail.len() > 0 && word.len() >= trail.len() && word.ends_with(trail) {
            let stem = {
                let mut stem: String = word.into();
                stem.truncate(word.len() - trail.len());
                stem
            };

            for end in endings.iter() {
                let variant = format!("{}{}", stem, end);
                if is_all_kana(&variant) {
                    keys.push((hiragana_to_katakana(&variant), priority));
                }
                keys.push((variant, priority));
            }
        }
    };

    let mut forms: Vec<_> = jm_entry
        .writings
        .iter()
        .chain(if jm_entry.usually_kana {
            jm_entry.readings.iter()
        } else {
            (&jm_entry.readings[0..1]).iter()
        })
        .collect();
    forms.sort();
    forms.dedup();

    use ConjugationClass::*;
    for word in forms.iter() {
        match jm_entry.conj {
            IchidanVerb => {
                end_replace_push(word, "る", &["", "られ", "させ", "ろ", "て", "た"]);
            }

            GodanVerbU => {
                end_replace_push(word, "う", &["わ", "い", "え", "お", "って", "った"]);
            }

            GodanVerbTsu => {
                end_replace_push(word, "つ", &["た", "ち", "て", "と", "って", "った"]);
            }

            GodanVerbRu => {
                end_replace_push(word, "ち", &["ら", "り", "れ", "ろ", "って", "った"]);
            }

            GodanVerbKu => {
                end_replace_push(word, "く", &["か", "き", "け", "こ", "いて", "いた"]);
            }

            GodanVerbGu => {
                end_replace_push(word, "ぐ", &["が", "ぎ", "げ", "ご", "いで", "いだ"]);
            }

            GodanVerbNu => {
                end_replace_push(word, "ぬ", &["な", "に", "ね", "の", "んで", "んだ"]);
            }

            GodanVerbBu => {
                end_replace_push(word, "ぶ", &["ば", "び", "べ", "ぼ", "んで", "んだ"]);
            }

            GodanVerbMu => {
                end_replace_push(word, "む", &["ま", "み", "め", "も", "んで", "んだ"]);
            }

            GodanVerbSu => {
                end_replace_push(word, "す", &["さ", "し", "せ", "そ", "して", "した"]);
            }

            IkuVerb => {
                end_replace_push(word, "く", &["か", "き", "け", "こ", "って", "った"]);
            }

            KuruVerb => {
                end_replace_push(
                    word,
                    "くる",
                    &[
                        "こない",
                        "こなかった",
                        "こなくて",
                        "きて",
                        "きた",
                        "こられ",
                        "こさせ",
                        "こい",
                        "きます",
                        "きません",
                        "きました",
                    ],
                );
                end_replace_push(
                    word,
                    "来る",
                    &[
                        "来ない",
                        "来なかった",
                        "来なくて",
                        "来て",
                        "来た",
                        "来られ",
                        "来させ",
                        "来い",
                        "来ます",
                        "来ません",
                        "来ました",
                    ],
                );
            }

            SuruVerb => {
                end_replace_push(
                    word,
                    "する",
                    &[
                        "しな",
                        "しろ",
                        "させ",
                        "され",
                        "でき",
                        "した",
                        "して",
                        "します",
                        "しません",
                    ],
                );
            }

            IAdjective => {
                end_replace_push(word, "い", &["", "く", "け", "かった", "かって"]);
            }

            _ => {
                end_replace_push(word, "", &[]);
            }
        };
    }

    keys.sort_by_key(|a| (a.1, a.0.len(), a.0.clone()));
    keys.dedup();
    keys
}
/// Generates the look-up keys for a JMDict word entry, including
/// basic conjugations.
Generates the look-up keys for a JMDict word entry, including
basic conjugations.
Generates the look - up keys for a JMDict word entry including basic conjugations .
fn generate_lookup_keys(jm_entry: &WordEntry) -> Vec<(String, u32)> {
    let mut keys = Vec::new();
    let mut end_replace_push = |word: &str, trail: &str, endings: &[&str]| {
        // If a word is usually written in kana, give the kana form a major
        // priority boost.
        let priority = if is_all_kana(word) && jm_entry.usually_kana {
            jm_entry.priority / 8
        } else {
            jm_entry.priority
        };
        // We include the katakana version for all-hiragana
        // words as well because for some reason that's how Kobo
        // looks up hiragana words.  Leaving this out causes the Kobo
        // to completely fail to find entries for all-hirigana words.
        if is_all_kana(word) {
            keys.push((hiragana_to_katakana(word), priority));
        }
        keys.push((word.into(), priority));
        if trail.len() > 0 && word.len() >= trail.len() && word.ends_with(trail) {
            let stem = {
                let mut stem: String = word.into();
                stem.truncate(word.len() - trail.len());
                stem
            };
            for end in endings.iter() {
                let variant = format!("{}{}", stem, end);
                if is_all_kana(&variant) {
                    keys.push((hiragana_to_katakana(&variant), priority));
                }
                keys.push((variant, priority));
            }
        }
    };
    let mut forms: Vec<_> = jm_entry
        .writings
        .iter()
        .chain(if jm_entry.usually_kana {
            jm_entry.readings.iter()
        } else {
            (&jm_entry.readings[0..1]).iter()
        })
        .collect();
    forms.sort();
    forms.dedup();
    use ConjugationClass::*;
    for word in forms.iter() {
        match jm_entry.conj {
            IchidanVerb => {
                end_replace_push(word, "る", &["", "られ", "させ", "ろ", "て", "た"]);
            }
            GodanVerbU => {
                end_replace_push(word, "う", &["わ", "い", "え", "お", "って", "った"]);
            }
            GodanVerbTsu => {
                end_replace_push(word, "つ", &["た", "ち", "て", "と", "って", "った"]);
            }
            GodanVerbRu => {
                end_replace_push(word, "ち", &["ら", "り", "れ", "ろ", "って", "った"]);
            }
            GodanVerbKu => {
                end_replace_push(word, "く", &["か", "き", "け", "こ", "いて", "いた"]);
            }
            GodanVerbGu => {
                end_replace_push(word, "ぐ", &["が", "ぎ", "げ", "ご", "いで", "いだ"]);
            }
            GodanVerbNu => {
                end_replace_push(word, "ぬ", &["な", "に", "ね", "の", "んで", "んだ"]);
            }
            GodanVerbBu => {
                end_replace_push(word, "ぶ", &["ば", "び", "べ", "ぼ", "んで", "んだ"]);
            }
            GodanVerbMu => {
                end_replace_push(word, "む", &["ま", "み", "め", "も", "んで", "んだ"]);
            }
            GodanVerbSu => {
                end_replace_push(word, "す", &["さ", "し", "せ", "そ", "して", "した"]);
            }
            IkuVerb => {
                end_replace_push(word, "く", &["か", "き", "け", "こ", "って", "った"]);
            }
            KuruVerb => {
                end_replace_push(
                    word,
                    "くる",
                    &[
                        "こない",
                        "こなかった",
                        "こなくて",
                        "きて",
                        "きた",
                        "こられ",
                        "こさせ",
                        "こい",
                        "きます",
                        "きません",
                        "きました",
                    ],
                );
                end_replace_push(
                    word,
                    "来る",
                    &[
                        "来ない",
                        "来なかった",
                        "来なくて",
                        "来て",
                        "来た",
                        "来られ",
                        "来させ",
                        "来い",
                        "来ます",
                        "来ません",
                        "来ました",
                    ],
                );
            }
            SuruVerb => {
                end_replace_push(
                    word,
                    "する",
                    &[
                        "しな",
                        "しろ",
                        "させ",
                        "され",
                        "でき",
                        "した",
                        "して",
                        "します",
                        "しません",
                    ],
                );
            }
            IAdjective => {
                end_replace_push(word, "い", &["", "く", "け", "かった", "かって"]);
            }
            _ => {
                end_replace_push(word, "", &[]);
            }
        };
    }
    keys.sort_by_key(|a| (a.1, a.0.len(), a.0.clone()));
    keys.dedup();
    keys
}
fn generate_lookup_keys ( jm_entry : & WordEntry ) -> Vec < ( String , u32 ) > { let mut keys = Vec :: new ( ) ; let mut end_replace_push = | word : & str , trail : & str , endings : & [ & str ] | { // If a word is usually written in kana, give the kana form a major // priority boost. let priority = if is_all_kana ( word ) && jm_entry . usually_kana { jm_entry . priority / 8 } else { jm_entry . priority } ; // We include the katakana version for all-hiragana // words as well because for some reason that's how Kobo // looks up hiragana words.  Leaving this out causes the Kobo // to completely fail to find entries for all-hirigana words. if is_all_kana ( word ) { keys . push ( ( hiragana_to_katakana ( word ) , priority ) ) ; } keys . push ( ( word . into ( ) , priority ) ) ; if trail . len ( ) > 0 && word . len ( ) >= trail . len ( ) && word . ends_with ( trail ) { let stem = { let mut stem : String = word . into ( ) ; stem . truncate ( word . len ( ) - trail . len ( ) ) ; stem } ; for end in endings . iter ( ) { let variant = format ! ( " " stem end ) ; if is_all_kana ( & variant ) { keys . push ( ( hiragana_to_katakana ( & variant ) , priority ) ) ; } keys . push ( ( variant , priority ) ) ; } } } ; let mut forms : Vec < _ > = jm_entry . writings . iter ( ) . chain ( if jm_entry . usually_kana { jm_entry . readings . iter ( ) } else { ( & jm_entry . readings [ 0 .. 1 ] ) . iter ( ) } ) . collect ( ) ; forms . sort ( ) ; forms . dedup ( ) ; use ConjugationClass :: * ; for word in forms . iter ( ) { match jm_entry . conj { IchidanVerb => { end_replace_push ( word , " & " " , " れ " , " " , " ) ; } GodanVerbU => { end_replace_push ( word , " & " わ " い " , お " っ " っ た ] } GodanVerbTsu => { end_replace_push ( word , " & " た " ち " , と " っ " っ た ] } GodanVerbRu => { end_replace_push ( word , " & " ら " り " , ろ " っ " っ た ] } GodanVerbKu => { end_replace_push ( word , " & " か " き " , こ " い " い た ] } GodanVerbGu => { end_replace_push ( word , " & " が " ぎ " , ご " い " い だ ] } GodanVerbNu => { end_replace_push ( word , " & " な " に " , の " ん " ん だ ] } GodanVerbBu => { end_replace_push ( word , " & " ば " び " , ぼ " ん " ん だ ] } GodanVerbMu => { end_replace_push ( word , " & " ま " み " , も " ん " ん だ ] } GodanVerbSu => { end_replace_push ( word , " & " さ " し " , そ " し " し た ] } IkuVerb => { end_replace_push ( word , " & " か " き " , こ " っ " っ た ] } KuruVerb => { end_replace_push ( word , " & [ " " " " " " " " " " " ] , ) ; end_replace_push ( word , " & [ " " " " " " " " " " " ] , ) ; } SuruVerb => { end_replace_push ( word , " & [ " " " " " " " " " ] , ) ; } IAdjective => { end_replace_push ( word , " & " " , " " け " た " } _ => { end_replace_push ( word , " " , & [ ] ) ; } } ; } keys . sort_by_key ( | a | ( a . 1 , a . 0 . len ( ) , a . 0 . clone ( ) ) ) ; keys . dedup ( ) ; keys }
Generates the look-up keys for a JMDict word entry, including
basic conjugations.
Generates the look - up keys for a JMDict word entry including basic conjugations .
jm_entry
&WordEntry
jm_entry
&WordEntry