Skip to content

Commit

Permalink
fix: added original curies to results as query_id (#204)
Browse files Browse the repository at this point in the history
* fix: added original curies to results as `query_id`

* fix: replaced redundant map with forEach
  • Loading branch information
NeuralFlux authored Aug 6, 2024
1 parent 1da1bde commit f6eaa70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/graph/kg_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ export default class TRAPIQueryHandler {
this.finalizedResults = fixedResults;
}

appendOriginalCuriesToResults(results: TrapiResult[]): void {
results.forEach(result => {
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;
}
})
})
})
}

async addQueryNodes(): Promise<void> {
const qNodeIDsByOriginalID: Map<string, TrapiQNode> = new Map();
const curiesToResolve = [
Expand All @@ -339,6 +351,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'],
Expand Down Expand Up @@ -702,6 +715,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();

// Attempt to enrich results with PFOCR figures
Expand Down

0 comments on commit f6eaa70

Please sign in to comment.