Skip to content

Commit

Permalink
Implemented sqlite database.
Browse files Browse the repository at this point in the history
  • Loading branch information
SekouDiaoNlp committed Aug 24, 2023
1 parent 1895f3f commit 432d4ad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pylexique/pylexique.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _initialize_database(self) -> None:
cursor = self._conn.cursor()
cursor.execute('''
CREATE TABLE lexicon (
ortho TEXT PRIMARY KEY,
ortho TEXT,
phon TEXT,
lemme TEXT,
cgram TEXT,
Expand Down Expand Up @@ -196,13 +196,16 @@ def _initialize_database(self) -> None:
nbmorph INTEGER
)
''')
cursor.execute('''
CREATE INDEX idx_ortho ON lexicon (ortho)
''')
cursor.close()

def _insert_entry(self, row_fields: ConvertedRow) -> None:
"""Insert a row into the lexicon table."""
cursor = self._conn.cursor()
cursor.execute('''
INSERT INTO lexicon VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO lexicon VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', row_fields)
cursor.close()

Expand Down Expand Up @@ -230,7 +233,7 @@ def save_cache(self) -> None:
disk_conn = sqlite3.connect(self._cache_path)
cursor = disk_conn.cursor()
cursor.execute("ATTACH DATABASE ':memory:' AS inmemory")
cursor.execute("CREATE TABLE inmemory.lexicon AS SELECT * FROM main.lexicon")
cursor.execute("CREATE TABLE inmemory.lexicon AS SELECT * FROM lexicon")
cursor.execute("DETACH DATABASE inmemory")
disk_conn.commit()
cursor.close()
Expand Down

0 comments on commit 432d4ad

Please sign in to comment.