Skip to content

Commit

Permalink
Merge pull request #1285 from PathwayCommons/iss1148_organism-hints
Browse files Browse the repository at this point in the history
Adding an organism-hints model
  • Loading branch information
fileoy authored Jul 18, 2024
2 parents d3c4e4a + 1605d1a commit e7f2368
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/model/hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import _ from 'lodash';

const HINT_TYPE = Object.freeze({
ORGANISM: 'organism'
});
const HINT_TYPES = _.flatMap(HINT_TYPE);

const HINT_PASSAGE = Object.freeze({
TITLE: 'title',
ABSTRACT: 'abstract'
});
const HINT_PASSAGES = _.flatMap(HINT_PASSAGE);

/*
* Class representing a Hint.
* A hint is a piece of information that is extracted from sections of articles, such as the title or abstract.
* It can be about the organism being studied in the article or a gene name under investigation.
*/
class Hint{

/**
* Create a Hint.
* @param {string} text - The hint text.
* @param {string} type - The hint type.
* @param {Object} xref - The hint xref.
* @param {string} section - The hint section.
*/
constructor(text, type, xref, section){
this._text = text;
this._type = type;
this._xref = xref;
this._section = section;
}

/**
* Get the hint text.
* The text is a single mention extracted from the article section.
* @returns {string} The hint text.
*/
get text(){
return this._text;
}

set text(value){
this._text = value;
}

get type(){
return this._type;
}

set type(value){
if( value != HINT_TYPES.ORGANISM){
throw new Error('Invalid type' + value);
}
this._type = value;
}

get xref(){
return this._xref;
}

set xref(value){
if (!value.dbPrefix || !value.id){
throw new Error('Invalid xref' + JSON.stringify(value));
}
this._xref = value;
}

get section(){
return this._section;
}

set section(value){
if( value != HINT_PASSAGES.TITLE && value != HINT_PASSAGES.ABSTRACT){
throw new Error('Invalid section' + value);
}
this._section = value;
}
}
export {
Hint,
HINT_TYPES,
HINT_PASSAGES
};

0 comments on commit e7f2368

Please sign in to comment.