-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1285 from PathwayCommons/iss1148_organism-hints
Adding an organism-hints model
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |