sql-join-test #1
20
src/match.py
20
src/match.py
|
@ -11,16 +11,22 @@ class StructureMatch:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_db(db, colocation_id, structure):
|
def from_db(db, colocation_id, structure):
|
||||||
result = StructureMatch(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,)):
|
prev_match_id = None
|
||||||
to_add = {}
|
|
||||||
|
|
||||||
for component_id, word_lemma, word_text, word_msd, word_id in db.execute("""
|
stmt = """SELECT match_id, component_id, word_lemma, word_text, word_msd, word_id
|
||||||
SELECT component_id, word_lemma, word_text, word_msd, word_id
|
FROM ColocationMatches
|
||||||
FROM Matches WHERE match_id=?""", match_id):
|
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,)):
|
for component_id, text in db.execute("SELECT component_id, text FROM Representations WHERE colocation_id=?", (colocation_id,)):
|
||||||
result.representations[str(component_id)] = text
|
result.representations[str(component_id)] = text
|
||||||
|
|
Loading…
Reference in New Issue
Block a user