# domain/converters/reason.converter.ts

> 108 lines of code and 4 definitions.

Tree: Site tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/tree#file-domain-converters-reason-converter-ts
Source text: https://banes-lab.com/assets/sources/source.f5c474daeec5dbe892c2e7c74eacf0bd65032ffdd7abf68d2a732c19b6931f24.generated.txt

## Definitions

- `layerSection` (lexical_declaration, line 35)
- `spineSections` (lexical_declaration, line 92, exported)
- `axisSubsection` (lexical_declaration, line 49)
- `nodeSubsection` (lexical_declaration, line 69)

## Uses

- [domain/converters/loop.converter.ts](https://banes-lab.com/source/tree/domain/converters/loop.converter.ts.md)
- [domain/converters/ontology.converter.ts](https://banes-lab.com/source/tree/domain/converters/ontology.converter.ts.md)

## Source

```typescript
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_ANCHOR, 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, labelled, 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";

const layerSection = function layerSection(reason: ReasonView): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: REASON_LAYER_SECTION_ID,
        intro: REASON_LAYER_INTRO,
        subsections: reason.layers.map((layer) => ({
            blocks: [glossary([row(QUESTION_LABEL, layer.question), ...linkRow(AXES_LABEL, layer.axes)])],
            id: REASON_ANCHOR + layer.anchor,
            title: layer.label,
        })),
        title: REASON_LAYER_TITLE,
    };
};

const axisSubsection = function axisSubsection(axis: AxisView): Subsection {
    return {
        blocks: [
            chips([
                linked(LAYER_LABEL, axis.layer),
                labelled(MANDATORY_LABEL, axis.mandatory),
                linked(MATH_TYPE_LABEL, axis.primaryMathType),
                labelled(SELECTABLE_LABEL, axis.selectable ? YES_LABEL : NO_LABEL),
            ]),
            glossary([
                row(QUESTION_LABEL, axis.question),
                ...linkRow(NODES_LABEL, axis.nodes),
                ...linkRow(CONTRACTS_LABEL, axis.contracts),
            ]),
        ],
        id: REASON_ANCHOR + axis.anchor,
        title: axis.id,
    };
};

const nodeSubsection = function nodeSubsection(entry: ReasonNodeView): Subsection {
    return {
        blocks: [
            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(),
            ),
        ],
        id: REASON_ANCHOR + entry.anchor,
        title: entry.id,
    };
};

export const spineSections = function spineSections(reason: ReasonView): readonly Section[] {
    return [
        loopSection(reason),
        substrateSection(reason),
        layerSection(reason),
        {
            icon: REASON_SECTION_ICON,
            id: AXES_SECTION_ID,
            intro: AXES_INTRO,
            subsections: reason.axes.map(axisSubsection),
            title: AXES_TITLE,
        },
        {
            icon: REASON_SECTION_ICON,
            id: NODE_SECTION_ID,
            intro: NODE_INTRO,
            subsections: reason.nodes.map(nodeSubsection),
            title: NODE_TITLE,
        },
    ];
};
```
