# core/converters/taxonomy.converter.ts

> 39 lines of code and 5 definitions.

Tree: GovLab Stats
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/stats#file-stats-core-converters-taxonomy-converter-ts
Source text: https://banes-lab.com/source/stats/core/converters/taxonomy.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/stats/core/converters.md), after [core/converters/metric.converter.ts](https://banes-lab.com/source/stats/core/converters/metric.converter.ts.md).

## Definitions

- `row` (lexical_declaration, line 13)
- `usedOf` (lexical_declaration, line 4)
- `vocabularyRows` (lexical_declaration, line 17, exported)
- `used` (lexical_declaration, line 9)
- `tags` (lexical_declaration, line 22, exported)

## Contained in

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

## Used by

- [core/analyzers/taxonomy.analyzer.ts](https://banes-lab.com/source/stats/core/analyzers/taxonomy.analyzer.ts.md)

## Linked from

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

## Source

```typescript
import type { RootScan, VocabularyStat } from "#types/taxonomy.types";
import type { Vocabulary } from "@ssot/govlab/types/taxonomy.types.ts";

const usedOf = function usedOf(
    declared: ReadonlySet<string>,
    scans: readonly RootScan[],
    pick: (scan: RootScan) => ReadonlySet<string>,
): number {
    const used = new Set(scans.flatMap((scan) => [...pick(scan)]));
    return [...declared].filter((word) => used.has(word)).length;
};

const row = function row(name: string, declared: number, used: number): VocabularyStat {
    return { declared, name, unused: Math.max(0, declared - used), used };
};

export const vocabularyRows = function vocabularyRows(
    host: Vocabulary,
    scans: readonly RootScan[],
    containers: { declared: number; layers: number; layerTotals: ReadonlyMap<string, number>; present: number },
): VocabularyStat[] {
    const tags = new Set(host.byTag.keys());
    return [
        row(
            "concern tags",
            tags.size,
            usedOf(tags, scans, (scan) => scan.usedConcerns),
        ),
        row(
            "subjects",
            host.subjects.size,
            usedOf(host.subjects, scans, (scan) => scan.usedSubjects),
        ),
        row(
            "variants",
            host.variants.size,
            usedOf(host.variants, scans, (scan) => scan.usedVariants),
        ),
        row("containers", containers.declared, containers.present),
        row("layers", containers.layers, [...containers.layerTotals.values()].filter((count) => count > 0).length),
    ];
};
```
