Defined known edge types

This commit is contained in:
Chegele 2023-09-13 07:06:21 -04:00
parent a4daf1c3e0
commit 42bf560f9f
5 changed files with 68 additions and 7 deletions

View File

@ -1,12 +1,13 @@
import { Node } from "../node-types/abstract-node"; import { Node } from "../node-types/abstract-node";
export abstract class EDGE { export abstract class Edge {
public static readonly EDGE_TYPE: string; public static readonly EDGE_TYPE: string;
public static readonly SOURCE_TYPES: string[]; public static readonly SOURCE_TYPES: string[];
public static readonly REFERENCE_TYPES: string[]; public static readonly REFERENCE_TYPES: string[];
public static readonly RELATIONSHIP: string;
public readonly source: Node; public readonly source: Node;
public readonly reference: Node; public readonly reference: Node;
@ -16,12 +17,14 @@ export abstract class EDGE {
} }
public static nodesCompatible(source: Node, reference: Node): boolean { public static nodesCompatible(source: Node, reference: Node): boolean {
if (!this.SOURCE_TYPES.includes(source.TYPE)) return false; const sourceClass = source.constructor as typeof Node;
if (!this.REFERENCE_TYPES.includes(reference.TYPE)) return false; const referenceClass = reference.constructor as typeof Node;
if (!this.SOURCE_TYPES.includes(sourceClass.TYPE)) return false;
if (!this.REFERENCE_TYPES.includes(referenceClass.TYPE)) return false;
return true; return true;
} }
public static createEdge(source: Node, reference: Node): EDGE { public static createEdge(source: Node, reference: Node): Edge {
throw new Error('You must override the static createEdge method in specific edge implementations'); throw new Error('You must override the static createEdge method in specific edge implementations');
} }

View File

@ -0,0 +1,19 @@
import { Node } from "../node-types/abstract-node";
import { Edge } from "./abstract-edge";
export class GenerateEdge extends Edge {
public static readonly EDGE_TYPE = "generate";
public static readonly SOURCE_TYPES = ["claim", "evidence"];
public static readonly REFERENCE_TYPES = ['question'];
public static readonly RELATIONSHIP = "generated-by";
constructor(source: Node, reference: Node) {
super(source, reference);
}
public static createEdge(source: Node, reference: Node) {
return new GenerateEdge(source, reference);
}
}

View File

@ -1,12 +1,13 @@
import { Node } from "../node-types/abstract-node"; import { Node } from "../node-types/abstract-node";
import { EDGE } from "./abstract-edge"; import { Edge } from "./abstract-edge";
export class InformEdge extends EDGE { export class InformEdge extends Edge {
public static readonly EDGE_TYPE = "inform"; public static readonly EDGE_TYPE = "inform";
public static readonly SOURCE_TYPES = ["claim", "evidence"]; public static readonly SOURCE_TYPES = ["claim", "evidence"];
public static readonly REFERENCE_TYPES = ['question']; public static readonly REFERENCE_TYPES = ['question'];
public static readonly RELATIONSHIP = "informed-by";
constructor(source: Node, reference: Node) { constructor(source: Node, reference: Node) {
super(source, reference); super(source, reference);

19
src/edge-types/oppose.ts Normal file
View File

@ -0,0 +1,19 @@
import { Node } from "../node-types/abstract-node";
import { Edge } from "./abstract-edge";
export class OpposeEdge extends Edge {
public static readonly EDGE_TYPE = "oppose";
public static readonly SOURCE_TYPES = ["claim", "evidence"];
public static readonly REFERENCE_TYPES = ['claim'];
public static readonly RELATIONSHIP = "opposed-by";
constructor(source: Node, reference: Node) {
super(source, reference);
}
public static createEdge(source: Node, reference: Node) {
return new OpposeEdge(source, reference);
}
}

19
src/edge-types/support.ts Normal file
View File

@ -0,0 +1,19 @@
import { Node } from "../node-types/abstract-node";
import { Edge } from "./abstract-edge";
export class SupportEdge extends Edge {
public static readonly EDGE_TYPE = "support";
public static readonly SOURCE_TYPES = ["claim", "evidence"];
public static readonly REFERENCE_TYPES = ['claim'];
public static readonly RELATIONSHIP = "supported-by";
constructor(source: Node, reference: Node) {
super(source, reference);
}
public static createEdge(source: Node, reference: Node) {
return new SupportEdge(source, reference);
}
}