Skip to content

Commit

Permalink
concat support graph edge bindings with normal edges
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Mar 5, 2024
1 parent a725635 commit da5978d
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/pages/answer/useAnswerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,33 @@ export default function useAnswerStore() {
const edges = {};
const edgesJSON = {};
row.analyses.forEach((analysis) => {
Object.values(analysis.edge_bindings).forEach((edgeBindings) => {
edgeBindings.forEach((binding) => {
const kgEdge = message.knowledge_graph.edges[binding.id];
edgesJSON[binding.id] = kgEdge || 'Unknown';
if (kgEdge) {
const graphEdge = {
id: binding.id,
source: kgEdge.subject,
target: kgEdge.object,
predicate: kgEdge.predicate,
};
edges[binding.id] = graphEdge;
if (kgEdge.subject in nodes) {
nodes[kgEdge.subject].score += 1;
}
if (kgEdge.object in nodes) {
nodes[kgEdge.object].score += 1;
}
const subjectNode = message.knowledge_graph.nodes[kgEdge.subject];
const objectNode = message.knowledge_graph.nodes[kgEdge.object];
const edgeKey = `${subjectNode.name || kgEdge.subject} ${stringUtils.displayPredicate(kgEdge.predicate)} ${objectNode.name || kgEdge.object}`;
publications[edgeKey] = resultsUtils.getPublications(kgEdge);
const edge_bindings = Object.values(analysis.edge_bindings)[0] || [];
const support_graph_edge_bindings = analysis.support_graphs.reduce((acc, support_graph_id) => (
[...acc, ...message.auxiliary_graphs[support_graph_id].edges.map((e) => ({ id: e }))]
), []);

[...edge_bindings, ...support_graph_edge_bindings].forEach((binding) => {
const kgEdge = message.knowledge_graph.edges[binding.id];
edgesJSON[binding.id] = kgEdge || 'Unknown';
if (kgEdge) {
const graphEdge = {
id: binding.id,
source: kgEdge.subject,
target: kgEdge.object,
predicate: kgEdge.predicate,
};
edges[binding.id] = graphEdge;
if (kgEdge.subject in nodes) {
nodes[kgEdge.subject].score += 1;
}
if (kgEdge.object in nodes) {
nodes[kgEdge.object].score += 1;
}
});
const subjectNode = message.knowledge_graph.nodes[kgEdge.subject];
const objectNode = message.knowledge_graph.nodes[kgEdge.object];
const edgeKey = `${subjectNode.name || kgEdge.subject} ${stringUtils.displayPredicate(kgEdge.predicate)} ${objectNode.name || kgEdge.object}`;
publications[edgeKey] = resultsUtils.getPublications(kgEdge);
}
});
});

Expand Down

0 comments on commit da5978d

Please sign in to comment.