Skip to content

Commit

Permalink
Merge pull request #188 from biothings/empty-attributes
Browse files Browse the repository at this point in the history
Add empty attributes property to node/edge bindings and aux-graphs
  • Loading branch information
tokebe authored Apr 12, 2024
2 parents 0c1d167 + 112b775 commit 1bd30c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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();
}
Expand Down Expand Up @@ -254,7 +254,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 };
Expand All @@ -276,7 +276,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]);
}
Expand Down
9 changes: 5 additions & 4 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
Expand Down Expand Up @@ -357,6 +357,7 @@ export default class InferredQueryHandler {
},
[] as string[],
),
attributes: []
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/results_assembly/query_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
};
});
},
Expand Down

0 comments on commit 1bd30c5

Please sign in to comment.