Skip to content
Snippets Groups Projects
Commit acac8b83 authored by Lukáš Paukert's avatar Lukáš Paukert
Browse files
parents 4059a7ce 86319d7e
No related branches found
No related tags found
Loading
CREATE TABLE Document
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT NOT NULL
filename TEXT NOT NULL UNIQUE
);
 
CREATE TABLE Term
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
value TEXT NOT NULL
value TEXT NOT NULL UNIQUE
);
 
CREATE TABLE TermDocumentOccurrence
......@@ -19,5 +19,3 @@ CREATE TABLE TermDocumentOccurrence
FOREIGN KEY (Document_id) REFERENCES Document (id),
FOREIGN KEY (Term_id) REFERENCES Term (id)
);
......@@ -137,7 +137,10 @@ class Preprocessor:
document_key = database.last_primary_key()
for term in self.terms:
database.execute('''INSERT OR IGNORE INTO Term(value) VALUES (?)''', [term])
term_key = database.last_primary_key()
database.execute('''SELECT id FROM Term WHERE value = ?''', [term])
term_key = database.fetchone()[0]
if term_key is None:
term_key = database.last_primary_key()
database.execute('''INSERT INTO TermDocumentOccurrence(Term_id, Document_id, count) VALUES (?,?,?)''',
[term_key, document_key, self.terms[term]])
database.commit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment