frames and slots from db
This commit is contained in:
parent
1f83f96267
commit
ca942344d7
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ data/samples/
|
|||
src/frontend_vue/node_modules/
|
||||
src/frontend_vue/dist/
|
||||
dockerfiles/database/create.js
|
||||
*__pycache__/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Flask, render_template, request, url_for, redirect
|
||||
from valency import Frame, Slot
|
||||
from valency.Frame import Frame, Slot, frames_from_db_entry
|
||||
from valency.reduce_functions import reduce_functions
|
||||
|
||||
"""
|
||||
|
@ -39,6 +39,7 @@ CORPORA = ["ssj", "kres"]
|
|||
app_index = {c: {} for c in CORPORA}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
valdb = None
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
|
@ -50,6 +51,18 @@ app = Flask(__name__)
|
|||
CORS(app)
|
||||
|
||||
|
||||
# DEV -------------------------------.
|
||||
|
||||
@app.route("/api/dev")
|
||||
def api_dev():
|
||||
cur = valdb.kres.find({"sid": "F0015940.37.2"})
|
||||
frames = []
|
||||
for ent in cur:
|
||||
frames += frames_from_db_entry(ent)
|
||||
return json.dumps([x.to_json() for x in frames])
|
||||
|
||||
# DEV -------------------------------^
|
||||
|
||||
# INDEX SELECTION -------------------.
|
||||
|
||||
@app.route("/api/words/<corpus>")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user