Skip to content

Commit

Permalink
Merge branch 'master' into release-0.18.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tomachalek committed Sep 20, 2024
2 parents 424543c + a8cce40 commit d062d3a
Show file tree
Hide file tree
Showing 40 changed files with 621 additions and 1,313 deletions.
9 changes: 8 additions & 1 deletion lib/action/model/concordance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,22 @@ def nicearg(arg, oid):
niceargs = []
prev_val = ''
prev_other = ''
exclude = False
for i, arg_i in enumerate(args):
if i % 2:
tmparg = arg_i.strip('\\').replace('(?i)', '')
if tmparg != prev_val or '|' not in prev_other:
niceargs.append(tmparg)
if exclude:
exclude = False
niceargs.append(f'!{tmparg}')
else:
niceargs.append(tmparg)
prev_val = tmparg
else:
if arg_i.startswith('within'):
niceargs.append('within')
if '!=' in arg_i:
exclude = True
prev_other = arg_i
return ', '.join(niceargs)
# o, a, u1, u2, s, opid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import aiofiles
import ujson as json
from openpyxl import Workbook
from plugins.masm_live_attributes.doclist import DocListItem
from ..doclist import DocListItem
from templating import Type2XML


Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/default_syntax_viewer/manatee_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, idx: int, data: Dict[str, Any], node_labels: List[str], word:
idx: node order in the list (zero based)
data: a dict containing detailed information about the node
node_labels: a list of labels for the nodes
word (str): a "word" value of the node (i.e. the actual word the node represents)
word (str): a "word" value of the node (i.e. the actual word dthe node represents)
sentence_word: a word used to construct a flat sentence
parent (int): parent node
hidden: if True then client should not render the node (this applies mainly for root)
Expand Down
83 changes: 3 additions & 80 deletions lib/plugins/masm_live_attributes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,89 +22,16 @@
from urllib.parse import urljoin
from typing import Any, List

import aiofiles
import plugins
import ujson as json
from action.control import http_action
from action.krequest import KRequest
from action.model.corpus import CorpusActionModel
from action.response import KResponse
from plugin_types.corparch import AbstractCorporaArchive
from plugin_types.live_attributes import (
AbstractLiveAttributes, AttrValuesResponse, BibTitle, LiveAttrsException)
from sanic.blueprints import Blueprint

from .doclist import DocListItem, mk_cache_key
from .doclist.writer import export_csv, export_jsonl, export_xlsx, export_xml

bp = Blueprint('masm_live_attributes')
UNLIMITED_LIST_PLACEHOLDER = 1_000_000
from plugin_types.live_attributes.doclist import DocListItem, mk_cache_key
from plugin_types.live_attributes.doclist.writer import export_csv, export_jsonl, export_xlsx, export_xml


@bp.route('/filter_attributes', methods=['POST'])
@http_action(return_type='json', action_model=CorpusActionModel)
async def filter_attributes(amodel: CorpusActionModel, req: KRequest, resp: KResponse):
attrs = json.loads(req.form.get('attrs', '{}'))
aligned = json.loads(req.form.get('aligned', '[]'))
with plugins.runtime.LIVE_ATTRIBUTES as lattr:
return await lattr.get_attr_values(
amodel.plugin_ctx, corpus=amodel.corp, attr_map=attrs,
aligned_corpora=aligned)


@bp.route('/attr_val_autocomplete', methods=['POST'])
@http_action(return_type='json', action_model=CorpusActionModel)
async def attr_val_autocomplete(amodel: CorpusActionModel, req: KRequest, resp: KResponse):
attrs = json.loads(req.form.get('attrs', '{}'))
pattern_attr = req.form.get('patternAttr')
with plugins.runtime.CORPARCH as ca:
corpus_info = await ca.get_corpus_info(amodel.plugin_ctx, amodel.corp.corpname)
attrs[pattern_attr] = '%{}%'.format(req.form.get('pattern'))
if pattern_attr == corpus_info.metadata.label_attr:
attrs[corpus_info.metadata.id_attr] = []
aligned = json.loads(req.form.get('aligned', '[]'))
with plugins.runtime.LIVE_ATTRIBUTES as lattr:
return await lattr.get_attr_values(
amodel.plugin_ctx, corpus=amodel.corp, attr_map=attrs,
aligned_corpora=aligned, autocomplete_attr=req.form.get('patternAttr'))


@bp.route('/fill_attrs', methods=['POST'])
@http_action(return_type='json', action_model=CorpusActionModel)
async def fill_attrs(amodel: CorpusActionModel, req: KRequest, resp: KResponse):
search = req.json['search']
values = req.json['values']
fill = req.json['fill']

with plugins.runtime.LIVE_ATTRIBUTES as lattr:
return await lattr.fill_attrs(corpus_id=amodel.corp.corpname, search=search, values=values, fill=fill)


@bp.route('/num_matching_documents', methods=['POST'])
@http_action(return_type='json', action_model=CorpusActionModel)
async def num_matching_documents(amodel: CorpusActionModel, req: KRequest, resp: KResponse):
with plugins.runtime.LIVE_ATTRIBUTES as lattr:
nm = await lattr.num_matching_documents(
amodel.plugin_ctx, amodel.args.corpname, req.json['lattrs'], req.json['laligned'])
return dict(num_documents=nm)


@bp.route('/save_document_list', methods=['POST'])
@http_action(return_type='plain', action_model=CorpusActionModel)
async def save_document_list(amodel: CorpusActionModel, req: KRequest, resp: KResponse):
attrs = req.json.get('lattrs', {})
aligned = req.json.get('laligned', [])
save_format = req.args.get('save_format')
with plugins.runtime.LIVE_ATTRIBUTES as lattr:
nm, ttype = await lattr.document_list(
amodel.plugin_ctx, amodel.args.corpname, req.args.getlist('lattr'), attrs, aligned, save_format)
resp.set_header('Content-Type', ttype)
file_size = await aiofiles.os.path.getsize(nm)
resp.set_header('Content-Length', str(file_size))
resp.set_header(
'Content-Disposition', f'attachment; filename="document-list-{amodel.args.corpname}.{save_format}"')
with open(nm, 'rb') as fr:
return fr.read()
UNLIMITED_LIST_PLACEHOLDER = 1_000_000


async def proc_masm_response(resp) -> Any:
Expand All @@ -118,10 +45,6 @@ class MasmLiveAttributes(AbstractLiveAttributes):

corparch: AbstractCorporaArchive

@staticmethod
def export_actions():
return bp

def __init__(
self,
corparch: AbstractCorporaArchive,
Expand Down
Loading

0 comments on commit d062d3a

Please sign in to comment.