From ac88bfc065206b135b82f252df7a1ccf7760da1d Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:50:24 -0400 Subject: [PATCH] feat: handling for non-array values --- src/graph/knowledge_graph.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/graph/knowledge_graph.ts b/src/graph/knowledge_graph.ts index 0ac539cd..f416ba26 100644 --- a/src/graph/knowledge_graph.ts +++ b/src/graph/knowledge_graph.ts @@ -17,6 +17,8 @@ import { APIDefinition } from '@biothings-explorer/types'; const debug = Debug('bte:biothings-explorer-trapi:KnowledgeGraph'); +const NON_ARRAY_ATTRIBUTES = ['biolink:knowledge_level', 'biolink:agent_type']; + export default class KnowledgeGraph { nodes: { [nodePrimaryID: string]: TrapiKGNode; @@ -114,11 +116,14 @@ export default class KnowledgeGraph { } Object.entries(kgEdge.attributes).forEach(([key, value]) => { - if (key == 'edge-attributes') return; + if (key === 'edge-attributes') return; // if (key == 'edge-attributes') return; attributes.push({ attribute_type_id: key, - value: Array.from(value as Set), + value: // technically works for numbers as well + NON_ARRAY_ATTRIBUTES.includes(key) + ? [...(value as Set)].reduce((acc, val) => acc + val) + : Array.from(value as Set), //value_type_id: 'bts:' + key, }); });