@@ -17,7 +17,8 @@ import { toArray, Telemetry } from '@biothings-explorer/utils';
17
17
18
18
const debug = Debug ( 'bte:biothings-explorer-trapi:KnowledgeGraph' ) ;
19
19
20
- const NON_ARRAY_ATTRIBUTES = [ 'biolink:knowledge_level' , 'biolink:agent_type' , 'biolink:evidence_count' ] ;
20
+ const NON_ARRAY_ATTRIBUTES = [ 'biolink:knowledge_level' , 'biolink:agent_type' ] ;
21
+ const SUM_ATTRIBUTES = [ 'biolink:evidence_count' ] ;
21
22
22
23
interface SpecialAttributeHandlers {
23
24
[ attribute_type_id : string ] : ( value : Set < string | number > , kgEdge : KGEdge ) => TrapiAttribute [ 'value' ] ;
@@ -149,12 +150,19 @@ export default class KnowledgeGraph {
149
150
Object . entries ( kgEdge . attributes ) . forEach ( ( [ key , value ] ) => {
150
151
if ( key === 'edge-attributes' ) return ;
151
152
152
- let formatted_value : TrapiAttribute [ 'value' ] = NON_ARRAY_ATTRIBUTES . includes ( key )
153
- ? Array . from ( value as Set < string > ) . reduce ( ( acc , val ) => acc + val )
154
- : Array . from ( value as Set < string > ) ;
153
+ let formatted_value : TrapiAttribute [ 'value' ] ;
154
+ if ( SUM_ATTRIBUTES . includes ( key ) ) {
155
+ // for sums we don't want to remove duplicates
156
+ formatted_value = ( value as string [ ] ) . reduce ( ( acc , val ) => acc + val ) ;
157
+ } else if ( NON_ARRAY_ATTRIBUTES . includes ( key ) ) {
158
+ // for non array attributes we want to remove duplicates (ie. same string for knowledge_level multiple times)
159
+ formatted_value = Array . from ( new Set ( value as string [ ] ) ) . reduce ( ( acc , val ) => acc + val ) ;
160
+ } else {
161
+ formatted_value = Array . from ( new Set ( value as string [ ] ) ) ;
162
+ }
155
163
156
164
if ( key in SPECIAL_ATTRIBUTE_HANDLERS ) {
157
- formatted_value = SPECIAL_ATTRIBUTE_HANDLERS [ key ] ( value as Set < string | number > , kgEdge ) ;
165
+ formatted_value = SPECIAL_ATTRIBUTE_HANDLERS [ key ] ( new Set ( value as string [ ] ) , kgEdge ) ;
158
166
}
159
167
160
168
attributes . push ( {
0 commit comments