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
Show file tree
Hide file tree
Changes from 3 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
66 changes: 66 additions & 0 deletions src/model/hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import _ from 'lodash';

//import { ENTITY_TYPE } from './entity-type.js';

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 Hint{

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
};
32 changes: 32 additions & 0 deletions src/server/routes/api/document/hint/pubtator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import _ from 'lodash';

import {
Hint,
HINT_TYPES
} from '../../../model/hint.js';

function map (bioCDocument) {
let hints = [];

const byText = annotation => {
const sanitzed = text => text.toLowerCase();
const { text } = annotation;
return sanitzed(text);
};

const byAnnotation = annotation => {

const isValidType = annotation => {
const {infons: { type } } = annotation;
return type === HINT_TYPES.ORGANISM;
};

const hasXref = annotation => {
const { infons } = annotation;
return _.has(infons, 'identifier');
};

return isValidType(annotation) && hasXref(annotation);
};

}