|
|
|
@ -37,7 +37,7 @@ SENSEMAP_COLL = "sensemap"
|
|
|
|
|
|
|
|
|
|
# pre-generated data (gui leftside word index)
|
|
|
|
|
CORPORA = ["ssj", "kres"]
|
|
|
|
|
app_index = {c: {} for c in CORPORA}
|
|
|
|
|
app_index = None
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
valdb = None
|
|
|
|
@ -239,7 +239,6 @@ def prepare_frames(ret_frames):
|
|
|
|
|
# append sentences
|
|
|
|
|
for frame in ret_frames:
|
|
|
|
|
unique_sids = {".".join(x.split(".")[:-1]): x for x in frame.tids}
|
|
|
|
|
log.debug(str(unique_sids))
|
|
|
|
|
# frame.sentences = []
|
|
|
|
|
frame.aggr_sent = {}
|
|
|
|
|
# sid, tid==hw
|
|
|
|
@ -268,8 +267,13 @@ def api_get_frames():
|
|
|
|
|
rf_name = request.args.get("rf", "reduce_0") # 2nd is default
|
|
|
|
|
RF = reduce_functions[rf_name]["f"]
|
|
|
|
|
|
|
|
|
|
corpus = request.args.get("cor")
|
|
|
|
|
if corpus not in CORPORA:
|
|
|
|
|
return json.dumps({"error": "cor={kres,ssj}"})
|
|
|
|
|
|
|
|
|
|
# entry = vallex.entries[hw] # TODO hw -> [Frame,]
|
|
|
|
|
cur = valdb.kres.find({"headwords": hw})
|
|
|
|
|
cur = valdb[corpus].find({"headwords": hw})
|
|
|
|
|
print("N_results: " + str(cur.count()))
|
|
|
|
|
frames = []
|
|
|
|
|
for ent in cur:
|
|
|
|
|
# TODO: maybe filter by hw?
|
|
|
|
@ -277,11 +281,7 @@ def api_get_frames():
|
|
|
|
|
|
|
|
|
|
# return json.dumps([x.to_json() for x in frames])
|
|
|
|
|
|
|
|
|
|
print("A")
|
|
|
|
|
print(frames[0].to_json())
|
|
|
|
|
ret_frames = RF(frames, None)
|
|
|
|
|
print("B")
|
|
|
|
|
print(ret_frames[0].to_json())
|
|
|
|
|
return prepare_frames(ret_frames)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -438,6 +438,7 @@ def prepare_db():
|
|
|
|
|
valdb[corpus].ensure_index([("functors", pymongo.ASCENDING)])
|
|
|
|
|
|
|
|
|
|
# create app_index (used in frontend, left side word index)
|
|
|
|
|
tmp_app_index = {c: {} for c in CORPORA}
|
|
|
|
|
for corpus in CORPORA:
|
|
|
|
|
res_hws = {}
|
|
|
|
|
res_fns = {}
|
|
|
|
@ -467,11 +468,13 @@ def prepare_db():
|
|
|
|
|
|
|
|
|
|
for k, e in alphabetical.items():
|
|
|
|
|
alphabetical[k] = sorted(e, key=lambda x: x[0])
|
|
|
|
|
app_index[corpus]["words"] = alphabetical
|
|
|
|
|
tmp_app_index[corpus]["words"] = alphabetical
|
|
|
|
|
|
|
|
|
|
functors = [(k, e) for (k, e) in res_fns.items()]
|
|
|
|
|
functors = sorted(functors, key=lambda x: x[0])
|
|
|
|
|
app_index[corpus]["functors"] = functors
|
|
|
|
|
tmp_app_index[corpus]["functors"] = functors
|
|
|
|
|
|
|
|
|
|
valdb.appindex.update({"dockey": "appindex"}, {"dockey": "appindex", "data": tmp_app_index}, upsert=True)
|
|
|
|
|
|
|
|
|
|
# APP PREFLIGHT ---------------------^
|
|
|
|
|
|
|
|
|
@ -506,9 +509,12 @@ if __name__ == "__main__":
|
|
|
|
|
)
|
|
|
|
|
valdb = client.valdb
|
|
|
|
|
|
|
|
|
|
if config["prepare_db"]:
|
|
|
|
|
if bool(config["prepare_db"]):
|
|
|
|
|
prepare_db()
|
|
|
|
|
|
|
|
|
|
# app index from db
|
|
|
|
|
app_index = (valdb.appindex.find_one({"dockey": "appindex"}))["data"]
|
|
|
|
|
|
|
|
|
|
# log.info("[*] Starting app.py with config:\n%s".format(config))
|
|
|
|
|
log.info("[*] Starting app.py with config:\n{}".format(config))
|
|
|
|
|
|
|
|
|
|