From a073f9959c8a3c2f7fdda8fe0c83768d125e943f Mon Sep 17 00:00:00 2001 From: jiwen xin Date: Mon, 1 Feb 2021 20:40:33 -0800 Subject: [PATCH 1/2] fix: :bug: use predicate from api if no predicate supplied in qg https://github.com/biothings/BioThings_Explorer_TRAPI/issues/29 --- src/controllers/QueryGraphHandler/knowledge_graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/QueryGraphHandler/knowledge_graph.js b/src/controllers/QueryGraphHandler/knowledge_graph.js index ff3f0f70..8023197e 100644 --- a/src/controllers/QueryGraphHandler/knowledge_graph.js +++ b/src/controllers/QueryGraphHandler/knowledge_graph.js @@ -80,7 +80,7 @@ module.exports = class KnowledgeGraph { _createEdge(record) { return { [helper._createUniqueEdgeID(record)]: { - predicate: "biolink:" + record["$reasoner_edge"].getQueryPredicate(), + predicate: "biolink:" + ((typeof record["$reasoner_edge"].getQueryPredicate() === "undefined") ? record["$association"].predicate : record["$reasoner_edge"].getQueryPredicate()), subject: helper._getInputID(record), object: helper._getOutputID(record), attributes: this._createAttributes(record) From 56eb1feed819ea4c682c7700602796a663f85ff0 Mon Sep 17 00:00:00 2001 From: jiwen xin Date: Mon, 1 Feb 2021 20:41:03 -0800 Subject: [PATCH 2/2] fix: :bug: check if user provided predicate is undefined https://github.com/biothings/BioThings_Explorer_TRAPI/issues/29 --- src/controllers/QueryGraphHandler/reverse.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controllers/QueryGraphHandler/reverse.js b/src/controllers/QueryGraphHandler/reverse.js index 9abb2ef9..6cbbaef8 100644 --- a/src/controllers/QueryGraphHandler/reverse.js +++ b/src/controllers/QueryGraphHandler/reverse.js @@ -8,12 +8,15 @@ module.exports = class EdgeReverse { } reverse(predicate) { - let modifiedPredicate = predicate.replace('_', ' '); - if (modifiedPredicate in this.data.slots) { - if ('inverse' in this.data.slots[modifiedPredicate]) { - return this.data.slots[modifiedPredicate].inverse.replace(' ', '_'); + if (typeof predicate === "string") { + let modifiedPredicate = predicate.replace('_', ' '); + if (modifiedPredicate in this.data.slots) { + if ('inverse' in this.data.slots[modifiedPredicate]) { + return this.data.slots[modifiedPredicate].inverse.replace(' ', '_'); + } } } + return undefined; } } \ No newline at end of file