From 7d0e2c709fdda09bb333dc5a867be67f6a65eeb3 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Thu, 3 Jun 2021 15:07:57 -0700 Subject: [PATCH 1/2] feat: post query filter by predicates --- .DS_Store | Bin 0 -> 8196 bytes src/batch_edge_query.js | 20 +++++++++++++++++++- src/index.js | 2 +- src/query_graph.js | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3f25085fb67ebf286ca36c8e96362fe4f8351821 GIT binary patch literal 8196 zcmeHM-EPw`6h7WMmUbHyfwW%c28oL?Z47M}2&wBf!6g1f5nKT3lBR4KSu!;#1xitG zcn9DOcod$12jKzWJGNKlr@b9W*pdA?_W6A5&u-I`5|L>1ymg`)5n0HL)ddt268Cd1 zq#50E1t`F${UB<)LFD4TTCg?^MggOMQNSo*6fg?>3ku+w&B>bb+*iG(Gzu66{!0b; z`@u$LtZN)8lwTbvWC#E(p;;!>5A5P<=UBgTEQ?yW5?IG5QP0}b?VSA_ zxtPCCL1D#g`6adDMcSczv`r7`F745MdIVgh6Y_E%SgADcA|315tWp~*59u}h9fEsI zah5A}OLLb}+*m5ngC>)htX`T~o5Ey0J@}952Id}NMsFsL$GWD+Ta>%zf!&fk52^*c zuIvg}Uty(GyNvld(u;#Nci=Thdu2UxBS62*2#dK9z>kx)wVz^UwlsHP-m)rIWvTM2c@*`ViIeo=hSPn) zcaNRq$kp|yQ51~pj{D5-^jp=dJ5iW8e%R?svhQ_Z^76SKdQra-^+GR}<1|%=WtFXR zt6Ccj);HHy?2Vh7!xek5wT1evjm_b(Y%O0~zq5aE^8Ul%7C$<|YloS*)90$s9 f960{N5Oo`-%&BV}DMSmBc@ZFGFojXzTow2OWbQ%$ literal 0 HcmV?d00001 diff --git a/src/batch_edge_query.js b/src/batch_edge_query.js index 488d0528..b227b132 100644 --- a/src/batch_edge_query.js +++ b/src/batch_edge_query.js @@ -3,6 +3,7 @@ const QEdge2BTEEdgeHandler = require('./qedge2bteedge'); const NodesUpdateHandler = require('./update_nodes'); const debug = require('debug')('biothings-explorer-trapi:batch_edge_query'); const CacheHandler = require('./cache_handler'); +const utils = require('./utils'); module.exports = class BatchEdgeQueryHandler { constructor(kg, resolveOutputIDs = true) { @@ -30,6 +31,7 @@ module.exports = class BatchEdgeQueryHandler { * @private */ _expandBTEEdges(bteEdges) { + debug(`BTE EDGE ${JSON.stringify(this.qEdges)}`) return bteEdges; } @@ -47,7 +49,23 @@ module.exports = class BatchEdgeQueryHandler { * @private */ async _postQueryFilter(response) { - return response; + try { + const filtered = response.filter(item => { + let edge_predicate = item['$edge_metadata']['predicate'] + let predicate_filters = item['$edge_metadata']['trapi_qEdge_obj']['qEdge']['predicate'] + //remove prefix from filter list to match predicate name format + predicate_filters = predicate_filters.map(item => utils.removeBioLinkPrefix(item)) + //compare edge predicate to filter list + if (predicate_filters.includes(edge_predicate)) { + return item + } + }); + debug(`Filtered results from ${response.length} down to ${filtered.length} results`); + return filtered + } catch (error) { + debug(`Failed to filter ${response.length} results due to ${error}`); + return response + } } async query(qEdges) { diff --git a/src/index.js b/src/index.js index 29f77388..204fb42b 100644 --- a/src/index.js +++ b/src/index.js @@ -95,7 +95,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { const kg = this._loadMetaKG(this.smartapiID, this.team); debug('metakg successfully loaded'); let queryPaths = this._processQueryGraph(this.queryGraph); - debug(`query paths constructed: ${queryPaths}`); + debug(`query paths constructed: ${JSON.stringify(queryPaths)}`); const handlers = this._createBatchEdgeQueryHandlers(queryPaths, kg); debug(`Query depth is ${Object.keys(handlers).length}`); for (let i = 0; i < Object.keys(handlers).length; i++) { diff --git a/src/query_graph.js b/src/query_graph.js index e96dda2f..af70324e 100644 --- a/src/query_graph.js +++ b/src/query_graph.js @@ -5,6 +5,7 @@ const _ = require('lodash'); const InvalidQueryGraphError = require('./exceptions/invalid_query_graph_error'); const LogEntry = require('./log_entry'); const MAX_DEPTH = 3; +const debug = require('debug')('biothings-explorer-trapi:query_graph'); module.exports = class QueryGraphHandler { constructor(queryGraph) { @@ -106,6 +107,7 @@ module.exports = class QueryGraphHandler { `BTE identified your query graph as a ${Object.keys(paths).length}-depth query graph`, ).getLog(), ); + debug(`ALL PATHS ${JSON.stringify(paths)}`) return paths; } From 774e4f956f521f4cd725322be6bcc50034168494 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Fri, 4 Jun 2021 12:42:53 -0700 Subject: [PATCH 2/2] feat: edge class includes expanded_predicates attribute --- src/query_edge.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/query_edge.js b/src/query_edge.js index d59444d2..dd51bd80 100644 --- a/src/query_edge.js +++ b/src/query_edge.js @@ -14,6 +14,12 @@ module.exports = class QEdge { this.predicate = info.predicates; this.subject = info.subject; this.object = info.object; + this.expanded_predicates = [] + this.init() + } + + init() { + this.expanded_predicates = this.getPredicate() } getID() {