Merge branch 'query-builder' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into query-builder

This commit is contained in:
Inga Kirschnick 2023-11-07 13:24:11 +01:00
commit 1f40002249
11 changed files with 71 additions and 22 deletions

View File

@ -61,7 +61,7 @@ def build_corpus(corpus_id):
@bp.route('/stopwords') @bp.route('/stopwords')
@content_negotiation(produces='application/json') @content_negotiation(produces='application/json')
def get_stopwords(): def get_stopwords():
nltk.download('stopwords') nltk.download('stopwords', quiet=True)
languages = ["german", "english", "catalan", "greek", "spanish", "french", "italian", "russian", "chinese"] languages = ["german", "english", "catalan", "greek", "spanish", "french", "italian", "russian", "chinese"]
stopwords = {} stopwords = {}
for language in languages: for language in languages:

View File

@ -25,12 +25,12 @@ class CorpusAnalysisApp {
async init() { async init() {
this.disableActionElements(); this.disableActionElements();
this.elements.m.initModal.open(); this.elements.m.initModal.open();
try { try {
// Setup CQi over SocketIO connection and gather data from the CQPServer // Setup CQi over SocketIO connection and gather data from the CQPServer
const statusTextElement = this.elements.initModal.querySelector('.status-text'); const statusTextElement = this.elements.initModal.querySelector('.status-text');
statusTextElement.innerText = 'Creating CQi over SocketIO client...'; statusTextElement.innerText = 'Creating CQi over SocketIO client...';
const cqiClient = new cqi.CQiClient('/cqi_over_sio'); const cqiClient = new cqi.Client('/cqi_over_sio');
statusTextElement.innerText += ' Done'; statusTextElement.innerText += ' Done';
statusTextElement.innerHTML = 'Waiting for the CQP server...'; statusTextElement.innerHTML = 'Waiting for the CQP server...';
const response = await cqiClient.api.socket.emitWithAck('init', this.corpusId); const response = await cqiClient.api.socket.emitWithAck('init', this.corpusId);

View File

@ -0,0 +1,53 @@
/**
* @param {cqi.models.corpora.Corpus} corpus
* @param {number[]} cposList
* @returns {Promise<object>}
*/
async function lookupsByCpos(corpus, cposList) {
let lookups = {};
lookups['cpos_lookup'] = {};
for (let cpos in cposList) {
lookups['cpos_lookup'][cpos] = {};
}
let pAttrs = await corpus.positionalAttributes.list();
for (let attr in pAttrs) {
let values = await attr.valuesByCpos(cposList);
for (let i = 0; i < cposList.length; i++) {
let cpos = cposList[i];
let value = values[i];
lookups['cpos_lookup'][cpos][attr.name] = value;
}
}
let sAttrs = await corpus.structuralAttributes.list();
for (let attr in sAttrs) {
// We only want to iterate over non subattributes, identifiable by
// sAttr.hasValues == false
if (attr.hasValues) {continue;}
let idList = await attr.idsByCpos(cposList);
for (let i = 0; i < cposList.length; i++) {
let cpos = cposList[i];
let id = idList[i];
if (id == -1) {continue;}
lookups['cpos_lookup'][cpos][attr.name] = id;
}
let occuredIdList = Array.from(new Set(idList.filter(x => x != -1)));
if (occuredIdList.length == 0) {continue;}
let subattrs = sAttrs.filter(x => x.name.startsWith(`${attr.name}_`));
if (subattrs.length == 0) {continue;}
let lookupName = `${attr.name}_lookup`;
lookups[lookupName] = {};
for (let id in occuredIdList) {
lookups[lookupName][id] = {};
}
}
return lookups;
}

View File

@ -1 +0,0 @@
App = {};

View File

@ -1,4 +1,4 @@
cqi.api.APIClient = class APIClient { cqi.api.Client = class Client {
/** /**
* @param {string} host * @param {string} host
* @param {number} [timeout=60] timeout * @param {number} [timeout=60] timeout

View File

@ -1,12 +1,12 @@
cqi.CQiClient = class CQiClient { cqi.Client = class Client {
/** /**
* @param {string} host * @param {string} host
* @param {number} [timeout=60] timeout * @param {number} [timeout=60] timeout
* @param {string} [version=0.1] version * @param {string} [version=0.1] version
*/ */
constructor(host, timeout = 60, version = '0.1') { constructor(host, timeout = 60, version = '0.1') {
/** @type {cqi.api.APIClient} */ /** @type {cqi.api.Client} */
this.api = new cqi.api.APIClient(host, timeout, version); this.api = new cqi.api.Client(host, timeout, version);
} }
/** /**

View File

@ -37,7 +37,7 @@ cqi.models.attributes.AttributeCollection = class AttributeCollection extends cq
static model = cqi.models.attributes.Attribute; static model = cqi.models.attributes.Attribute;
/** /**
* @param {cqi.CQiClient} client * @param {cqi.Client} client
* @param {cqi.models.corpora.Corpus} corpus * @param {cqi.models.corpora.Corpus} corpus
*/ */
constructor(client, corpus) { constructor(client, corpus) {

View File

@ -1,9 +1,4 @@
// IDEA: Split the App logic into seperate units nopaque.App = class App {
// - App.Data
// - App.IO (name is WIP)
// - App.UI
App.App = class App {
constructor() { constructor() {
this.data = { this.data = {
promises: {getUser: {}, subscribeUser: {}}, promises: {getUser: {}, subscribeUser: {}},
@ -139,9 +134,9 @@ App.App = class App {
} }
optgroupElement.remove(); optgroupElement.remove();
} }
// #endregion // #endregion
/* Initialize Materialize Components */ /* Initialize Materialize Components */
// #region // #region
@ -190,10 +185,12 @@ App.App = class App {
); );
// #endregion // #endregion
// #region Nopaque Components
/* Initialize nopaque Components */
// #region
ResourceDisplays.AutoInit(); ResourceDisplays.AutoInit();
ResourceLists.AutoInit(); ResourceLists.AutoInit();
Forms.AutoInit(); Forms.AutoInit();
// #endregion Nopaque Components // #endregion
} }
}; };

View File

@ -0,0 +1 @@
var nopaque = {};

View File

@ -7,8 +7,8 @@
{%- assets {%- assets
filters='rjsmin', filters='rjsmin',
output='gen/app.%(version)s.js', output='gen/app.%(version)s.js',
'js/app/index.js', 'js/nopaque/index.js',
'js/app/app.js' 'js/nopaque/app.js'
%} %}
<script src="{{ ASSET_URL }}"></script> <script src="{{ ASSET_URL }}"></script>
{%- endassets %} {%- endassets %}
@ -115,7 +115,7 @@
<script> <script>
// TODO: Implement an app.run method and use this for all of the following // TODO: Implement an app.run method and use this for all of the following
const app = new App.App(); const app = new nopaque.App();
app.init(); app.init();
// Check if the current user is authenticated // Check if the current user is authenticated

View File

@ -281,7 +281,6 @@ let users = {
{% if not loop.last %},{% endif %} {% if not loop.last %},{% endif %}
{% endfor %} {% endfor %}
}; };
console.log(users);
let inviteUserModalSearch = M.Chips.init( let inviteUserModalSearch = M.Chips.init(
inviteUserModalSearchElement, inviteUserModalSearchElement,