# core/validators/algorithm.reference.validator.ts

> 49 lines of code and 7 definitions.

Tree: GovLab Context
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/context#file-context-core-validators-algorithm-reference-validator-ts
Source text: https://banes-lab.com/source/context/core/validators/algorithm.reference.validator.ts.txt

Listed in [core/validators](https://banes-lab.com/api/source/context/core/validators.md), after [core/validators/algorithm.reason.validator.ts](https://banes-lab.com/source/context/core/validators/algorithm.reason.validator.ts.md) and before [core/validators/algorithm.validator.ts](https://banes-lab.com/source/context/core/validators/algorithm.validator.ts.md).

## Definitions

- `unresolvedGrammarGroundsOf` (lexical_declaration, line 25, exported)
- `ungroundedGatesOf` (lexical_declaration, line 10, exported)
- `ambiguousReasonRefsOf` (lexical_declaration, line 41, exported)
- `id` (lexical_declaration, line 32, exported)
- `kindMembers` (lexical_declaration, line 44, exported)
- `bare` (lexical_declaration, line 47, exported)
- `kinds` (lexical_declaration, line 48, exported)

## Contained in

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

## Uses

- [core/resolvers/reference.resolver.ts](https://banes-lab.com/source/context/core/resolvers/reference.resolver.ts.md)

## Used by

- [core/validators/ontology.validator.ts](https://banes-lab.com/source/context/core/validators/ontology.validator.ts.md)

## Linked from

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

## Source

```typescript
import type { AlgoContractView, GrammarGroundingFaces } from "#types/reference.types";
import {
    DOMAIN_CONCEPT_CATEGORIES,
    GATE_SUFFIX,
    REASON_PREFIX,
    REF_SEPARATOR,
} from "#configuration/constants/reference.constants";
import { bareReasonId, kindRefResolves, kindsHolding } from "#core/resolvers/reference.resolver";

export const ungroundedGatesOf = function ungroundedGatesOf(faces: {
    algo: { all: () => AlgoContractView[] };
}): string[] {
    return faces.algo
        .all()
        .filter(
            (contract) =>
                contract.id.endsWith(GATE_SUFFIX) &&
                !DOMAIN_CONCEPT_CATEGORIES.has(contract.domain) &&
                (contract.grounds ?? []).length === 0,
        )
        .map((contract) => contract.id)
        .toSorted((a, b) => a.localeCompare(b));
};

export const unresolvedGrammarGroundsOf = function unresolvedGrammarGroundsOf(
    faces: GrammarGroundingFaces,
): { from: string; target: string }[] {
    const kindMembers = faces.reason.kindMembers();
    return faces.algo.all().flatMap((contract) =>
        (contract.grounds ?? [])
            .filter((target) => {
                const id = bareReasonId(target);
                return id.includes(REF_SEPARATOR)
                    ? !kindRefResolves(kindMembers, `${REASON_PREFIX}${id}`)
                    : faces.reason.resolve(id) === null;
            })
            .map((target) => ({ from: contract.id, target })),
    );
};

export const ambiguousReasonRefsOf = function ambiguousReasonRefsOf(
    faces: GrammarGroundingFaces,
): { from: string; kinds: string[]; target: string }[] {
    const kindMembers = faces.reason.kindMembers();
    return faces.algo.all().flatMap((contract) =>
        (contract.grounds ?? []).flatMap((target) => {
            const bare = bareReasonId(target);
            const kinds = bare.includes(REF_SEPARATOR) ? [] : kindsHolding(kindMembers, bare);
            return kinds.length > 1 ? [{ from: contract.id, kinds, target }] : [];
        }),
    );
};
```
