1+ /* eslint-disable one-var */
12const { loadDelimToJson } = require ( '../util' ) ;
23const {
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 ( {
0 commit comments