@@ -149,7 +149,6 @@ const MapProject = () => {
149149 const [ otherMatchedConcepts , setOtherMatchedConcepts ] = React . useState ( [ ] ) ;
150150 const [ bridgeCandidates , setBridgeCandidates ] = React . useState ( [ ] ) ;
151151 const [ scispacyCandidates , setScispacyCandidates ] = React . useState ( [ ] ) ;
152- const [ candidatesToSave , setCandidatesToSave ] = React . useState ( [ ] ) ;
153152 const [ searchedConcepts , setSearchedConcepts ] = React . useState ( { } ) ;
154153 const [ facets , setFacets ] = React . useState ( { } ) ;
155154 const [ appliedFacets , setAppliedFacets ] = React . useState ( { } ) ;
@@ -350,8 +349,21 @@ const MapProject = () => {
350349 } else {
351350 setLoadingProject ( false )
352351 }
353- setOtherMatchedConcepts ( response ?. data ?. candidates || [ ] )
354- setCandidatesToSave ( response ?. data ?. candidates || [ ] )
352+ let _candidates = [ ]
353+ let _bridgeCandidates = [ ]
354+ let _scispacyCandidates = [ ]
355+ forEach ( ( response ?. data ?. candidates || [ ] ) , candidate => {
356+ let algo = get ( candidate . results , '0.search_meta.algorithm' )
357+ if ( algo === 'ocl-ciel-bridge' )
358+ _bridgeCandidates . push ( candidate )
359+ else if ( algo === 'ocl-scispacy-loinc' )
360+ _scispacyCandidates . push ( candidate )
361+ else
362+ _candidates . push ( candidate )
363+ } )
364+ setOtherMatchedConcepts ( _candidates )
365+ setBridgeCandidates ( _bridgeCandidates )
366+ setScispacyCandidates ( _scispacyCandidates )
355367 setName ( response . data ?. name || '' )
356368 setDescription ( response . data ?. description || '' )
357369 setOwner ( response . data ?. owner_url )
@@ -730,12 +742,17 @@ const MapProject = () => {
730742 rowIndex : i
731743 }
732744 } )
733- const candidates = [ ]
734- forEach ( candidatesToSave , _candidates => {
735- if ( _candidates ?. results ?. length ) {
736- candidates . push ( { ..._candidates , results : _candidates . results . slice ( 0 , 10 ) } )
737- }
738- } )
745+ let _getCandidates = ( _candidates , returnAll ) => {
746+ let __candidates = [ ]
747+ forEach ( _candidates , ___candidates => {
748+ if ( ___candidates ?. results ?. length )
749+ __candidates . push ( { ...___candidates , results : returnAll ? ___candidates . results : ___candidates . results . slice ( 0 , CANDIDATES_LIMIT ) } )
750+ } )
751+ return __candidates
752+ }
753+ const candidates = [
754+ ..._getCandidates ( otherMatchedConcepts ) , ..._getCandidates ( bridgeCandidates ) , ..._getCandidates ( scispacyCandidates , true )
755+ ]
739756 const formData = new FormData ( ) ;
740757 formData . append ( 'file' , f ) ;
741758 formData . append ( 'candidates' , JSON . stringify ( candidates ) )
@@ -986,9 +1003,6 @@ const MapProject = () => {
9861003 setOtherMatchedConcepts ( prev => {
9871004 return [ ...reject ( prev , c => c . row . __index === concept . row . __index ) , concept ]
9881005 } )
989- setCandidatesToSave ( prev => {
990- return [ ...reject ( prev , c => c . row . __index === concept . row . __index ) , concept ]
991- } )
9921006 } )
9931007 setMatchedConcepts ( prev => [ ...prev , ...data ] ) ;
9941008 activeRequests . delete ( promise ) ; // Remove from active set after completion
@@ -1385,28 +1399,40 @@ const MapProject = () => {
13851399 return workbook
13861400 }
13871401
1388- const getTop10RowCandidates = ( index , removeNull = false ) => {
1389- let _candidates = find ( otherMatchedConcepts , c => c . row ?. __index === index ) ?. results || [ ]
1390- let _bridgeCandidates = find ( bridgeCandidates , c => c . row ?. __index === index ) ?. results || [ ]
1391- let _scispacyCandidates = find ( scispacyCandidates , c => c . row ?. __index === index ) ?. results || [ ]
1392- let __all = [ ...times ( 10 , i => _candidates [ i ] ) , ...times ( 10 , i => _bridgeCandidates [ i ] ) , ...times ( 10 , i => _scispacyCandidates [ i ] ) ]
1393- return removeNull ? compact ( __all ) : __all
1394- }
1395-
1396- const getTop10RowCandidatesForDownload = index => {
1397- let _candidatesTop10 = { } ;
1398- let _bridgeCandidatesTop10 = { } ;
1399- let _scispacyCandidatesTop10 = { } ;
1400- forEach ( getTop10RowCandidates ( index ) , ( candidate , i ) => {
1401- if ( i < 10 )
1402- _candidatesTop10 [ `__Candidate_Top_${ i + 1 } __` ] = candidate ?. id ? compact ( [ `${ candidate . id } :${ candidate . display_name } ` , `Score: ${ candidate ?. search_meta ?. search_normalized_score } ` ] ) . join ( '\n' ) : null
1403- else if ( bridgeEnabled ) {
1404- _bridgeCandidatesTop10 [ `__BridgeCandidate_Top_${ i - 9 } __` ] = candidate ? bridgeRef . current ?. getCandidateLabelForDownload ( candidate ) : null
1405- } else if ( scispacyEnabled ) {
1406- _scispacyCandidatesTop10 [ `__ScispacyCandidate_Top_${ i - 9 } __` ] = candidate ?. id ? compact ( [ `${ candidate . id } :${ candidate . display_name } ` , `Score: ${ candidate ?. search_meta ?. search_normalized_score } ` ] ) . join ( '\n' ) : null
1402+ const getTopRowCandidates = ( index ) => {
1403+ let _candidates = orderBy ( find ( otherMatchedConcepts , c => c . row ?. __index === index ) ?. results || [ ] , 'search_meta.search_normalized_score' , 'desc' )
1404+ let _bridgeCandidates = orderBy ( find ( bridgeCandidates , c => c . row ?. __index === index ) ?. results || [ ] , 'search_meta.search_normalized_score' , 'desc' )
1405+ let _scispacyCandidates = orderBy ( find ( scispacyCandidates , c => c . row ?. __index === index ) ?. results || [ ] , 'search_meta.search_normalized_score' , 'desc' )
1406+ return [ times ( CANDIDATES_LIMIT , i => _candidates [ i ] ) , times ( CANDIDATES_LIMIT , i => _bridgeCandidates [ i ] ) , times ( CANDIDATES_LIMIT , i => _scispacyCandidates [ i ] ) ]
1407+ }
1408+
1409+ const getRowCandidatesForDownload = index => {
1410+ let _candidates = { } ;
1411+ let _bridgeCandidates = { } ;
1412+ let _scispacyCandidates = { } ;
1413+ const [ __candidates , __bridgeCandidates , __scispacyCandidates ] = getTopRowCandidates ( index )
1414+ forEach ( __candidates , ( candidate , i ) => {
1415+ if ( candidate ?. id ) {
1416+ let algo = candidate . search_meta . algorithm || 'ocl-semantic'
1417+ algo = algo . replaceAll ( '-' , '' )
1418+ _candidates [ `__candidate__${ algo } _${ i + 1 } __` ] = candidate ?. id ? compact ( [ `${ candidate . id } :${ candidate . display_name } ` , `Score: ${ candidate ?. search_meta ?. search_normalized_score } ` ] ) . join ( '\n' ) : null
1419+ }
1420+ } )
1421+ forEach ( __bridgeCandidates , ( candidate , i ) => {
1422+ if ( candidate ?. id ) {
1423+ let algo = candidate . search_meta . algorithm || 'ocl-ciel-bridge'
1424+ algo = algo . replaceAll ( '-' , '' )
1425+ _bridgeCandidates [ `__candidate_${ algo } _${ i + 1 } __` ] = candidate ?. id ? bridgeRef . current ?. getCandidateLabelForDownload ( candidate ) : null
1426+ }
1427+ } )
1428+ forEach ( __scispacyCandidates , ( candidate , i ) => {
1429+ if ( candidate ?. id ) {
1430+ let algo = candidate . search_meta . algorithm || 'ocl-scispacy-loinc'
1431+ algo = algo . replaceAll ( '-' , '' )
1432+ _scispacyCandidates [ `__candidate_${ algo } _${ i + 1 } __` ] = candidate ?. id ? compact ( [ `${ candidate . id } :${ candidate . display_name } ` , `Score: ${ candidate ?. search_meta ?. search_normalized_score } ` ] ) . join ( '\n' ) : null
14071433 }
14081434 } )
1409- return { ..._candidatesTop10 , ..._bridgeCandidatesTop10 , ..._scispacyCandidatesTop10 }
1435+ return { ..._candidates , ..._bridgeCandidates , ..._scispacyCandidates }
14101436 }
14111437
14121438 const getRowsForDownload = ( ) => {
@@ -1420,7 +1446,7 @@ const MapProject = () => {
14201446 const aiCandidate = get ( aiRecommendation , 'primary_candidate' )
14211447 const aiCandidateID = aiCandidate ?. concept_id
14221448 const aiScore = compact ( [ aiCandidate ?. confidence_level , aiCandidate ?. match_strength ] ) . join ( ':' )
1423- let candidates = getTop10RowCandidatesForDownload ( index )
1449+ let candidates = getRowCandidatesForDownload ( index )
14241450 const getOutOfScopeSuggestions = ( ) => {
14251451 let suggestions = get ( aiRecommendation , 'out_of_scope_suggestions' ) || [ ]
14261452 return map ( suggestions , sugg => {
@@ -1451,6 +1477,7 @@ const MapProject = () => {
14511477 '__Repo URL__' : _repo ?. version_url || _repo ?. url ,
14521478 ...candidates ,
14531479 }
1480+ newRow = omitBy ( newRow , ( val , key ) => key . startsWith ( '__' ) && key . endsWith ( '__' ) && key . includes ( '_Top_' ) )
14541481 delete newRow . __index
14551482 return newRow
14561483 } )
@@ -1721,7 +1748,7 @@ const MapProject = () => {
17211748 const payload = { rows : [ { label : inputRow . name , itemid : __row . __index } ] }
17221749 const service = APIService . new ( )
17231750 service . URL = SCISPACY_API_URL
1724- service . appendToUrl ( '/$match-scispacy-loinc/' ) . post ( payload ) . then ( response => {
1751+ service . appendToUrl ( '/$match-scispacy-loinc/' ) . post ( payload , "a4cabbaabef41cf6fa3816d230f3a6a51bbe8f40" ) . then ( response => {
17251752 if ( ! isEmpty ( response ?. data ) ) {
17261753 let candidates = [ { row : __row , results : fromScispacyResultsToConcepts ( get ( response . data , __row . __index ) || [ ] ) } ]
17271754 setScispacyCandidates ( prev => [ ...reject ( prev , c => c . row . __index == __row . __index ) , ...( candidates || [ ] ) ] )
@@ -1735,7 +1762,7 @@ const MapProject = () => {
17351762 let formatted = [ ]
17361763 forEach ( results , ( result ) => {
17371764 if ( result ?. LOINC_NUM )
1738- formatted . push ( { id : result . LOINC_NUM , display_name : result . LONG_COMMON_NAME , search_meta : { search_normalized_score : result . composite_score * 100 } , extras : result , source : 'LOINC' } )
1765+ formatted . push ( { id : result . LOINC_NUM , display_name : result . LONG_COMMON_NAME , search_meta : { search_normalized_score : result . composite_score * 100 , search_score : result . composite_score , algorithm : 'ocl-scispacy-loinc' } , extras : result , source : 'LOINC' } )
17391766 } )
17401767 return formatted
17411768 }
0 commit comments