Attempt at speed optimization with sql-join

pull/1/head
Ozbolt Menegatti 5 years ago
parent 4124036474
commit 6bb3586051

@ -11,16 +11,22 @@ class StructureMatch:
@staticmethod
def from_db(db, colocation_id, structure):
result = StructureMatch(colocation_id, structure)
for match_id in db.execute("SELECT mid_match_id FROM ColocationMatches WHERE mid_colocation_id=?", (colocation_id,)):
to_add = {}
prev_match_id = None
for component_id, word_lemma, word_text, word_msd, word_id in db.execute("""
SELECT component_id, word_lemma, word_text, word_msd, word_id
FROM Matches WHERE match_id=?""", match_id):
stmt = """SELECT match_id, component_id, word_lemma, word_text, word_msd, word_id
FROM ColocationMatches
JOIN Matches ON Matches.match_id=ColocationMatches.mid_match_id
WHERE mid_colocation_id=?
ORDER BY match_id"""
to_add[str(component_id)] = Word(word_lemma, word_msd, word_id, word_text, False)
for row in db.execute(stmt, (colocation_id,)):
match_id, component_id, word_lemma, word_text, word_msd, word_id = row
result.matches.append(to_add)
if match_id != prev_match_id:
result.matches.append({})
prev_match_id = match_id
result.matches[-1][str(component_id)] = Word(word_lemma, word_msd, word_id, word_text, False)
for component_id, text in db.execute("SELECT component_id, text FROM Representations WHERE colocation_id=?", (colocation_id,)):
result.representations[str(component_id)] = text

Loading…
Cancel
Save