# types/ontology.types.ts

> 57 lines of code and 11 definitions.

Tree: GovLab Context
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/context#file-context-types-ontology-types-ts
Source text: https://banes-lab.com/source/context/types/ontology.types.ts.txt

Listed in [types](https://banes-lab.com/api/source/context/types.md), after [types/lexicon.types.ts](https://banes-lab.com/source/context/types/lexicon.types.ts.md) and before [types/reason.concept.types.ts](https://banes-lab.com/source/context/types/reason.concept.types.ts.md).

## Definitions

- `Logger` (interface_declaration, line 4, exported)
- `OntologyIssues` (interface_declaration, line 8, exported)
- `Edge` (interface_declaration, line 13, exported)
- `Ontology` (interface_declaration, line 18, exported)
- `OntologyOptions` (interface_declaration, line 27, exported)
- `OntologyAudit` (interface_declaration, line 34, exported)
- `BaseFaceConfig` (interface_declaration, line 39, exported)
- `FaceContext` (interface_declaration, line 47, exported)
- `OntologyFaceDefinition` (interface_declaration, line 52, exported)
- `JsonDirOptions` (interface_declaration, line 58, exported)
- `Normalizer` (type_alias_declaration, line 63, exported)

## Contained in

- [types](https://banes-lab.com/anatomy/context/folder-context-types.md)

## Source

```typescript
import type { CheckFacet } from "#types/check.types";
import type { UnreadKey } from "#types/record.types";

export interface Logger {
    warn: (message: string, detail?: unknown) => void;
}

export interface OntologyIssues {
    duplicateIds: string[];
    danglingEdges: { from: string; relation: string; target: string }[];
}

export interface Edge {
    relation: string;
    targets: string[];
}

export interface Ontology<R> {
    get: (id: string) => R | null;
    all: () => R[];
    ids: () => string[];
    query: (matcher: (record: R) => boolean) => R[];
    index: () => ReadonlyMap<string, R>;
    validateOntology: (edgesOf: (record: R) => Edge[], resolveId?: (target: string) => string) => OntologyIssues;
}

export interface OntologyOptions<R> {
    records: readonly R[];
    idOf: (record: R) => string;
    label: string;
    logger?: Logger | undefined;
}

export interface OntologyAudit {
    attributions: () => string[];
    unread: () => UnreadKey[];
}

export interface BaseFaceConfig<R, F> {
    audit: OntologyAudit;
    idOf: (record: R) => string;
    label: string;
    matches: (record: R, filter: F) => boolean;
    logger?: Logger | undefined;
}

export interface FaceContext {
    logger?: Logger | undefined;
    canonicalizeId?: ((term: string) => string) | undefined;
}

export interface OntologyFaceDefinition<P = unknown> {
    name: string;
    dependsOn?: readonly string[];
    build: (context: FaceContext, dependencies: Record<string, unknown>) => P;
}

export interface JsonDirOptions {
    only?: (name: string) => boolean;
    exclude?: (name: string) => boolean;
}

export type Normalizer<R> = (
    raw: Record<string, unknown>,
    category: string,
    declared: CheckFacet | null,
    group: Record<string, unknown>,
) => R;
```
