From 1961f2d4cfe67138b1c19b81fac5bf42ce240427 Mon Sep 17 00:00:00 2001 From: NeuralFlux <40491005+NeuralFlux@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:26:57 -0400 Subject: [PATCH 1/2] fix: added original curies to results as --- src/graph/kg_node.ts | 5 +++++ src/index.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/graph/kg_node.ts b/src/graph/kg_node.ts index 60dac19f..ff338c5d 100644 --- a/src/graph/kg_node.ts +++ b/src/graph/kg_node.ts @@ -8,12 +8,14 @@ export interface KGNodeInfo { curies: string[]; primaryCurie: string; qNodeID: string; + originalCurie?: string; } export default class KGNode { id: string; primaryCurie: string; qNodeID: string; + originalCurie: string; curies: string[]; names: string[]; semanticType: string[]; @@ -36,6 +38,9 @@ export default class KGNode { this.targetNodes = new Set(); this.sourceQNodeIDs = new Set(); this.targetQNodeIDs = new Set(); + + // store original curie to output `query_id bte#815` + this.originalCurie = info.originalCurie; } addSourceNode(kgNodeID: string): void { diff --git a/src/index.ts b/src/index.ts index 59401b36..202a182a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -317,6 +317,21 @@ export default class TRAPIQueryHandler { this.finalizedResults = fixedResults; } + appendOriginalCuriesToResults(results: TrapiResult[]): void { + results.forEach(result => { + Object.entries(result.node_bindings).map(([qNodeID, bindings]) => { + return [ + qNodeID, + bindings.forEach((binding) => { + if (this.bteGraph.nodes[binding.id].originalCurie && this.bteGraph.nodes[binding.id].originalCurie !== binding.id) { + binding.query_id = this.bteGraph.nodes[binding.id].originalCurie; + } + }) + ] + }) + }) + } + async addQueryNodes(): Promise { const qNodeIDsByOriginalID: Map = new Map(); const curiesToResolve = [ @@ -338,6 +353,7 @@ export default class TRAPIQueryHandler { this.bteGraph.nodes[resolvedEntity.primaryID] = new KGNode(resolvedEntity.primaryID, { primaryCurie: resolvedEntity.primaryID, qNodeID: qNodeIDsByOriginalID[originalCurie], + originalCurie: originalCurie, curies: resolvedEntity.equivalentIDs, names: resolvedEntity.labelAliases, semanticType: category ? [category] : ['biolink:NamedThing'], @@ -701,6 +717,8 @@ export default class TRAPIQueryHandler { this.createSubclassSupportGraphs(); // prune bteGraph this.bteGraph.prune(this.finalizedResults, this.auxGraphs); + // add original curies to results + this.appendOriginalCuriesToResults(this.finalizedResults); this.bteGraph.notify(); span3?.finish(); From d0b2ab5873469bef8fcd8c75eb1ad580cb47d41d Mon Sep 17 00:00:00 2001 From: NeuralFlux <40491005+NeuralFlux@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:49:37 -0400 Subject: [PATCH 2/2] fix: replaced redundant map with forEach --- src/index.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 202a182a..443654da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -319,15 +319,12 @@ export default class TRAPIQueryHandler { appendOriginalCuriesToResults(results: TrapiResult[]): void { results.forEach(result => { - Object.entries(result.node_bindings).map(([qNodeID, bindings]) => { - return [ - qNodeID, - bindings.forEach((binding) => { - if (this.bteGraph.nodes[binding.id].originalCurie && this.bteGraph.nodes[binding.id].originalCurie !== binding.id) { - binding.query_id = this.bteGraph.nodes[binding.id].originalCurie; - } - }) - ] + Object.entries(result.node_bindings).forEach(([_, bindings]) => { + bindings.forEach(binding => { + if (this.bteGraph.nodes[binding.id].originalCurie && this.bteGraph.nodes[binding.id].originalCurie !== binding.id) { + binding.query_id = this.bteGraph.nodes[binding.id].originalCurie; + } + }) }) }) }