forked from kristjan/cjvt-valency
frames and slots from db
This commit is contained in:
@@ -2,10 +2,36 @@ import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def frames_from_db_entry(dbent):
|
||||
def _full_tid(tid):
|
||||
return ".".join([dbent["sid"], str(tid)])
|
||||
|
||||
frames = []
|
||||
if "srl_links" not in dbent:
|
||||
return []
|
||||
srldict = {}
|
||||
for srl in dbent["srl_links"]:
|
||||
key = str(srl["from"])
|
||||
if key not in srldict:
|
||||
srldict[key] = [srl]
|
||||
else:
|
||||
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],
|
||||
slots=[
|
||||
Slot(
|
||||
functor=srl["afun"],
|
||||
tids=[_full_tid(srl["to"])]
|
||||
) for srl in srlarr
|
||||
]
|
||||
)]
|
||||
return frames
|
||||
|
||||
class Frame():
|
||||
def __init__(self, tids, deep_links=None, slots=None, hw=None):
|
||||
self.hw = hw
|
||||
def __init__(self, tids, deep_links=None, slots=None, hw_lemma=None):
|
||||
self.hw = hw_lemma
|
||||
self.tids = tids # list of tokens with the same hw_lemma
|
||||
# Each tid = "S123.t123";
|
||||
# you can get sentence with vallex.get_sentence(S123)
|
||||
@@ -33,7 +59,7 @@ class Frame():
|
||||
slots = []
|
||||
for link in deep:
|
||||
slots.append(Slot(
|
||||
functor=link["functor"],
|
||||
functor=link["afun"],
|
||||
tids=[link["to"]]
|
||||
))
|
||||
return slots
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from valency.Frame import Frame, Slot
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Input: list of Frame objects, output: list of Frame objects.
|
||||
# App uses reduce_0, 1 and 5
|
||||
|
||||
from valency import Frame, Slot
|
||||
from valency.Frame import Frame, Slot
|
||||
from copy import deepcopy as DC
|
||||
import logging
|
||||
|
||||
|
||||
Reference in New Issue
Block a user