diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..3f25085f Binary files /dev/null and b/.DS_Store differ 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_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() { 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; }