pub fn generate_entries(&mut self, lang: &Language, entries: &WiktionaryEntries) {
        let mut conn = self.connect();
        let transaction = conn.transaction().unwrap();

        let mut statement = transaction.prepare(&format!(
            "SELECT {0}_words.content
            FROM {0}_words
            JOIN {0}_types
            ON {0}_types.id = {0}_words.type_id
            WHERE {0}_words.word = ?
            AND {0}_types.name = ?", &lang.code)
        ).unwrap();

        for entry in entries.iter() {
            if let Some(forms) = entry.parse_json()["forms"].as_array() {
                let mut forms_vec: Vec<Form> = Vec::new();

                for form in forms {
                    let form: Form = serde_json::from_value(form.clone()).unwrap();
                    forms_vec.push(form);
                }

                forms_vec = forms_vec.into_iter()
                                     .filter(|x|
                                         match &x.source {
                                             Some(src) => src == "Declension" || src == "Conjugation",
                                             None => false
                                         }
                                     ).collect();

                forms_vec.sort_by_key(|x| x.form.clone());

                let forms_group = forms_vec.group_by(|a, b| a.form == b.form);

                for forms in forms_group.into_iter() {
                    let mut entries = statement.query([&forms[0].form, &entry.type_]).unwrap();

                    if let None = entries.next().unwrap() {
                        let mut senses: Vec<Value> = Vec::new();

                        for form in forms {
                            let mut tags = match &form.tags {
                                Some(tags) => tags.clone(),
                                None => Vec::new()
                            };
                            tags.push(String::from("form-of"));
                            tags.push(String::from("auto-generated"));

                            senses.push(json!({
                                "form_of": [
                                    {
                                        "word": entry.word
                                    }
                                ],
                                "glosses": [
                                    match &form.tags {
                                        Some(tags) => tags.join(" "),
                                        None => String::from("")
                                    }
                                ],
                                "tags": tags
                            }));
                        }

                        let entry_json = json!({
                            "pos": entry.type_.clone(),
                            "word": forms[0].form.clone(),
                            "senses": senses
                        });

                        let new_entry = WiktionaryEntry::new(forms[0].form.clone(),
                                                             entry.type_.clone(),
                                                             entry_json.to_string());

                        self.insert_entry(&transaction, lang, &new_entry);
                    }
                }
            }
        }

        drop(statement);
        transaction.commit().unwrap();
    }
/// Generate missing "form-of" entries
Generate missing "form-of" entries
Generate missing " form - of " entries
pub fn generate_entries(&mut self, lang: &Language, entries: &WiktionaryEntries) {
        let mut conn = self.connect();
        let transaction = conn.transaction().unwrap();
        let mut statement = transaction.prepare(&format!(
            "SELECT {0}_words.content
            FROM {0}_words
            JOIN {0}_types
            ON {0}_types.id = {0}_words.type_id
            WHERE {0}_words.word = ?
            AND {0}_types.name = ?", &lang.code)
        ).unwrap();
        for entry in entries.iter() {
            if let Some(forms) = entry.parse_json()["forms"].as_array() {
                let mut forms_vec: Vec<Form> = Vec::new();
                for form in forms {
                    let form: Form = serde_json::from_value(form.clone()).unwrap();
                    forms_vec.push(form);
                }
                forms_vec = forms_vec.into_iter()
                                     .filter(|x|
                                         match &x.source {
                                             Some(src) => src == "Declension" || src == "Conjugation",
                                             None => false
                                         }
                                     ).collect();
                forms_vec.sort_by_key(|x| x.form.clone());
                let forms_group = forms_vec.group_by(|a, b| a.form == b.form);
                for forms in forms_group.into_iter() {
                    let mut entries = statement.query([&forms[0].form, &entry.type_]).unwrap();
                    if let None = entries.next().unwrap() {
                        let mut senses: Vec<Value> = Vec::new();
                        for form in forms {
                            let mut tags = match &form.tags {
                                Some(tags) => tags.clone(),
                                None => Vec::new()
                            };
                            tags.push(String::from("form-of"));
                            tags.push(String::from("auto-generated"));
                            senses.push(json!({
                                "form_of": [
                                    {
                                        "word": entry.word
                                    }
                                ],
                                "glosses": [
                                    match &form.tags {
                                        Some(tags) => tags.join(" "),
                                        None => String::from("")
                                    }
                                ],
                                "tags": tags
                            }));
                        }
                        let entry_json = json!({
                            "pos": entry.type_.clone(),
                            "word": forms[0].form.clone(),
                            "senses": senses
                        });
                        let new_entry = WiktionaryEntry::new(forms[0].form.clone(),
                                                             entry.type_.clone(),
                                                             entry_json.to_string());
                        self.insert_entry(&transaction, lang, &new_entry);
                    }
                }
            }
        }
        drop(statement);
        transaction.commit().unwrap();
    }
pub fn generate_entries ( & mut self , lang : & Language , entries : & WiktionaryEntries ) { let mut conn = self . connect ( ) ; let transaction = conn . transaction ( ) . unwrap ( ) ; let mut statement = transaction . prepare ( & format ! ( " " lang code ) ) . unwrap ( ) ; for entry in entries . iter ( ) { if let Some ( forms ) = entry . parse_json ( ) [ " " ] . as_array ( ) { let mut forms_vec : Vec < Form > = Vec :: new ( ) ; for form in forms { let form : Form = serde_json :: from_value ( form . clone ( ) ) . unwrap ( ) ; forms_vec . push ( form ) ; } forms_vec = forms_vec . into_iter ( ) . filter ( | x | match & x . source { Some ( src ) => src == " " || src == " " , None => false } ) . collect ( ) ; forms_vec . sort_by_key ( | x | x . form . clone ( ) ) ; let forms_group = forms_vec . group_by ( | a , b | a . form == b . form ) ; for forms in forms_group . into_iter ( ) { let mut entries = statement . query ( [ & forms [ 0 ] . form , & entry . type_ ] ) . unwrap ( ) ; if let None = entries . next ( ) . unwrap ( ) { let mut senses : Vec < Value > = Vec :: new ( ) ; for form in forms { let mut tags = match & form . tags { Some ( tags ) => tags . clone ( ) , None => Vec :: new ( ) } ; tags . push ( String :: from ( " " ) ) ; tags . push ( String :: from ( " " ) ) ; senses . push ( json ! ( { " " [ { " " entry word } ] " " [ match form tags { Some ( tags ) tags join ( " " ) None String from ( " " ) } ] " " tags } ) ) ; } let entry_json = json ! ( { " " entry type_ clone ( ) " " forms [ 0 ] form clone ( ) " " senses } ) ; let new_entry = WiktionaryEntry :: new ( forms [ 0 ] . form . clone ( ) , entry . type_ . clone ( ) , entry_json . to_string ( ) ) ; self . insert_entry ( & transaction , lang , & new_entry ) ; } } } } drop ( statement ) ; transaction . commit ( ) . unwrap ( ) ; }
Generate missing "form-of" entries
Generate missing " form - of " entries
&mut self
lang
&Language
entries
&WiktionaryEntries
&mut self
lang
&Language
entries
&WiktionaryEntries