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(chinese_sentences, nonchinese_sentences, links, db_name): print("Writing to database file") 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, ) # Add sentences to tables for key in chinese_sentences: sentence = chinese_sentences[key] database.insert_chinese_sentence( c, sentence.traditional, sentence.simplified, sentence.pinyin, sentence.jyutping, sentence.language, sentence.id, ) for key in nonchinese_sentences: sentence = nonchinese_sentences[key] database.insert_nonchinese_sentence( c, sentence.sentence, sentence.language, sentence.id, ) # Add links for source_sentence_id in links: for target_sentence_id in links[source_sentence_id]: direct = links[source_sentence_id][target_sentence_id] database.insert_sentence_link( c, source_sentence_id, target_sentence_id, 1, direct, ) 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()
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()