Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: post query filter by predicates #12

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
20 changes: 19 additions & 1 deletion src/batch_edge_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -30,6 +31,7 @@ module.exports = class BatchEdgeQueryHandler {
* @private
*/
_expandBTEEdges(bteEdges) {
debug(`BTE EDGE ${JSON.stringify(this.qEdges)}`)
return bteEdges;
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
6 changes: 6 additions & 0 deletions src/query_edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/query_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Loading