def write(db_name, source, entries): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) insert_words(c, entries) database.generate_indices(c) db.commit() db.close()
def write(db_name, source, words): db = sqlite3.connect(db_name) c = db.cursor() database.write_database_version(c) database.drop_tables(c) database.create_tables(c) database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) insert_words(c, words) database.generate_indices(c) db.commit() db.close()
def write(db_name, source, entries): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) for key in entries: for entry in entries[key]: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: logging.error( f"Could not insert word {entry.traditional}, uh oh!") continue for label, definition in entry.definitions: definition_id = database.insert_definition( c, definition, label, entry_id, 1, None) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional} " "- check if the definition is a duplicate!") continue database.generate_indices(c) db.commit() db.close()
def write(db_name, source, entries, sentences, translations): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) for entry in entries: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: logging.error(f"Could not insert word {entry.traditional}, uh oh!") continue for label, definition in entry.definitions: definition_id = database.insert_definition( c, definition, label, entry_id, 1, None ) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional}, uh oh!" ) continue for sentence in sentences: database.insert_chinese_sentence( c, sentence.traditional, sentence.simplified, sentence.pinyin, sentence.jyutping, sentence.language, sentence.id, ) # In CantoDict, a sentence ID and its corresponding translation ID are separated by 500000000 # (See parse_sentence_file()) database.insert_sentence_link( c, sentence.id, sentence.id + 500000000, 1, True, ) for translation in translations: database.insert_nonchinese_sentence( c, translation.sentence, translation.language, translation.id, ) database.generate_indices(c) db.commit() db.close()
WHERE definitions.fk_entry_id = entries.entry_id AND definitions.fk_source_id = sources.source_id ) INSERT INTO definitions_chinese_sentences_links(fk_definition_id, fk_chinese_sentence_id) SELECT ned.definition_id, cs.chinese_sentence_id FROM defs_s_links_tmp AS dsl, new_entry_and_definitions AS ned, chinese_sentences AS cs WHERE dsl.sentence_traditional = cs.traditional AND dsl.sentence_simplified = cs.simplified AND dsl.sentence_pinyin = cs.pinyin AND dsl.sentence_jyutping = cs.jyutping AND dsl.sentence_language = cs.language AND dsl.definition = ned.definition AND dsl.label = ned.label AND dsl.traditional = ned.traditional AND dsl.simplified = ned.simplified AND dsl.pinyin = ned.pinyin AND dsl.jyutping = ned.jyutping AND dsl.source = ned.source """ ) # Populate FTS versions of tables database.generate_indices(c) db.commit() db.close()
def write(entries, db_name): db = sqlite3.connect(db_name) c = db.cursor() database.write_database_version(c) database.drop_tables(c) database.create_tables(c) database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) entry_id = 0 for key in entries: for entry in entries[key]: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping if entry.jyutping != "" else entry.fuzzy_jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping if entry.jyutping != "" else entry.fuzzy_jyutping, entry.freq, ) if entry_id == -1: logging.error( f"Could not insert word {entry.traditional}, uh oh!") continue for definition in entry.definitions: definition_id = database.insert_definition( c, definition, "", entry_id, 1, None) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional}, uh oh!" ) continue database.generate_indices(c) db.commit() db.close()