From 112b775f6eafb58ce6b017ea7b1da020c03e6556 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:54:05 -0400 Subject: [PATCH] feat: node/edge bindings & auxgraph attributes --- src/index.ts | 6 +++--- src/inferred_mode/inferred_mode.ts | 9 +++++---- src/results_assembly/query_results.ts | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index cc4c6e01..30764a9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -209,7 +209,7 @@ export default class TRAPIQueryHandler { suffix += 1; } const supportGraphID = `support${suffix}-${boundEdgeID}`; - auxGraphs[supportGraphID] = { edges: supportGraph }; + auxGraphs[supportGraphID] = { edges: supportGraph, attributes: [] }; if (!edgesIDsByAuxGraphID[supportGraphID]) { edgesIDsByAuxGraphID[supportGraphID] = new Set(); } @@ -250,7 +250,7 @@ export default class TRAPIQueryHandler { boundIDs.add(binding.id); } } else if (!boundIDs.has(nodesToRebind[binding.id].newNode)) { - newBindings.push({ id: nodesToRebind[binding.id].newNode }); + newBindings.push({ id: nodesToRebind[binding.id].newNode, attributes: [] }); boundIDs.add(nodesToRebind[binding.id].newNode); } return { boundIDs, newBindings }; @@ -272,7 +272,7 @@ export default class TRAPIQueryHandler { boundIDs.add(binding.id); } } else if (!boundIDs.has(edgesToRebind[binding.id])) { - newBindings.push({ id: edgesToRebind[binding.id] }); + newBindings.push({ id: edgesToRebind[binding.id], attributes: [] }); boundIDs.add(edgesToRebind[binding.id]); resultBoundEdgesWithAuxGraphs.add(edgesToRebind[binding.id]); } diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index cd360243..ec798dd6 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -288,8 +288,8 @@ export default class InferredQueryHandler { newResponse.message.results.forEach((result) => { const translatedResult: TrapiResult = { node_bindings: { - [qEdge.subject]: [{ id: result.node_bindings.creativeQuerySubject[0].id }], - [qEdge.object]: [{ id: result.node_bindings.creativeQueryObject[0].id }], + [qEdge.subject]: [{ id: result.node_bindings.creativeQuerySubject[0].id, attributes: [] }], + [qEdge.object]: [{ id: result.node_bindings.creativeQueryObject[0].id, attributes: [] }], }, pfocr: result.pfocr?.length ? result.pfocr : undefined, analyses: [ @@ -311,14 +311,14 @@ export default class InferredQueryHandler { // Direct edge answers stand on their own, not as an inferred edge. if (Object.keys(result.node_bindings).length == 2) { const boundEdgeID = Object.values(result.analyses[0].edge_bindings)[0][0].id; - translatedResult.analyses[0].edge_bindings = { [qEdgeID]: [{ id: boundEdgeID }] }; + translatedResult.analyses[0].edge_bindings = { [qEdgeID]: [{ id: boundEdgeID, attributes: [] }] }; } else { // Create an aux graph using the result and associate it with an inferred Edge const inferredEdgeID = `inferred-${resultCreativeSubjectID}-${qEdge.predicates[0].replace( 'biolink:', '', )}-${resultCreativeObjectID}`; - translatedResult.analyses[0].edge_bindings = { [qEdgeID]: [{ id: inferredEdgeID }] }; + translatedResult.analyses[0].edge_bindings = { [qEdgeID]: [{ id: inferredEdgeID, attributes: [] }] }; if (!combinedResponse.message.knowledge_graph.edges[inferredEdgeID]) { combinedResponse.message.knowledge_graph.edges[inferredEdgeID] = { subject: resultCreativeSubjectID, @@ -353,6 +353,7 @@ export default class InferredQueryHandler { }, [] as string[], ), + attributes: [] }; } diff --git a/src/results_assembly/query_results.ts b/src/results_assembly/query_results.ts index 026556fc..d3c104d3 100644 --- a/src/results_assembly/query_results.ts +++ b/src/results_assembly/query_results.ts @@ -452,18 +452,21 @@ export default class TrapiResultsAssembler { result.node_bindings[inputQNodeID] = Array.from(inputPrimaryCuries).map((inputPrimaryCurie) => { return { id: inputPrimaryCurie, + attributes: [], }; }); result.node_bindings[outputQNodeID] = Array.from(outputPrimaryCuries).map((outputPrimaryCurie) => { return { id: outputPrimaryCurie, + attributes: [], }; }); result.analyses[0].edge_bindings[qEdgeID] = Array.from(recordHashes).map((recordHash) => { return { id: recordHash, + attributes: [], }; }); },