mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Replace the old js CQiClient with fully featured new one
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -26,25 +26,19 @@ class CorpusAnalysisApp {
 | 
			
		||||
    this.disableActionElements();
 | 
			
		||||
    this.elements.m.initModal.open();
 | 
			
		||||
    // Init data
 | 
			
		||||
    this.data.cQiClient = new CQiClient(this.settings.corpusId);
 | 
			
		||||
    this.data.cQiClient.connect()
 | 
			
		||||
      .then(cQiStatus => {
 | 
			
		||||
        return this.data.cQiClient.corpora.get(`NOPAQUE_${this.settings.corpusId}`);
 | 
			
		||||
    this.data.cqiClient = new cqi.CQiClient('/cqi_over_sio', this.settings.corpusId);
 | 
			
		||||
    this.data.cqiClient.connect('anonymous', '')
 | 
			
		||||
      .then((cqiStatus) => {
 | 
			
		||||
        return this.data.cqiClient.corpora.list();
 | 
			
		||||
      })
 | 
			
		||||
      .then(
 | 
			
		||||
        cQiCorpus => {
 | 
			
		||||
          this.data.corpus = {o: cQiCorpus};
 | 
			
		||||
          this.data.corpus.o.getVisualizationData()
 | 
			
		||||
            .then(
 | 
			
		||||
              (data) => {
 | 
			
		||||
                console.log(data);
 | 
			
		||||
                this.renderGeneralCorpusInfo(data);
 | 
			
		||||
                this.renderTextInfoList(data);
 | 
			
		||||
                this.renderTextProportionsGraphic(data);
 | 
			
		||||
                this.renderFrequenciesGraphic(data);
 | 
			
		||||
                this.renderBoundsGraphic(data);
 | 
			
		||||
              }
 | 
			
		||||
            );
 | 
			
		||||
      .then((cqiCorpora) => {
 | 
			
		||||
          this.data.corpus = {o: cqiCorpora[0]};
 | 
			
		||||
          console.log(this.data.corpus.o.staticData);
 | 
			
		||||
          this.renderGeneralCorpusInfo(this.data.corpus.o.staticData);
 | 
			
		||||
          this.renderTextInfoList(this.data.corpus.o.staticData);
 | 
			
		||||
          this.renderTextProportionsGraphic(this.data.corpus.o.staticData);
 | 
			
		||||
          this.renderFrequenciesGraphic(this.data.corpus.o.staticData);
 | 
			
		||||
          this.renderBoundsGraphic(this.data.corpus.o.staticData);
 | 
			
		||||
          // this.data.corpus.o.getCorpusData()
 | 
			
		||||
          //   .then(corpusData => {
 | 
			
		||||
          //     console.log(corpusData);
 | 
			
		||||
@@ -55,19 +49,20 @@ class CorpusAnalysisApp {
 | 
			
		||||
          //     this.renderBoundsGraphic(corpusData);
 | 
			
		||||
          //   });
 | 
			
		||||
          // TODO: Don't do this hgere
 | 
			
		||||
          cQiCorpus.updateDb();
 | 
			
		||||
          this.data.corpus.o.updateDb();
 | 
			
		||||
          this.enableActionElements();
 | 
			
		||||
          for (let extension of Object.values(this.extensions)) {extension.init();}
 | 
			
		||||
          this.elements.m.initModal.close();
 | 
			
		||||
        },
 | 
			
		||||
        cQiError => {
 | 
			
		||||
        (cqiError) => {
 | 
			
		||||
          // TODO: CHECK THIS!
 | 
			
		||||
          let errorsElement = this.elements.initModal.querySelector('.errors');
 | 
			
		||||
          let progressElement = this.elements.initModal.querySelector('.progress');
 | 
			
		||||
          errorsElement.innerText = JSON.stringify(cQiError);
 | 
			
		||||
          errorsElement.innerText = JSON.stringify(cqiError);
 | 
			
		||||
          errorsElement.classList.remove('hide');
 | 
			
		||||
          progressElement.classList.add('hide');
 | 
			
		||||
          if ('payload' in cQiError && 'code' in cQiError.payload && 'msg' in cQiError.payload) {
 | 
			
		||||
            app.flash(`${cQiError.payload.code}: ${cQiError.payload.msg}`, 'error');
 | 
			
		||||
          if ('payload' in cqiError && 'code' in cqiError.payload && 'msg' in cqiError.payload) {
 | 
			
		||||
            app.flash(`${cqiError.payload.code}: ${cqiError.payload.msg}`, 'error');
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
 
 | 
			
		||||
@@ -45,18 +45,18 @@ class CorpusAnalysisConcordance {
 | 
			
		||||
      this.elements.progress.classList.remove('hide');
 | 
			
		||||
      let subcorpus = {};
 | 
			
		||||
      this.data.corpus.o.query(subcorpusName, query)
 | 
			
		||||
        .then(cQiStatus => {
 | 
			
		||||
        .then((cqiStatus) => {
 | 
			
		||||
          subcorpus.q = query;
 | 
			
		||||
          subcorpus.selectedItems = new Set();
 | 
			
		||||
          if (subcorpusName !== 'Last') {this.data.subcorpora.Last = subcorpus;}
 | 
			
		||||
          return this.data.corpus.o.subcorpora.get(subcorpusName);
 | 
			
		||||
        })
 | 
			
		||||
        .then(cQiSubcorpus => {
 | 
			
		||||
          subcorpus.o = cQiSubcorpus;
 | 
			
		||||
          return cQiSubcorpus.paginate(1, this.settings.perPage, this.settings.context);
 | 
			
		||||
        .then((cqiSubcorpus) => {
 | 
			
		||||
          subcorpus.o = cqiSubcorpus;
 | 
			
		||||
          return cqiSubcorpus.paginate(this.settings.context, 1, this.settings.perPage);
 | 
			
		||||
        })
 | 
			
		||||
        .then(
 | 
			
		||||
          paginatedSubcorpus => {
 | 
			
		||||
          (paginatedSubcorpus) => {
 | 
			
		||||
            subcorpus.p = paginatedSubcorpus;
 | 
			
		||||
            this.data.subcorpora[subcorpusName] = subcorpus;
 | 
			
		||||
            this.settings.selectedSubcorpus = subcorpusName;
 | 
			
		||||
@@ -68,11 +68,12 @@ class CorpusAnalysisConcordance {
 | 
			
		||||
            this.elements.progress.classList.add('hide');
 | 
			
		||||
            this.app.enableActionElements();
 | 
			
		||||
          },
 | 
			
		||||
          cQiError => {
 | 
			
		||||
            this.elements.error.innerText = JSON.stringify(cQiError);
 | 
			
		||||
          (cqiStatus) => {
 | 
			
		||||
            // TODDO: CHECK THIS!
 | 
			
		||||
            this.elements.error.innerText = JSON.stringify(cqiStatus);
 | 
			
		||||
            this.elements.error.classList.remove('hide');
 | 
			
		||||
            if ('payload' in cQiError && 'code' in cQiError.payload && 'msg' in cQiError.payload) {
 | 
			
		||||
              app.flash(`${cQiError.payload.code}: ${cQiError.payload.msg}`, 'error');
 | 
			
		||||
            if ('payload' in cqiStatus && 'code' in cqiStatus.payload && 'msg' in cqiStatus.payload) {
 | 
			
		||||
              app.flash(`${cqiStatus.payload.code}: ${cqiStatus.payload.msg}`, 'error');
 | 
			
		||||
            }
 | 
			
		||||
            this.elements.progress.classList.add('hide');
 | 
			
		||||
            this.app.enableActionElements();
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ class CorpusAnalysisReader {
 | 
			
		||||
  init() {
 | 
			
		||||
    // Init data
 | 
			
		||||
    this.data.corpus = this.app.data.corpus;
 | 
			
		||||
    this.data.subcorpora = {};
 | 
			
		||||
    this.data.subcorpora = {};    // TODO: DO WE NEED THIS HERE?
 | 
			
		||||
    // Add event listeners
 | 
			
		||||
    this.elements.form.addEventListener('submit', (event) => {
 | 
			
		||||
      event.preventDefault();
 | 
			
		||||
@@ -38,14 +38,15 @@ class CorpusAnalysisReader {
 | 
			
		||||
      this.elements.progress.classList.remove('hide');
 | 
			
		||||
      this.data.corpus.o.paginate(1, this.settings.perPage)
 | 
			
		||||
        .then(
 | 
			
		||||
          paginatedCorpus => {
 | 
			
		||||
          (paginatedCorpus) => {
 | 
			
		||||
            this.data.corpus.p = paginatedCorpus;
 | 
			
		||||
            this.renderCorpus();
 | 
			
		||||
            this.renderCorpusPagination();
 | 
			
		||||
            this.elements.progress.classList.add('hide');
 | 
			
		||||
            this.app.enableActionElements();
 | 
			
		||||
          },
 | 
			
		||||
          error => {
 | 
			
		||||
          (cqiError) => {
 | 
			
		||||
            // TODO: CHECK THIS!
 | 
			
		||||
            this.elements.error.innerText = JSON.stringify(error);
 | 
			
		||||
            this.elements.error.classList.remove('hide');
 | 
			
		||||
            if ('payload' in error && 'code' in error.payload && 'msg' in error.payload) {
 | 
			
		||||
@@ -247,7 +248,7 @@ class CorpusAnalysisReader {
 | 
			
		||||
    this.elements.progress.classList.remove('hide');
 | 
			
		||||
    this.data.corpus.o.paginate(pageNum, this.settings.perPage)
 | 
			
		||||
      .then(
 | 
			
		||||
        paginatedCorpus => {
 | 
			
		||||
        (paginatedCorpus) => {
 | 
			
		||||
          this.data.corpus.p = paginatedCorpus;
 | 
			
		||||
          this.renderCorpus();
 | 
			
		||||
          this.renderCorpusPagination();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,13 @@
 | 
			
		||||
cqi.api.APIClient = class APIClient {
 | 
			
		||||
  constructor(host, corpus_id, version = '0.1') {
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} host
 | 
			
		||||
   * @param {string} corpusId
 | 
			
		||||
   * @param {number} [timeout=Infinity] timeout
 | 
			
		||||
   * @param {string} [version=0.1] version
 | 
			
		||||
   */
 | 
			
		||||
  constructor(host, corpus_id, timeout = Infinity, version = '0.1') {
 | 
			
		||||
    this.host = host;
 | 
			
		||||
    this.timeout = timeout;
 | 
			
		||||
    this.version = version;
 | 
			
		||||
    this.socket = io(
 | 
			
		||||
      this.host,
 | 
			
		||||
@@ -19,7 +26,8 @@ cqi.api.APIClient = class APIClient {
 | 
			
		||||
   */
 | 
			
		||||
  #request(fn_name, fn_args = {}) {
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      this.socket.emit('cqi_client.api', {fn_name: fn_name, fn_args: fn_args}, (response) => {
 | 
			
		||||
      // TODO: implement this.socket.timeout(this.timeout).emit(...)
 | 
			
		||||
      this.socket.emit('cqi', {fn_name: fn_name, fn_args: fn_args}, (response) => {
 | 
			
		||||
        if (response.code === 200) {
 | 
			
		||||
          resolve(response.payload);
 | 
			
		||||
        }
 | 
			
		||||
@@ -595,4 +603,84 @@ cqi.api.APIClient = class APIClient {
 | 
			
		||||
    const fn_args = {subcorpus: subcorpus, cutoff: cutoff, field1: field1, attribute1: attribute1, field2: field2, attribute2: attribute2};
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * NOTE: The following functions are non standard implementations of nopaque
 | 
			
		||||
   */
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} corpus
 | 
			
		||||
   * @returns {Promise<cqi.status.StatusOk>}
 | 
			
		||||
   */
 | 
			
		||||
  async corpus_update_db(corpus) {
 | 
			
		||||
    const fn_name = 'nopaque_corpus_update_db';
 | 
			
		||||
    const fn_args = {corpus: corpus};
 | 
			
		||||
    let payload = await this.#request(fn_name, fn_args);
 | 
			
		||||
    return new cqi.status.lookup[payload.code]();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} corpus
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async corpus_static_data(corpus) {
 | 
			
		||||
    const fn_name = 'nopaque_corpus_static_data';
 | 
			
		||||
    const fn_args = {corpus: corpus};
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} corpus
 | 
			
		||||
   * @param {number=} page
 | 
			
		||||
   * @param {number=} per_page
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async corpus_paginate_corpus(corpus, page, per_page) {
 | 
			
		||||
    const fn_name = 'nopaque_corpus_paginate_corpus';
 | 
			
		||||
    const fn_args = {corpus: corpus}
 | 
			
		||||
    if (page !== undefined) {fn_args.page = page;}
 | 
			
		||||
    if (per_page !== undefined) {fn_args.per_page = per_page;}
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} subcorpus
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @param {number=} page
 | 
			
		||||
   * @param {number=} per_page
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async cqp_paginate_subcorpus(subcorpus, context, page, per_page) {
 | 
			
		||||
    const fn_name = 'nopaque_cqp_paginate_subcorpus';
 | 
			
		||||
    const fn_args = {subcorpus: subcorpus}
 | 
			
		||||
    if (context !== undefined) {fn_args.context = context;}
 | 
			
		||||
    if (page !== undefined) {fn_args.page = page;}
 | 
			
		||||
    if (per_page !== undefined) {fn_args.per_page = per_page;}
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} subcorpus
 | 
			
		||||
   * @param {number[]} match_id_list
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async cqp_partial_export_subcorpus(subcorpus, match_id_list, context) {
 | 
			
		||||
    const fn_name = 'nopaque_cqp_partial_export_subcorpus';
 | 
			
		||||
    const fn_args = {subcorpus: subcorpus, match_id_list: match_id_list};
 | 
			
		||||
    if (context !== undefined) {fn_args.context = context;}
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} subcorpus
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async cqp_export_subcorpus(subcorpus, context) {
 | 
			
		||||
    const fn_name = 'nopaque_cqp_export_subcorpus';
 | 
			
		||||
    const fn_args = {subcorpus: subcorpus};
 | 
			
		||||
    if (context !== undefined) {fn_args.context = context;}
 | 
			
		||||
    return await this.#request(fn_name, fn_args);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,10 @@ cqi.CQiClient = class CQiClient {
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {string} host
 | 
			
		||||
   * @param {string} corpusId
 | 
			
		||||
   * @param {number} [timeout=Infinity] timeout
 | 
			
		||||
   * @param {string} [version=0.1] version
 | 
			
		||||
   */
 | 
			
		||||
  constructor(host, corpusId, version = '0.1') {
 | 
			
		||||
  constructor(host, corpusId, timeout = Infinity, version = '0.1') {
 | 
			
		||||
     /** @type {cqi.api.APIClient} */
 | 
			
		||||
    this.api = new cqi.api.APIClient(host, corpusId, version);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -80,6 +80,33 @@ cqi.models.corpora.Corpus = class Corpus extends cqi.models.resource.Model {
 | 
			
		||||
  async query(subcorpusName, query) {
 | 
			
		||||
    return await this.client.api.cqp_query(this.apiName, subcorpusName, query);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**************************************************************************
 | 
			
		||||
   * NOTE: The following are non standard implementations of nopaque        *
 | 
			
		||||
   **************************************************************************/
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @returns {string}
 | 
			
		||||
   */
 | 
			
		||||
  get staticData() {
 | 
			
		||||
    return this.attrs.static_data;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @returns {cqi.status.StatusOk}
 | 
			
		||||
   */
 | 
			
		||||
  async updateDb() {
 | 
			
		||||
    return await this.client.api.corpus_update_db(this.apiName);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {number=} page
 | 
			
		||||
   * @param {number=} per_page
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async paginate(page, per_page) {
 | 
			
		||||
    return await this.client.api.corpus_paginate_corpus(this.apiName, page, per_page);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -95,11 +122,12 @@ cqi.models.corpora.CorpusCollection = class CorpusCollection extends cqi.models.
 | 
			
		||||
    return {
 | 
			
		||||
      api_name: corpusName,
 | 
			
		||||
      charset: await this.client.api.corpus_charset(corpusName),
 | 
			
		||||
      // full_name: await this.client.api.corpus_full_name(api_name),
 | 
			
		||||
      // info: await this.client.api.corpus_info(api_name),
 | 
			
		||||
      // full_name: await this.client.api.corpus_full_name(corpusName),
 | 
			
		||||
      // info: await this.client.api.corpus_info(corpusName),
 | 
			
		||||
      name: corpusName,
 | 
			
		||||
      properties: await this.client.api.corpus_properties(corpusName),
 | 
			
		||||
      size: await this.client.api.cl_attribute_size(`${corpusName}.word`)
 | 
			
		||||
      size: await this.client.api.cl_attribute_size(`${corpusName}.word`),
 | 
			
		||||
      static_data: await this.client.api.corpus_static_data(corpusName),
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -85,6 +85,37 @@ cqi.models.subcorpora.Subcorpus = class Subcorpus extends cqi.models.resource.Mo
 | 
			
		||||
      attribute2.apiName
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**************************************************************************
 | 
			
		||||
   * NOTE: The following are non standard implementations of nopaque        *
 | 
			
		||||
   **************************************************************************/
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @param {number=} page
 | 
			
		||||
   * @param {number=} perPage
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async paginate(context, page, perPage) {
 | 
			
		||||
    return await this.client.api.cqp_paginate_subcorpus(this.apiName, context, page, perPage);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {number[]} matchIdList
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async partialExport(matchIdList, context) {
 | 
			
		||||
    return await this.client.api.cqp_partial_export_subcorpus(this.apiName, matchIdList, context);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param {number=} context
 | 
			
		||||
   * @returns {Promise<object>}
 | 
			
		||||
   */
 | 
			
		||||
  async export(context) {
 | 
			
		||||
    return await this.client.api.cqp_export_subcorpus(this.apiName, context);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user