| |
|
|
| |
|
|
| |
| |
| from tasks.longwiki.retrieval import DocDB |
| import sqlite3 |
| import argparse |
|
|
| def get_titles_all(db): |
| |
| cursor = db.connection.cursor() |
| cursor.execute("SELECT title FROM documents") |
| results = cursor.fetchall() |
| results_title = [r[0] for r in results] |
| cursor.close() |
| return results_title |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--wiki_db_path", type=str, default="data/wiki_data/.cache/enwiki-20230401.db") |
| args = parser.parse_args() |
|
|
| db_path=args.wiki_db_path |
| db_title_path=db_path.replace(".db", "-title.db") |
| db = DocDB(db_path=db_path) |
|
|
| |
| titles = get_titles_all(db) |
|
|
| |
| conn = sqlite3.connect(db_title_path) |
| cursor_ = conn.cursor() |
|
|
| |
| cursor_.execute(''' |
| CREATE TABLE IF NOT EXISTS titles ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| title_name TEXT NOT NULL |
| ); |
| ''') |
|
|
| |
| cursor_.executemany(''' |
| INSERT INTO titles (title_name) VALUES (?) |
| ''', [(title,) for title in titles]) |
|
|
| |
| conn.commit() |
|
|
| |
| cursor_.execute("SELECT * FROM titles") |
| i = 0 |
| for row in cursor_.fetchall(): |
| print(row) |
| i +=1 |
| if i > 10: |
| break |
|
|
| |
| conn.close() |