cqi.models.attributes = {}; cqi.models.attributes.Attribute = class Attribute extends cqi.models.resource.Model { /** * @returns {string} */ get apiName() { return this.attrs.api_name; } /** * @returns {string} */ get name() { return this.attrs.name; } /** * @returns {number} */ get size() { return this.attrs.size; } /** * @returns {Promise} */ async drop() { return await this.client.api.cl_drop_attribute(this.apiName); } }; cqi.models.attributes.AttributeCollection = class AttributeCollection extends cqi.models.resource.Collection { /** @type{typeof cqi.models.attributes.Attribute} */ static model = cqi.models.attributes.Attribute; /** * @param {cqi.CQiClient} client * @param {cqi.models.corpora.Corpus} corpus */ constructor(client, corpus) { super(client); /** @type {cqi.models.corpora.Corpus} */ this.corpus = corpus; } /** * @param {string} attributeName * @returns {Promise} */ async _get(attributeName) { /** @type{string} */ let apiName = `${this.corpus.apiName}.${attributeName}`; return { api_name: apiName, name: attributeName, size: await this.client.api.cl_attribute_size(apiName) } } /** * @param {string} attributeName * @returns {Promise} */ async get(attributeName) { return this.prepareModel(await this._get(attributeName)); } }; cqi.models.attributes.AlignmentAttribute = class AlignmentAttribute extends cqi.models.attributes.Attribute { /** * @param {number} id * @returns {Promise<[number, number, number, number]>} */ async cposById(id) { return await this.client.api.cl_alg2cpos(this.apiName, id); } /** * @param {number[]} cposList * @returns {Promise} */ async idsByCpos(cposList) { return await this.client.api.cl_cpos2alg(this.apiName, cposList); } }; cqi.models.attributes.AlignmentAttributeCollection = class AlignmentAttributeCollection extends cqi.models.attributes.AttributeCollection { /** @type{typeof cqi.models.attributes.AlignmentAttribute} */ static model = cqi.models.attributes.AlignmentAttribute; /** * @returns {Promise} */ async list() { /** @type {string[]} */ let alignmentAttributeNames = await this.client.api.corpus_alignment_attributes(this.corpus.apiName); /** @type {cqi.models.attributes.AlignmentAttribute[]} */ let alignmentAttributes = []; for (let alignmentAttributeName of alignmentAttributeNames) { alignmentAttributes.push(await this.get(alignmentAttributeName)); } return alignmentAttributes; } }; cqi.models.attributes.PositionalAttribute = class PositionalAttribute extends cqi.models.attributes.Attribute { /** * @returns {number} */ get lexiconSize() { return this.attrs.lexicon_size; } /** * @param {number} id * @returns {Promise} */ async cposById(id) { return await this.client.api.cl_id2cpos(this.apiName, id); } /** * @param {number[]} idList * @returns {Promise} */ async cposByIds(idList) { return await this.client.api.cl_idlist2cpos(this.apiName, idList); } /** * @param {number[]} idList * @returns {Promise} */ async freqsByIds(idList) { return await this.client.api.cl_id2freq(this.apiName, idList); } /** * @param {number[]} cposList * @returns {Promise} */ async idsByCpos(cposList) { return await this.client.api.cl_cpos2id(this.apiName, cposList); } /** * @param {string} regex * @returns {Promise} */ async idsByRegex(regex) { return await this.client.api.cl_regex2id(this.apiName, regex); } /** * @param {string[]} valueList * @returns {Promise} */ async idsByValues(valueList) { return await this.client.api.cl_str2id(this.apiName, valueList); } /** * @param {number[]} cposList * @returns {Promise} */ async valuesByCpos(cposList) { return await this.client.api.cl_cpos2str(this.apiName, cposList); } /** * @param {number[]} idList * @returns {Promise} */ async valuesByIds(idList) { return await this.client.api.cl_id2str(this.apiName, idList); } }; cqi.models.attributes.PositionalAttributeCollection = class PositionalAttributeCollection extends cqi.models.attributes.AttributeCollection { /** @type{typeof cqi.models.attributes.PositionalAttribute} */ static model = cqi.models.attributes.PositionalAttribute; /** * @param {string} positionalAttributeName * @returns {Promise} */ async _get(positionalAttributeName) { let positionalAttribute = await super._get(positionalAttributeName); positionalAttribute.lexicon_size = await this.client.api.cl_lexicon_size(positionalAttribute.api_name); return positionalAttribute; } /** * @returns {Promise} */ async list() { let positionalAttributeNames = await this.client.api.corpus_positional_attributes(this.corpus.apiName); let positionalAttributes = []; for (let positionalAttributeName of positionalAttributeNames) { positionalAttributes.push(await this.get(positionalAttributeName)); } return positionalAttributes; } }; cqi.models.attributes.StructuralAttribute = class StructuralAttribute extends cqi.models.attributes.Attribute { /** * @returns {boolean} */ get hasValues() { return this.attrs.has_values; } /** * @param {number} id * @returns {Promise<[number, number]>} */ async cposById(id) { return await this.client.api.cl_struc2cpos(this.apiName, id); } /** * @param {number[]} cposList * @returns {Promise} */ async idsByCpos(cposList) { return await this.client.api.cl_cpos2struc(this.apiName, cposList); } /** * @param {number[]} cposList * @returns {Promise} */ async lboundByCpos(cposList) { return await this.client.api.cl_cpos2lbound(this.apiName, cposList); } /** * @param {number[]} cposList * @returns {Promise} */ async rboundByCpos(cposList) { return await this.client.api.cl_cpos2rbound(this.apiName, cposList); } /** * @param {number[]} idList * @returns {Promise} */ async valuesByIds(idList) { return await this.client.api.cl_struc2str(this.apiName, idList); } }; cqi.models.attributes.StructuralAttributeCollection = class StructuralAttributeCollection extends cqi.models.attributes.AttributeCollection { /** @type{typeof cqi.models.attributes.StructuralAttribute} */ static model = cqi.models.attributes.StructuralAttribute; /** * @param {string} structuralAttributeName * @returns {Promise} */ async _get(structuralAttributeName) { let structuralAttribute = await super._get(structuralAttributeName); structuralAttribute.has_values = await this.client.api.cl_has_values(structuralAttribute.api_name); return structuralAttribute; } /** * @returns {Promise} */ async list() { let structuralAttributeNames = await this.client.api.corpus_structural_attributes(this.corpus.apiName); let structuralAttributes = []; for (let structuralAttributeName of structuralAttributeNames) { structuralAttributes.push(await this.get(structuralAttributeName)); } return structuralAttributes; } };