generated from kevinxin90/typescript_template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix_issue_109
- Loading branch information
Showing
12 changed files
with
404 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.