Skip to content

Commit

Permalink
Print lemma numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Sep 8, 2024
1 parent 7bb4363 commit bce9fe2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/proficiency/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import sqlite3
from pathlib import Path

Expand Down Expand Up @@ -53,11 +54,14 @@ def init_db(
return conn


def create_indexes_then_close(conn: sqlite3.Connection) -> None:
def create_indexes_then_close(conn: sqlite3.Connection, lemma_lang: str) -> None:
create_indexes_sql = """
CREATE INDEX idx_lemmas ON lemmas (lemma);
CREATE INDEX idx_senses ON senses (lemma_id, pos);
"""
conn.executescript(create_indexes_sql)
if lemma_lang != "":
for (lemma_num,) in conn.execute("SELECT count(*) FROM lemmas"):
logging.info(f"{lemma_lang}: {lemma_num}")
conn.commit()
conn.close()
2 changes: 1 addition & 1 deletion src/proficiency/extract_dbnary.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def create_lemmas_db_from_dbnary(
if has_morphology and lemma_lang == gloss_lang:
insert_forms(store, conn, lemma_lang, lemma_ids)
insert_senses(store, conn, lemma_lang, gloss_lang, lemma_ids)
create_indexes_then_close(conn)
create_indexes_then_close(conn, lemma_lang)
return [db_path]


Expand Down
4 changes: 2 additions & 2 deletions src/proficiency/extract_kaikki.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def create_lemmas_db_from_kaikki(lemma_lang: str, gloss_lang: str) -> list[Path]
]
insert_senses(zh_cn_conn, zh_cn_senses, lemma_id, pos, difficulty)

create_indexes_then_close(conn)
create_indexes_then_close(conn, lemma_lang)
if gloss_lang == "zh":
create_indexes_then_close(zh_cn_conn)
create_indexes_then_close(zh_cn_conn, "")
kaikki_json_path.unlink()
return [db_path, zh_cn_db_path] if gloss_lang == "zh" else [db_path]

Expand Down
2 changes: 1 addition & 1 deletion src/proficiency/extract_kindle_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_kindle_lemmas_db(db_path: Path) -> None:
en_data = (sense_id, enabled, pos_type, difficulty)
insert_en_data(conn, lemma, en_data, lemminflect_pos, lemma_ids)

create_indexes_then_close(conn)
create_indexes_then_close(conn, "")


def insert_lemma(
Expand Down

0 comments on commit bce9fe2

Please sign in to comment.