Skip to content

Commit

Permalink
use canonical direction
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Aug 5, 2022
1 parent 984f68e commit ec0816e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/biolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class BioLinkModel {
return BioLinkModel.instance;
}

isCanonical(predicate) {
if (typeof predicate === 'string') {
if (predicate in this.biolink.slotTree.objects) {
console.log("slttree")
console.log(this.biolink.slotTree.objects[predicate])
if (this.biolink.slotTree.objects[predicate].canonical_predicate !== true) {
return false;
}
}
}
return true;
}

reverse(predicate) {
if (typeof predicate === 'string') {
if (predicate in this.biolink.slotTree.objects) {
Expand Down
13 changes: 13 additions & 0 deletions src/graph/graph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const kg_edge = require('./kg_edge');
const kg_node = require('./kg_node');
const debug = require('debug')('bte:biothings-explorer-trapi:Graph');
const biolink = require('../biolink')

module.exports = class BTEGraph {
constructor() {
Expand Down Expand Up @@ -91,6 +92,18 @@ module.exports = class BTEGraph {
debug(`pruned ${nodesToDelete.length} nodes and ${edgesToDelete.length} edges from BTEGraph.`);
}

useCanonicalDirection() {
Object.keys(this.edges).map(edgeID => {
const predicate = this.edges[edgeID].predicate.substring(8)
if (!biolink.isCanonical(predicate)) {
let temp = this.edges[edgeID].subject
this.edges[edgeID].subject = this.edges[edgeID].object
this.edges[edgeID].object = temp
this.edges[edgeID].predicate = 'biolink:' + biolink.reverse(predicate)
}
})
}

/**
* Register subscribers
* @param {object} subscriber
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
this.logs = [...this.logs, ...this.trapiResultsAssembler.logs];
// prune bteGraph
this.bteGraph.prune(this.trapiResultsAssembler.getResults());
this.bteGraph.useCanonicalDirection()
this.bteGraph.notify();
// finishing logs
this.createSummaryLog(this.logs).forEach((log) => this.logs.push(log));
Expand Down

0 comments on commit ec0816e

Please sign in to comment.