forked from kristjan/cjvt-valency
working on api changes
This commit is contained in:
@@ -6,6 +6,8 @@ def frames_from_db_entry(dbent):
|
||||
def _full_tid(tid):
|
||||
return ".".join([dbent["sid"], str(tid)])
|
||||
|
||||
token_dict = {str(x["tid"]): x for x in dbent["tokens"]}
|
||||
|
||||
frames = []
|
||||
if "srl_links" not in dbent:
|
||||
return []
|
||||
@@ -18,19 +20,20 @@ def frames_from_db_entry(dbent):
|
||||
srldict[key] += [srl]
|
||||
for hwtid, srlarr in srldict.items():
|
||||
frames += [Frame(
|
||||
hw_lemma=_full_tid(hwtid),
|
||||
tids=[_full_tid(x["to"]) for x in srlarr],
|
||||
hw_lemma=token_dict[hwtid]["text"],
|
||||
tids=[_full_tid(hwtid)],
|
||||
slots=[
|
||||
Slot(
|
||||
functor=srl["afun"],
|
||||
tids=[_full_tid(srl["to"])]
|
||||
) for srl in srlarr
|
||||
]
|
||||
],
|
||||
sentences=[dbent["tokens"]],
|
||||
)]
|
||||
return frames
|
||||
|
||||
class Frame():
|
||||
def __init__(self, tids, deep_links=None, slots=None, hw_lemma=None):
|
||||
def __init__(self, tids, deep_links=None, slots=None, hw_lemma=None, sentences=None):
|
||||
self.hw = hw_lemma
|
||||
self.tids = tids # list of tokens with the same hw_lemma
|
||||
# Each tid = "S123.t123";
|
||||
@@ -41,7 +44,7 @@ class Frame():
|
||||
else:
|
||||
self.slots = slots
|
||||
self.sense_info = {}
|
||||
self.sentences = None # Used for passing to view in app.py, get_frames
|
||||
self.sentences = sentences
|
||||
self.aggr_sent = None # Dictionary { hw: self.sentences idx }
|
||||
|
||||
def to_json(self):
|
||||
|
||||
@@ -56,11 +56,13 @@ def reduce_1(frames, vallex=None):
|
||||
break
|
||||
else:
|
||||
# Python for else -> fires if loop has ended.
|
||||
# init new frame set [set_of_functors, list_of_one_frame]
|
||||
frame_sets.append([functors, [frame]])
|
||||
|
||||
ret_frames = []
|
||||
for fs in frame_sets:
|
||||
tids = []
|
||||
sentences = []
|
||||
slots = {}
|
||||
# All possible slots in this frame.
|
||||
for functor in fs[0]:
|
||||
@@ -68,12 +70,13 @@ def reduce_1(frames, vallex=None):
|
||||
# Reduce slots from all frames. (Merge ACT from all frames, ...)
|
||||
for frame in fs[1]:
|
||||
tids += frame.tids
|
||||
sentences += frame.sentences
|
||||
for sl in frame.slots:
|
||||
slots[sl.functor].tids += sl.tids
|
||||
slots_list = []
|
||||
for k, e in slots.items():
|
||||
slots_list.append(e)
|
||||
rf = Frame(tids=tids, slots=slots_list)
|
||||
rf = Frame(tids=tids, slots=slots_list, sentences=sentences)
|
||||
rf.sort_slots()
|
||||
ret_frames.append(rf)
|
||||
return sorted_by_len_tids(ret_frames)
|
||||
|
||||
Reference in New Issue
Block a user