mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-07 05:03:18 +00:00
Some code cleanup
This commit is contained in:
@ -25,12 +25,12 @@ class CorpusAnalysisApp {
|
||||
async init() {
|
||||
this.disableActionElements();
|
||||
this.elements.m.initModal.open();
|
||||
|
||||
|
||||
try {
|
||||
// Setup CQi over SocketIO connection and gather data from the CQPServer
|
||||
const statusTextElement = this.elements.initModal.querySelector('.status-text');
|
||||
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.innerHTML = 'Waiting for the CQP server...';
|
||||
const response = await cqiClient.api.socket.emitWithAck('init', this.corpusId);
|
||||
|
53
app/static/js/CorpusAnalysis/Utils.js
Normal file
53
app/static/js/CorpusAnalysis/Utils.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user