From 82bd2d691f3997acab186cf384cc0618b3ec40f5 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Tue, 16 Apr 2024 19:21:12 -0700 Subject: [PATCH] fix aux graph while loop --- src/inferred_mode/inferred_mode.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index dd5178a0..abcb0415 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -293,6 +293,7 @@ export default class InferredQueryHandler { // modified count used for pathfinder const pfIntermediateSet = new Set(); + let auxGraphSuffixes: {[inferredEdgeID: string]: number} = {}; // add results newResponse.message.results.forEach((result) => { const translatedResult: TrapiResult = { @@ -356,13 +357,9 @@ export default class InferredQueryHandler { attributes: [{ attribute_type_id: 'biolink:support_graphs', value: [] }], }; } - let auxGraphSuffix = 0; - while ( - Object.keys(combinedResponse.message.auxiliary_graphs).includes(`${inferredEdgeID}-support${auxGraphSuffix}`) - ) { - auxGraphSuffix += 1; - } - const auxGraphID = `${inferredEdgeID}-support${auxGraphSuffix}`; + if (!auxGraphSuffixes[inferredEdgeID]) auxGraphSuffixes[inferredEdgeID] = 0; + const auxGraphID = `${inferredEdgeID}-support${auxGraphSuffixes[inferredEdgeID]}`; + auxGraphSuffixes[inferredEdgeID]++; (combinedResponse.message.knowledge_graph.edges[inferredEdgeID].attributes[0].value as string[]).push( auxGraphID, );