# domain/converters/lexicon.converter.ts

> 47 lines of code and 3 definitions.

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

## Definitions

- `termSubsection` (lexical_declaration, line 17, exported)
- `categorySection` (lexical_declaration, line 38)
- `lexiconSections` (lexical_declaration, line 48, exported)

## Uses

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

## Source

```typescript
import {
    ALIASES_LABEL,
    CATEGORY_LABEL,
    CONTRACT_LABEL,
    KIND_LABEL,
    LAYER_LABEL,
    PRINCIPLE_LABEL,
    REFERENCED_BY_LABEL,
} from "#configuration/strings/ontology.strings";
import { DEFINITION_LABEL, LEXICON_INTRO } from "#configuration/strings/lexicon.strings";
import { LEX_ANCHOR, LEX_CATEGORY_ANCHOR } from "#core/ids/ontology.ids";
import type { Section, Subsection } from "#types/document.types";
import type { TermCategoryView, TermView } from "#types/ontology.types";
import { chips, glossary, linkRow, linked, plainList, row } from "#domain/converters/ontology.converter";
import { ONTOLOGY_LEXICON_ICON } from "#configuration/icons/ontology.icons";

export const termSubsection = function termSubsection(term: TermView): Subsection {
    return {
        blocks: [
            chips([
                linked(KIND_LABEL, term.kind),
                linked(CATEGORY_LABEL, term.category),
                linked(LAYER_LABEL, term.layer),
            ]),
            glossary([
                row(DEFINITION_LABEL, term.definition),
                ...(term.aliases.length === 0 ? [] : [row(ALIASES_LABEL, plainList(term.aliases))]),
                ...linkRow(PRINCIPLE_LABEL, term.principle === null ? [] : [term.principle]),
                ...linkRow(CONTRACT_LABEL, term.contract === null ? [] : [term.contract]),
                ...linkRow(REFERENCED_BY_LABEL, term.referencedBy),
            ]),
        ],
        id: LEX_ANCHOR + term.id,
        title: term.name,
    };
};

const categorySection = function categorySection(group: TermCategoryView): Section {
    return {
        icon: ONTOLOGY_LEXICON_ICON,
        id: LEX_CATEGORY_ANCHOR + group.id,
        intro: LEXICON_INTRO,
        subsections: [...group.terms].sort((a, b) => a.name.localeCompare(b.name)).map(termSubsection),
        title: group.category,
    };
};

export const lexiconSections = function lexiconSections(groups: readonly TermCategoryView[]): readonly Section[] {
    return [...groups].sort((a, b) => a.category.localeCompare(b.category)).map(categorySection);
};
```
