2019-06-27 14:51:58 +00:00
|
|
|
from word import Word
|
|
|
|
|
2019-06-15 16:55:35 +00:00
|
|
|
class StructureMatch:
|
|
|
|
def __init__(self, match_id, structure):
|
2019-06-27 20:04:33 +00:00
|
|
|
self.match_id = str(match_id)
|
2019-06-15 16:55:35 +00:00
|
|
|
self.structure = structure
|
|
|
|
|
|
|
|
self.matches = []
|
|
|
|
self.representations = {}
|
2019-06-27 14:51:58 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_db(db, colocation_id, structure):
|
2019-06-27 20:04:33 +00:00
|
|
|
result = StructureMatch(colocation_id, structure)
|
2019-06-27 14:51:58 +00:00
|
|
|
for match_id in db.execute("SELECT mid_match_id FROM ColocationMatches WHERE mid_colocation_id=?", (colocation_id,)):
|
|
|
|
to_add = {}
|
|
|
|
|
|
|
|
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):
|
|
|
|
|
|
|
|
to_add[str(component_id)] = Word(word_lemma, word_msd, word_id, word_text, False)
|
|
|
|
|
|
|
|
result.matches.append(to_add)
|
|
|
|
|
|
|
|
for component_id, text in db.execute("SELECT component_id, text FROM Representations WHERE colocation_id=?", (colocation_id,)):
|
|
|
|
result.representations[str(component_id)] = text
|
|
|
|
|
|
|
|
return result
|
2019-06-15 16:55:35 +00:00
|
|
|
|
|
|
|
def distinct_forms(self):
|
|
|
|
dm = set()
|
|
|
|
keys = list(self.matches[0].keys())
|
|
|
|
for words in self.matches:
|
|
|
|
dm.add(" ".join(words[k].text for k in keys))
|
|
|
|
return len(dm)
|
|
|
|
|
|
|
|
def append(self, match):
|
|
|
|
self.matches.append(match)
|
|
|
|
|
|
|
|
def __len__(self):
|
2019-06-27 14:51:58 +00:00
|
|
|
return len(self.matches)
|