Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an organism-hints model #1285

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

fileoy marked this conversation as resolved.
Show resolved Hide resolved
/*
* 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{

fileoy marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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 sentence extracted from the article section.
* @returns {string} The hint text.
fileoy marked this conversation as resolved.
Show resolved Hide resolved
*/
get text(){
fileoy marked this conversation as resolved.
Show resolved Hide resolved
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
};