Skip to content
Draft
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
31 changes: 22 additions & 9 deletions src/framework/graph-visualiser/graph.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
Attribute, AttributeType, Concept, ConceptRow, ConceptRowsQueryResponse, Entity, EntityType, getVariableName,
InstantiableType, QueryConstraintAny, QueryConstraintComparison, QueryConstraintExpression, QueryConstraintFunction,
AnalyzedPipeline, Attribute, AttributeType, Concept, ConceptRow, ConceptRowsQueryResponse,
Entity, EntityType, getVariableName, InstantiableType,
QueryConstraintAny, QueryConstraintComparison, QueryConstraintExpression, QueryConstraintFunction,
QueryConstraintHas, QueryConstraintIid, QueryConstraintIs, QueryConstraintIsa, QueryConstraintIsaExact, QueryConstraintKind,
QueryConstraintLabel, QueryConstraintLinks, QueryConstraintOwns, QueryConstraintPlays, QueryConstraintRelates,
QueryConstraintSpan, QueryConstraintSub, QueryConstraintSubExact, QueryConstraintValue, QueryStructure, QueryVertex,
Relation, RelationType, RoleType, ThingKind, Type, TypeKind, Value, ValueKind
Relation, RelationType, RoleType, ThingKind, Type, TypeKind, Value, ValueKind,
ConceptRowsQueryResponseForStudio, QueryStuctureForStudio
} from "typedb-driver-http";
import {MultiGraph} from "graphology";

type BackwardsCompatiblePipeline = QueryStructureForStudio | AnalyzedPipeline;
type BackwardsCompatibleConceptRowsResponse = ConceptRowsQueryResponse | ConceptRowsQueryResponseForStudio;
///////////////////////
// TypeDB Data Graph //
///////////////////////
Expand Down Expand Up @@ -138,7 +142,7 @@ export interface DataConstraintExpression {

text: string,
arguments: (Entity | Relation | Attribute | Value | VertexUnavailable)[],
assigned: (Entity | Relation | Attribute | Value | VertexUnavailable)[],
assigned: (Entity | Relation | Attribute | Value | VertexUnavailable),
}

export interface DataConstraintFunction {
Expand Down Expand Up @@ -262,11 +266,12 @@ class LogicalGraphBuilder {
constructor() {
}

build(rows_result: ConceptRowsQueryResponse): DataGraph {
build(rows_result: BackwardsCompatibleConceptRowsResponse): DataGraph {
let answers: DataConstraintAny[][] = [];
const blocks = backwardsCompatibility_getBlocks(rows_result.query!);
rows_result.answers.forEach((row, answerIndex) => {
let current_answer_edges = row.involvedBlocks.flatMap(branchIndex => {
return rows_result.query!.blocks[branchIndex].constraints.map((constraint, constraintIndex) => {
return blocks[branchIndex].constraints.map((constraint, constraintIndex) => {
return this.toDataConstraint(rows_result.query!, answerIndex, constraint, row.data, {
branch: branchIndex,
constraint: constraintIndex
Expand All @@ -278,7 +283,7 @@ class LogicalGraphBuilder {
return {answers: answers};
}

translate_vertex(structure: QueryStructure, structure_vertex: QueryVertex, answerIndex: number, data: ConceptRow): DataVertex {
translate_vertex(structure: BackwardsCompatiblePipeline, structure_vertex: QueryVertex, answerIndex: number, data: ConceptRow): DataVertex {
switch (structure_vertex.tag) {
case "variable": {
let name = getVariableName(structure, structure_vertex);
Expand All @@ -302,10 +307,13 @@ class LogicalGraphBuilder {
case "value": {
return structure_vertex.value;
}
case "namedRole": {
return structure_vertex.name;
}
}
}

private toDataConstraint(structure: QueryStructure, answerIndex: number, constraint: QueryConstraintAny, data: ConceptRow, coordinates: QueryCoordinates): DataConstraintAny {
private toDataConstraint(structure: BackwardsCompatiblePipeline, answerIndex: number, constraint: QueryConstraintAny, data: ConceptRow, coordinates: QueryCoordinates): DataConstraintAny {
switch (constraint.tag) {
case "isa": {
return {
Expand Down Expand Up @@ -408,6 +416,7 @@ class LogicalGraphBuilder {
}
}
case "expression": {
const assigned_vertex = Array.isArray(constraint.assigned) ? constraint.assigned[0] : constraint.assigned;
return {
tag: "expression",
textSpan: constraint.textSpan,
Expand All @@ -416,7 +425,7 @@ class LogicalGraphBuilder {

text: constraint.text,
arguments: constraint.arguments.map(vertex => this.translate_vertex(structure, vertex, answerIndex, data) as (Entity | Relation | Attribute | Value | VertexUnavailable)),
assigned: constraint.assigned.map(vertex => this.translate_vertex(structure, vertex, answerIndex, data) as (Entity | Relation | Attribute | Value | VertexUnavailable)),
assigned: this.translate_vertex(structure, assigned_vertex, answerIndex, data) as (Entity | Relation | Attribute | Value | VertexUnavailable),
}
}
case "functionCall": {
Expand Down Expand Up @@ -501,3 +510,7 @@ class LogicalGraphBuilder {
}
}
}

function backwardsCompatibility_getBlocks(pipeline: AnalyzedPipeline | QueryStructure | QueryStructureForStudio): AnalyzedConjunction[] | Analyz {
return pipeline.conjunctions != undefined ? pipeline.conjunctions : pipeline.blocks;
}