# core/converters/finding.tree.converter.ts

> 36 lines of code and 4 definitions.

Tree: GovLab Patterns
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/patterns#file-patterns-core-converters-finding-tree-converter-ts
Source text: https://banes-lab.com/source/patterns/core/converters/finding.tree.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/patterns/core/converters.md), after [core/converters/finding.sequence.converter.ts](https://banes-lab.com/source/patterns/core/converters/finding.sequence.converter.ts.md) and before [core/converters/finding.vector.converter.ts](https://banes-lab.com/source/patterns/core/converters/finding.vector.converter.ts.md).

## Definitions

- `treeFindings` (lexical_declaration, line 11, exported)
- `labeled` (lexical_declaration, line 7)
- `composition` (lexical_declaration, line 12, exported)
- `structure` (lexical_declaration, line 22, exported)

## Contained in

- [core/converters](https://banes-lab.com/anatomy/patterns/folder-patterns-core-converters.md)

## Uses

- [core/converters/finding.converter.ts](https://banes-lab.com/source/patterns/core/converters/finding.converter.ts.md)

## Used by

- [core/plugins/representation.tree.plugin.ts](https://banes-lab.com/source/patterns/core/plugins/representation.tree.plugin.ts.md)

## Linked from

- [core/converters](https://banes-lab.com/anatomy/patterns/folder-patterns-core-converters.md)
- [core/plugins](https://banes-lab.com/anatomy/patterns/folder-patterns-core-plugins.md)

## Source

```typescript
import type { Finding } from "#types/finding.types";
import { TREE_STRINGS } from "#configuration/strings/representation.strings";
import type { TreeSummary } from "#types/representation.types";
import { explanationFinding } from "#core/factories/finding.factory";
import { withSupport } from "#core/converters/finding.converter";

const labeled = function labeled(rows: readonly [string, number][], key: string): Readonly<Record<string, unknown>>[] {
    return rows.map(([name, count]) => ({ [key]: name, count }));
};

export const treeFindings = function treeFindings(field: string, summary: TreeSummary): Finding[] {
    const composition = explanationFinding({
        analysis: "structure",
        explained: TREE_STRINGS.compositionExplained,
        field,
        name: "composition",
        observation: { keys: labeled(summary.keys, "key"), leafTypes: labeled(summary.leafTypes, "type") },
        observed: TREE_STRINGS.compositionObserved(String(summary.keys.length), String(summary.totalLeaves)),
        ontology: "composition",
        representation: "symbolic",
    });
    const structure = explanationFinding({
        analysis: "structure",
        explained: TREE_STRINGS.structureExplained(String(summary.distinctShapes), String(summary.records)),
        field,
        name: "structure",
        observation: {
            distinctShapes: summary.distinctShapes,
            maxBranching: summary.maxBranching,
            maxDepth: summary.maxDepth,
            paths: labeled(summary.paths, "path"),
        },
        observed: TREE_STRINGS.structureObserved(String(summary.maxDepth), String(summary.maxBranching)),
        ontology: "structure",
        representation: "topology",
    });
    return withSupport([composition, structure], summary.records);
};
```
