import { EvaluationError } from "../parser/Evaluator"; import { FZ } from "./Context"; export enum NodeType { ANY = "any", CLAIM = "claim", EVIDENCE = "evidence", PREMISE = "premise", DEFEATER = "defeater", // Not a node type, used for internal parameter resolution on fuzzy symbols __FUZZY = "fuzzy" } // Add a helper namespace to attach utility methods to the enum export namespace NodeType { // Adjacency matrix for typegraph. const typeMatrix: Record> = { "any" : { "any": true, "premise": true, "claim": true, "evidence": true, "defeater": true, "fuzzy": true }, "premise" : { "any": true, "premise": true, "claim": true, "evidence": true, "defeater": false, "fuzzy": false }, "claim" : { "any": false, "premise": false, "claim": true, "evidence": false, "defeater": false, "fuzzy": false }, "evidence" : { "any": false, "premise": false, "evidence": true, "claim": false, "defeater": false, "fuzzy": false }, "defeater" : { "any": false, "premise": false, "claim": false, "evidence": false, "defeater": true, "fuzzy": false } } export function fromString(s: string): NodeType { if (!s) { throw new Error(`Cannot parse NodeType from: ${s}`); } const v = s.trim().toLowerCase(); switch (v) { case "any": case "*": return NodeType.ANY; case "claim": return NodeType.CLAIM; case "evidence": return NodeType.EVIDENCE; case "premise": return NodeType.PREMISE; case "defeater": return NodeType.DEFEATER; case "fuzzy": return NodeType.__FUZZY; default: throw new EvaluationError(`Unknown NodeType string: '${s}'`); } } /** * Checks if a child type is a subtype (inclusive) of the parent type. * * @param parent Parent type * @param child Child type to check for containment within parent type * @return true if child is a sub type of parent, false otherwise */ export function checkSubType(parent: NodeType, child: NodeType): boolean { return typeMatrix[parent.valueOf()][child.valueOf()]; } } export type Node = {id: string, type: NodeType, valuation: FZ}; export type Indicator = {id: string, value: number, valuation: IndicatorCategory} export type IndicatorCategory = {id: string} export type Artifact = {id: string};