Skip to content

Commit

Permalink
Merge branch 'main' into fix_issue_109
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinxin90 authored Mar 24, 2021
2 parents 41b31d7 + ffd5013 commit a9343fa
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 372 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.0.1](https://github.com/kevinxin90/bte_trapi_query_graph_handler/compare/v0.8.0...v1.0.1) (2021-03-24)

## [1.0.0](https://github.com/kevinxin90/bte_trapi_query_graph_handler/compare/v0.7.0...v1.0.0) (2021-03-23)


### Features

* :sparkles: support query graph with explain type of query ([2d767fd](https://github.com/kevinxin90/bte_trapi_query_graph_handler/commit/2d767fd67d04c8956e3d55c2438def12b79ec104))

## [1.0.0](https://github.com/kevinxin90/bte_trapi_query_graph_handler/compare/v0.7.0...v1.0.0) (2021-03-23)

### Features

* :sparkles: support query graph with explain type of query ([2d767fd](https://github.com/kevinxin90/bte_trapi_query_graph_handler/commit/2d767fd67d04c8956e3d55c2438def12b79ec104))

## [0.8.0](https://github.com/kevinxin90/bte_trapi_query_graph_handler/compare/v0.7.0...v0.8.0) (2021-03-23)


### Features

* :sparkles: add chemicalsubstance node when user specify drug as output ([ffb81b3](https://github.com/kevinxin90/bte_trapi_query_graph_handler/commit/ffb81b3f9397bd325ca38f3242f5cd110c03b288))

## [0.7.0](https://github.com/kevinxin90/bte_trapi_query_graph_handler/compare/v0.6.0...v0.7.0) (2021-03-18)


Expand Down
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biothings-explorer/query_graph_handler",
"version": "0.7.0",
"version": "1.0.1",
"description": "A nodejs module to query TRAPI Query Graph",
"main": "built/index.js",
"scripts": {
Expand Down Expand Up @@ -36,17 +36,17 @@
"homepage": "https://github.com/kevinxin90/bte_trapi_query_graph_handler#readme",
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.33",
"@types/jest": "^26.0.21",
"@types/node": "^14.14.35",
"coveralls": "^3.1.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"redis-mock": "^0.56.3",
"standard-version": "^9.1.0",
"ts-jest": "^26.5.3",
"ts-jest": "^26.5.4",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.20.30",
"typedoc": "^0.20.33",
"typescript": "^4.2.3"
},
"dependencies": {
Expand Down
172 changes: 86 additions & 86 deletions src/graph/graph.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
const kg_edge = require("./kg_edge");
const kg_node = require("./kg_node");
const helper = require("../helper");
const kg_edge = require('./kg_edge');
const kg_node = require('./kg_node');
const helper = require('../helper');

module.exports = class Graph {
constructor() {
this.nodes = {};
this.edges = {};
this.paths = {};
this.helper = new helper();
this.subscribers = [];
}
constructor() {
this.nodes = {};
this.edges = {};
this.paths = {};
this.helper = new helper();
this.subscribers = [];
}

update(queryResult) {
const bteAttributes = ['name', 'label', 'id', 'api', 'provided_by', 'publications'];
queryResult.map((record) => {
const inputPrimaryID = this.helper._getInputID(record);
const inputQGID = this.helper._getInputQueryNodeID(record);
const inputID = inputPrimaryID + '-' + inputQGID;
const outputPrimaryID = this.helper._getOutputID(record);
const outputQGID = this.helper._getOutputQueryNodeID(record);
const outputID = outputPrimaryID + '-' + outputQGID;
const edgeID = this.helper._getKGEdgeID(record);
if (!(outputID in this.nodes)) {
this.nodes[outputID] = new kg_node(outputID, {
primaryID: outputPrimaryID,
qgID: outputQGID,
equivalentIDs: this.helper._getOutputEquivalentIds(record),
label: this.helper._getOutputLabel(record),
category: this.helper._getOutputCategory(record),
nodeAttributes: this.helper._getOutputAttributes(record)
})
}
if (!(inputID in this.nodes)) {
this.nodes[inputID] = new kg_node(inputID, {
primaryID: inputPrimaryID,
qgID: inputQGID,
equivalentIDs: this.helper._getInputEquivalentIds(record),
label: this.helper._getInputLabel(record),
category: this.helper._getInputCategory(record),
nodeAttributes: this.helper._getInputAttributes(record)
})
}
this.nodes[outputID].addSourceNode(inputID);
this.nodes[outputID].addSourceQGNode(inputQGID);
this.nodes[inputID].addTargetNode(outputID);
this.nodes[inputID].addTargetQGNode(outputQGID);
if (!(edgeID in this.edges)) {
this.edges[edgeID] = new kg_edge(edgeID, {
predicate: this.helper._getPredicate(record),
subject: inputPrimaryID,
object: outputPrimaryID
})
}
this.edges[edgeID].addAPI(this.helper._getAPI(record));
this.edges[edgeID].addSource(this.helper._getSource(record));
this.edges[edgeID].addPublication(this.helper._getPublication(record));
Object.keys(record)
.filter((k) => !(bteAttributes.includes(k) || k.startsWith('$')))
.map((item) => {
this.edges[edgeID].addAdditionalAttributes(item, record[item]);
});
})
}
update(queryResult) {
const bteAttributes = ['name', 'label', 'id', 'api', 'provided_by', 'publications'];
queryResult.map((record) => {
const inputPrimaryID = this.helper._getInputID(record);
const inputQGID = this.helper._getInputQueryNodeID(record);
const inputID = inputPrimaryID + '-' + inputQGID;
const outputPrimaryID = this.helper._getOutputID(record);
const outputQGID = this.helper._getOutputQueryNodeID(record);
const outputID = outputPrimaryID + '-' + outputQGID;
const edgeID = this.helper._getKGEdgeID(record);
if (!(outputID in this.nodes)) {
this.nodes[outputID] = new kg_node(outputID, {
primaryID: outputPrimaryID,
qgID: outputQGID,
equivalentIDs: this.helper._getOutputEquivalentIds(record),
label: this.helper._getOutputLabel(record),
category: this.helper._getOutputCategory(record),
nodeAttributes: this.helper._getOutputAttributes(record),
});
}
if (!(inputID in this.nodes)) {
this.nodes[inputID] = new kg_node(inputID, {
primaryID: inputPrimaryID,
qgID: inputQGID,
equivalentIDs: this.helper._getInputEquivalentIds(record),
label: this.helper._getInputLabel(record),
category: this.helper._getInputCategory(record),
nodeAttributes: this.helper._getInputAttributes(record),
});
}
this.nodes[outputID].addSourceNode(inputID);
this.nodes[outputID].addSourceQGNode(inputQGID);
this.nodes[inputID].addTargetNode(outputID);
this.nodes[inputID].addTargetQGNode(outputQGID);
if (!(edgeID in this.edges)) {
this.edges[edgeID] = new kg_edge(edgeID, {
predicate: this.helper._getPredicate(record),
subject: inputPrimaryID,
object: outputPrimaryID,
});
}
this.edges[edgeID].addAPI(this.helper._getAPI(record));
this.edges[edgeID].addSource(this.helper._getSource(record));
this.edges[edgeID].addPublication(this.helper._getPublication(record));
Object.keys(record)
.filter((k) => !(bteAttributes.includes(k) || k.startsWith('$')))
.map((item) => {
this.edges[edgeID].addAdditionalAttributes(item, record[item]);
});
});
}

/**
/**
* Register subscribers
* @param {object} subscriber
*/
subscribe(subscriber) {
this.subscribers.push(subscriber);
}
subscribe(subscriber) {
this.subscribers.push(subscriber);
}

/**
* Unsubscribe a listener
* @param {object} subscriber
*/
unsubscribe(subscriber) {
this.subscribers = this.subscribers.filter((fn) => {
if (fn != subscriber) return fn;
});
}
/**
* Unsubscribe a listener
* @param {object} subscriber
*/
unsubscribe(subscriber) {
this.subscribers = this.subscribers.filter((fn) => {
if (fn != subscriber) return fn;
});
}

/**
* Nofity all listeners
*/
notify() {
this.subscribers.map((subscriber) => {
subscriber.update({
nodes: this.nodes,
edges: this.edges
});
});
}
}
/**
* Nofity all listeners
*/
notify() {
this.subscribers.map((subscriber) => {
subscriber.update({
nodes: this.nodes,
edges: this.edges,
});
});
}
};
Loading

0 comments on commit a9343fa

Please sign in to comment.