domain/converters/reason.converter.ts
domain/converters/reason.converter.ts is a file in Bane's Lab Site. 118 lines of code and 4 definitions.
import {
ANSWER_LABEL,
AXES_INTRO,
AXES_LABEL,
AXES_TITLE,
CONCEPT_LABEL,
DECISION_LABEL,
MANDATORY_LABEL,
NODES_LABEL,
NODE_INTRO,
NODE_TITLE,
QUESTION_LABEL,
REASON_LAYER_INTRO,
REASON_LAYER_TITLE,
ROLE_LABEL,
SELECTABLE_LABEL,
} from "#configuration/strings/reason.strings";
import { AXES_SECTION_ID, NODE_SECTION_ID, REASON_LAYER_SECTION_ID } from "#core/ids/ontology.ids";
import {
AXIS_LABEL,
CONTRACTS_LABEL,
GROUNDED_BY_LABEL,
LAYER_LABEL,
MATH_TYPE_LABEL,
NO_LABEL,
YES_LABEL,
} from "#configuration/strings/ontology.strings";
import type { AxisView, ReasonNodeView } from "#types/loop.types";
import type { Section, Subsection } from "#types/document.types";
import { chips, glossary, labeled, linkRow, linked, row } from "#domain/converters/ontology.converter";
import { loopSection, substrateSection } from "#domain/converters/loop.converter";
import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons";
import type { ReasonView } from "#types/reason.types";
import type { ResolutionView } from "#types/ontology.types";
import { reasonRecord } from "#domain/converters/reason.fragment.converter";
const layerSection = function layerSection(reason: ReasonView, resolution: ResolutionView): Section {
return {
icon: REASON_SECTION_ICON,
id: REASON_LAYER_SECTION_ID,
intro: REASON_LAYER_INTRO,
subsections: reason.layers.map((layer) =>
reasonRecord(
layer.anchor,
layer.label,
[glossary([row(QUESTION_LABEL, layer.question), ...linkRow(AXES_LABEL, layer.axes)])],
resolution,
),
),
title: REASON_LAYER_TITLE,
};
};
const axisSubsection = function axisSubsection(axis: AxisView, resolution: ResolutionView): Subsection {
return reasonRecord(
axis.anchor,
axis.id,
[
chips([
linked(LAYER_LABEL, axis.layer),
labeled(MANDATORY_LABEL, axis.mandatory),
linked(MATH_TYPE_LABEL, axis.primaryMathType),
labeled(SELECTABLE_LABEL, axis.selectable ? YES_LABEL : NO_LABEL),
]),
glossary([
row(QUESTION_LABEL, axis.question),
...linkRow(NODES_LABEL, axis.nodes),
...linkRow(CONTRACTS_LABEL, axis.contracts),
]),
],
resolution,
);
};
const nodeSubsection = function nodeSubsection(entry: ReasonNodeView, resolution: ResolutionView): Subsection {
return reasonRecord(
entry.anchor,
entry.name,
[
chips([
linked(AXIS_LABEL, entry.axis),
linked(MATH_TYPE_LABEL, entry.mathType),
linked(CONCEPT_LABEL, entry.concept),
]),
glossary(
[
entry.question === null ? [] : [row(QUESTION_LABEL, entry.question)],
entry.answerShape === null ? [] : [row(ANSWER_LABEL, entry.answerShape)],
entry.decisionTest === null ? [] : [row(DECISION_LABEL, entry.decisionTest)],
entry.role === null ? [] : [row(ROLE_LABEL, entry.role)],
linkRow(GROUNDED_BY_LABEL, entry.groundedBy),
].flat(),
),
],
resolution,
);
};
export const spineSections = function spineSections(
reason: ReasonView,
resolution: ResolutionView,
): readonly Section[] {
return [
loopSection(reason, resolution),
substrateSection(reason, resolution),
layerSection(reason, resolution),
{
icon: REASON_SECTION_ICON,
id: AXES_SECTION_ID,
intro: AXES_INTRO,
subsections: reason.axes.map((axis) => axisSubsection(axis, resolution)),
title: AXES_TITLE,
},
{
icon: REASON_SECTION_ICON,
id: NODE_SECTION_ID,
intro: NODE_INTRO,
subsections: reason.nodes.map((entry) => nodeSubsection(entry, resolution)),
title: NODE_TITLE,
},
];
};