From 69c105d42d7662dbf4f9d05368b4731904aa33d3 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Thu, 30 Sep 2021 15:41:02 -0700 Subject: [PATCH 1/7] fix: :sparkles: result annotation includes input ids as well --- src/query.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/query.js b/src/query.js index 89f0adf..e487432 100644 --- a/src/query.js +++ b/src/query.js @@ -140,30 +140,61 @@ module.exports = class APIQueryDispathcer { if (item && item.$edge_metadata) { const output_type = item.$edge_metadata.output_type; if (!(output_type in output_ids)) { - output_ids[output_type] = []; + output_ids[output_type] = new Set(); } - output_ids[output_type].push(item.$output.original); + output_ids[output_type].add(item.$output.original); } - }) + }); + for (const key in output_ids) { + output_ids[key] = [...output_ids[key]]; + } return output_ids; } + _groupIDsBySemanticType(result) { + const ids = {}; + result.map(item => { + if (item && item.$edge_metadata) { + //INPUTS + const input_type = item.$edge_metadata.input_type; + if (!(input_type in ids)) { + ids[input_type] = new Set(); + } + ids[input_type].add(item.$input.original); + // OUTPUTS + const output_type = item.$edge_metadata.output_type; + if (!(output_type in ids)) { + ids[output_type] = new Set(); + } + ids[output_type].add(item.$output.original); + } + }); + for (const key in ids) { + ids[key] = [...ids[key]]; + } + return ids; + } + /** * Add equivalent ids to all output using biomedical-id-resolver service */ async _annotate(result, enable = true) { - const grpedIDs = this._groupOutputIDsBySemanticType(result); + // const grpedIDs = this._groupOutputIDsBySemanticType(result); + const groupedIDs = this._groupIDsBySemanticType(result); + debug(`GROUPED IDS ${JSON.stringify(groupedIDs)}`); let res; if (enable === false) { - res = resolver.generateInvalidBioentities(grpedIDs); + res = resolver.generateInvalidBioentities(groupedIDs); } else { // const biomedical_resolver = new resolver.Resolver("biolink"); // res = await biomedical_resolver.resolve(grpedIDs); - res = await resolver.resolveSRI(grpedIDs); + res = await resolver.resolveSRI(groupedIDs); } + // debug(`RESULT ${JSON.stringify(res)}`); result.map(item => { if (item && item !== undefined) { item.$output.obj = res[item.$output.original]; + item.$input.obj = res[item.$input.original]; } }); return result; From ace5a85fd675c42e99f9366db61753986b289a7f Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Tue, 5 Oct 2021 09:44:20 -0700 Subject: [PATCH 2/7] fix: :sparkles: remove redundant debug logs --- src/query.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/query.js b/src/query.js index e487432..4f8b494 100644 --- a/src/query.js +++ b/src/query.js @@ -179,18 +179,13 @@ module.exports = class APIQueryDispathcer { * Add equivalent ids to all output using biomedical-id-resolver service */ async _annotate(result, enable = true) { - // const grpedIDs = this._groupOutputIDsBySemanticType(result); const groupedIDs = this._groupIDsBySemanticType(result); - debug(`GROUPED IDS ${JSON.stringify(groupedIDs)}`); let res; if (enable === false) { res = resolver.generateInvalidBioentities(groupedIDs); } else { - // const biomedical_resolver = new resolver.Resolver("biolink"); - // res = await biomedical_resolver.resolve(grpedIDs); res = await resolver.resolveSRI(groupedIDs); } - // debug(`RESULT ${JSON.stringify(res)}`); result.map(item => { if (item && item !== undefined) { item.$output.obj = res[item.$output.original]; From c20167a8fb4b98a309772eefbe445ee5fa9664e2 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Tue, 19 Oct 2021 16:45:12 -0700 Subject: [PATCH 3/7] fix: :sparkles: call get Attrs in parallel to resolve SRI --- package.json | 2 +- src/query.js | 17 ++++++++++++++++- tsconfig.json | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 120000 tsconfig.json diff --git a/package.json b/package.json index 6244ea8..c63c913 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "homepage": "https://github.com/biothings/call-apis.js#readme", "dependencies": { "@biothings-explorer/api-response-transform": "^1.12.0", - "biomedical_id_resolver": "^3.10.0", "axios": "^0.21.1", + "biomedical_id_resolver": "^3.10.0", "debug": "^4.3.1", "husky": "^4.3.8", "nunjucks": "^3.2.3" diff --git a/src/query.js b/src/query.js index 22ef8ef..1f48aa9 100644 --- a/src/query.js +++ b/src/query.js @@ -24,6 +24,8 @@ module.exports = class APIQueryDispathcer { constructor(edges) { this.edges = edges; this.logs = []; + this.biolink = new biolink.BioLink(); + this.biolink.loadSync(); } async _queryBucket(queries) { @@ -195,21 +197,34 @@ module.exports = class APIQueryDispathcer { } /** - * Add equivalent ids to all output using biomedical-id-resolver service + * Add equivalent ids to all entities using biomedical-id-resolver service */ async _annotate(result, enable = true) { const groupedIDs = this._groupIDsBySemanticType(result); let res; + let attributes; if (enable === false) { res = resolver.generateInvalidBioentities(groupedIDs); + attributes = await resolver.getAttributes(groupedIDs); } else { res = await resolver.resolveSRI(groupedIDs); + attributes = await resolver.getAttributes(groupedIDs); + debug(`Attributes retrieved ${JSON.stringify(attributes)}`); } result.map(item => { if (item && item !== undefined) { item.$output.obj = res[item.$output.original]; item.$input.obj = res[item.$input.original]; } + //add attributes + if (attributes && Object.hasOwnProperty.call(attributes, item.$input.original)) { + debug(`(I) Attributes added to ${item.$input.original}`); + item.$input.obj[0]['attributes'] = attributes[item.$input.original] + } + if (attributes && Object.hasOwnProperty.call(attributes, item.$output.original)) { + debug(`(O) Attributes added to ${item.$output.original}`); + item.$output.obj[0]['attributes'] = attributes[item.$output.original] + } }); return result; } diff --git a/tsconfig.json b/tsconfig.json new file mode 120000 index 0000000..0354cd0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1 @@ +../../../scripts/tsconfig.json_call-apis \ No newline at end of file From c372df612697abb90e45cf74f6de58bd0ae01db7 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Wed, 20 Oct 2021 08:23:38 -0700 Subject: [PATCH 4/7] fix: remove unused biolink mention, remove logs --- src/query.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/query.js b/src/query.js index 1f48aa9..ff3ff7c 100644 --- a/src/query.js +++ b/src/query.js @@ -24,8 +24,6 @@ module.exports = class APIQueryDispathcer { constructor(edges) { this.edges = edges; this.logs = []; - this.biolink = new biolink.BioLink(); - this.biolink.loadSync(); } async _queryBucket(queries) { @@ -218,11 +216,9 @@ module.exports = class APIQueryDispathcer { } //add attributes if (attributes && Object.hasOwnProperty.call(attributes, item.$input.original)) { - debug(`(I) Attributes added to ${item.$input.original}`); item.$input.obj[0]['attributes'] = attributes[item.$input.original] } if (attributes && Object.hasOwnProperty.call(attributes, item.$output.original)) { - debug(`(O) Attributes added to ${item.$output.original}`); item.$output.obj[0]['attributes'] = attributes[item.$output.original] } }); From 88e19224996cc30b3a29d04796ae6160e9efe2e5 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Mon, 1 Nov 2021 13:30:34 -0700 Subject: [PATCH 5/7] fix: :sparkles: check undefined before attempting to assign attributes --- src/query.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/query.js b/src/query.js index ff3ff7c..7040a1e 100644 --- a/src/query.js +++ b/src/query.js @@ -215,10 +215,10 @@ module.exports = class APIQueryDispathcer { item.$input.obj = res[item.$input.original]; } //add attributes - if (attributes && Object.hasOwnProperty.call(attributes, item.$input.original)) { + if (attributes && item && Object.hasOwnProperty.call(attributes, item.$input.original)) { item.$input.obj[0]['attributes'] = attributes[item.$input.original] } - if (attributes && Object.hasOwnProperty.call(attributes, item.$output.original)) { + if (attributes && item && Object.hasOwnProperty.call(attributes, item.$output.original)) { item.$output.obj[0]['attributes'] = attributes[item.$output.original] } }); From cdfc29306becc16f39e76960a041593591492531 Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Wed, 3 Nov 2021 07:24:36 -0700 Subject: [PATCH 6/7] fix: comment out debug log --- src/query.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query.js b/src/query.js index 7040a1e..6f3e5c9 100644 --- a/src/query.js +++ b/src/query.js @@ -207,7 +207,7 @@ module.exports = class APIQueryDispathcer { } else { res = await resolver.resolveSRI(groupedIDs); attributes = await resolver.getAttributes(groupedIDs); - debug(`Attributes retrieved ${JSON.stringify(attributes)}`); + // debug(`Attributes retrieved ${JSON.stringify(attributes)}`); } result.map(item => { if (item && item !== undefined) { From 71609c0ef67b7baf6e426a9dfbbe9b2677ea78ee Mon Sep 17 00:00:00 2001 From: Marco Cano Date: Wed, 3 Nov 2021 07:25:36 -0700 Subject: [PATCH 7/7] Delete tsconfig.json --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) delete mode 120000 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 120000 index 0354cd0..0000000 --- a/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../../scripts/tsconfig.json_call-apis \ No newline at end of file