# domain/converters/reason.fragment.converter.ts

> 189 lines of code and 9 definitions.

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

## Definitions

- `mathSection` (lexical_declaration, line 97, exported)
- `lensSection` (lexical_declaration, line 124, exported)
- `surfaceSection` (lexical_declaration, line 164, exported)
- `modelSection` (lexical_declaration, line 190, exported)
- `surfaceSubsection` (lexical_declaration, line 134)
- `lensSubsection` (lexical_declaration, line 107)
- `mathTypeSubsection` (lexical_declaration, line 73)
- `mathDomainSubsection` (lexical_declaration, line 89)
- `modelSubsection` (lexical_declaration, line 174)

## Uses

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

## Used by

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

## Source

```typescript
import {
    CONTRACTS_LABEL,
    DOMAIN_LABEL,
    FIELD_SEPARATOR,
    FLOW_ARROW,
    INVARIANT_LABEL,
} from "#configuration/strings/ontology.strings";
import {
    DETECTORS_LABEL,
    DIMENSION_LABEL,
    EVIDENCE_GROUNDS_LABEL,
    EVIDENCE_LABEL,
    FAILURE_MODES_LABEL,
    FIELDS_LABEL,
    LENS_INTRO,
    LENS_LABEL,
    LENS_TITLE,
    MATH_INTRO,
    MATH_TITLE,
    MODEL_INTRO,
    MODEL_TITLE,
    NATURE_LABEL,
    OPTIONAL_LABEL,
    PREDICATE_FAMILY_LABEL,
    PREDICATE_GROUNDS_LABEL,
    PREDICATE_TITLE,
    QUESTION_LABEL,
    RECURSION_LABEL,
    REQUIRED_LABEL,
    SEQUENCE_TITLE,
    STUDIES_LABEL,
    SURFACES_LABEL,
    SURFACE_INTRO,
    SURFACE_TITLE,
    TECHNIQUES_LABEL,
    TEST_SURFACES_LABEL,
    UNIVERSAL_AXIS_LABEL,
    VERDICTS_LABEL,
    YIELDS_SHAPE_LABEL,
} from "#configuration/strings/reason.strings";
import {
    LENS_SECTION_ID,
    MATH_SECTION_ID,
    MODEL_SECTION_ID,
    REASON_ANCHOR,
    SURFACE_SECTION_ID,
} from "#core/ids/ontology.ids";
import type {
    LensView,
    MathDomainView,
    MathTypeView,
    ModelView,
    ReasonView,
    TestSurfaceView,
} from "#types/reason.types";
import type { Section, Subsection } from "#types/document.types";
import {
    chips,
    codeOf,
    fields,
    glossary,
    labelled,
    linkList,
    linkOf,
    linkRow,
    linked,
    plainList,
    row,
} from "#domain/converters/ontology.converter";
import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons";
import { TEXT_LANGUAGE } from "#configuration/constants/code.constants";

const mathTypeSubsection = function mathTypeSubsection(mathType: MathTypeView): Subsection {
    return {
        blocks: [
            chips([linked(DOMAIN_LABEL, mathType.domain)]),
            glossary([
                row(QUESTION_LABEL, mathType.question),
                row(PREDICATE_FAMILY_LABEL, mathType.predicateFamily),
                row(YIELDS_SHAPE_LABEL, mathType.yieldsShape),
                ...linkRow(CONTRACTS_LABEL, mathType.contracts),
            ]),
        ],
        id: REASON_ANCHOR + mathType.anchor,
        title: mathType.id,
    };
};

const mathDomainSubsection = function mathDomainSubsection(domain: MathDomainView): Subsection {
    return {
        blocks: [glossary([row(STUDIES_LABEL, domain.studies), row(QUESTION_LABEL, domain.question)])],
        id: REASON_ANCHOR + domain.anchor,
        title: domain.id,
    };
};

export const mathSection = function mathSection(reason: ReasonView): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: MATH_SECTION_ID,
        intro: MATH_INTRO,
        subsections: [...reason.mathTypes.map(mathTypeSubsection), ...reason.mathDomains.map(mathDomainSubsection)],
        title: MATH_TITLE,
    };
};

const lensSubsection = function lensSubsection(lens: LensView): Subsection {
    return {
        blocks: [
            chips([labelled(NATURE_LABEL, lens.nature), linked(UNIVERSAL_AXIS_LABEL, lens.universalAxis)]),
            glossary([
                row(QUESTION_LABEL, lens.question),
                row(FIELDS_LABEL, linkList(lens.mathFields)),
                row(SURFACES_LABEL, plainList(lens.surfaces)),
                row(DETECTORS_LABEL, linkList(lens.detectedBy)),
                ...linkRow(TEST_SURFACES_LABEL, lens.testSurfaces),
            ]),
        ],
        id: REASON_ANCHOR + lens.anchor,
        title: lens.id,
    };
};

export const lensSection = function lensSection(reason: ReasonView): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: LENS_SECTION_ID,
        intro: LENS_INTRO,
        subsections: reason.lenses.map(lensSubsection),
        title: LENS_TITLE,
    };
};

const surfaceSubsection = function surfaceSubsection(surface: TestSurfaceView): Subsection {
    return {
        blocks: [
            chips([
                linked(DIMENSION_LABEL, surface.dimension),
                linked(LENS_LABEL, surface.lens),
                linked(INVARIANT_LABEL, surface.invariant),
            ]),
            glossary([
                row(FAILURE_MODES_LABEL, plainList(surface.failureModes)),
                row(TECHNIQUES_LABEL, linkList(surface.techniques)),
                ...linkRow(PREDICATE_GROUNDS_LABEL, surface.predicateGrounds),
                row(
                    EVIDENCE_LABEL,
                    fields([surface.evidenceSource, surface.evidenceRequired ? REQUIRED_LABEL : OPTIONAL_LABEL]),
                ),
                ...linkRow(EVIDENCE_GROUNDS_LABEL, surface.evidenceGrounds),
                row(VERDICTS_LABEL, plainList(surface.verdictDomain)),
            ]),
            codeOf(
                PREDICATE_TITLE + FIELD_SEPARATOR + surface.predicateType,
                surface.predicateExpression,
                TEXT_LANGUAGE,
            ),
        ],
        id: REASON_ANCHOR + surface.anchor,
        title: surface.id,
    };
};

export const surfaceSection = function surfaceSection(reason: ReasonView): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: SURFACE_SECTION_ID,
        intro: SURFACE_INTRO,
        subsections: reason.testSurfaces.map(surfaceSubsection),
        title: SURFACE_TITLE,
    };
};

const modelSubsection = function modelSubsection(model: ModelView): Subsection {
    return {
        blocks: [
            chips([
                labelled(QUESTION_LABEL, model.question),
                model.recursionFrom === null || model.recursionTo === null
                    ? null
                    : labelled(RECURSION_LABEL, model.recursionFrom + FLOW_ARROW + model.recursionTo),
            ]),
            glossary([row(SEQUENCE_TITLE, model.sequence.map(linkOf).join(FLOW_ARROW))]),
        ],
        id: REASON_ANCHOR + model.anchor,
        title: model.id,
    };
};

export const modelSection = function modelSection(reason: ReasonView): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: MODEL_SECTION_ID,
        intro: MODEL_INTRO,
        subsections: reason.models.map(modelSubsection),
        title: MODEL_TITLE,
    };
};
```
