Skip to content

Commit eb51a63

Browse files
Fix synonyms handling for ncit + linting
1 parent 71fed8a commit eb51a63

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/ncit/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable one-var */
12
const { loadDelimToJson } = require('../util');
23
const {
34
rid, convertRecordToQueryFilters, orderPreferredOntologyTerms,
@@ -101,15 +102,13 @@ const pickEndpoint = (conceptName, parentConcepts = '') => {
101102
* Synonyms filtering:
102103
* - no duplicates when compared in lowercase
103104
* - for each unique term, one original version kept only
104-
* - must be different from the record's name
105105
*
106106
* Returns an array of filtered synonyms
107107
*
108108
* @param {string[]} synonyms the synonym names to be formatted
109-
* @param {string} name the record's name to be filtered out
110109
* @returns {string[]}
111110
*/
112-
const filterSynonyms = (synonyms, name) => {
111+
const filterSynonyms = (synonyms) => {
113112
const filtered = new Map();
114113

115114
// distinct lowercase synonyms as key
@@ -122,9 +121,6 @@ const filterSynonyms = (synonyms, name) => {
122121
}
123122
});
124123

125-
// Remove name from synonyms
126-
filtered.delete(name.toLowerCase());
127-
128124
return Array.from(
129125
filtered.values(),
130126
);
@@ -232,7 +228,9 @@ const cleanRawRow = (rawRow) => {
232228
}
233229

234230
// synonyms
235-
const synonyms = filterSynonyms(row.synonyms, name);
231+
// We keep those equal to the record's name for now since we need them
232+
// for duplicated names disambiguation. They will be skipped later on.
233+
const synonyms = filterSynonyms(row.synonyms);
236234

237235
return {
238236
...row,
@@ -329,12 +327,14 @@ const uploadFile = async ({
329327
logger.verbose(`skipping (${deprecatedRows.length}) retired or obsolete concepts: ${deprecatedRows.map(d => d.sourceId).join(',')}`);
330328
const rejected = new Set();
331329

332-
// For duplicated names,
330+
// Name disambiguation, for duplicated names,
333331
// if possible, assign the row another name from its list of synonyms
334332
for (const [name, dups] of Object.entries(nameDuplicates)) {
333+
// skip if no duplicate for that name
335334
if (dups.length < 2) {
336335
continue;
337336
}
337+
338338
// filter non-human name duplicates
339339
const humanDups = [];
340340

@@ -465,6 +465,11 @@ const uploadFile = async ({
465465

466466
// add the synonyms as alias records
467467
for (const synonym of synonyms) {
468+
// Skipping synonym if equal to the record's name
469+
if (synonym.toLowerCase() === name) {
470+
continue;
471+
}
472+
468473
try {
469474
// alias Therapy|Disease|AnatomicalEntity node record
470475
const alias = await conn.addRecord({

test/ncit.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('cleanRawRow', () => {
123123
test.each([
124124
['to array', 'C', 'a|b', ['a', 'b']],
125125
['keep capitalization', 'C', 'A|B', ['A', 'B']],
126-
['filter by name', 'C', 'a|b|c', ['a', 'b']],
126+
['keep equal to name for now', 'C', 'a|b|c', ['a', 'b', 'c']],
127127
['remove duplicate', 'C', 'a|a', ['a']],
128128
['extra separators', 'C', '||a|b', ['a', 'b']],
129129
['add extra names to synonyms', 'a|b', 'c|d', ['c', 'd', 'b']],
@@ -167,10 +167,8 @@ describe('filterSynonyms', () => {
167167
'Abc',
168168
'ABC', // redundant based on lowercase comparison, to be skipped
169169
'def',
170-
'ghi', // synonym's name like record's name, to be skipped
171-
], 'Ghi'), // record's name, passed as capitalized
172-
).toEqual([
173-
'Abc',
170+
])).toEqual([
171+
'Abc', // keep capitalization
174172
'def',
175173
]);
176174
});

0 commit comments

Comments
 (0)