# core/selectors/lexicon.selector.ts

> 37 lines of code and 10 definitions.

Tree: GovLab Context
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/context#file-context-core-selectors-lexicon-selector-ts
Source text: https://banes-lab.com/source/context/core/selectors/lexicon.selector.ts.txt

Listed in [core/selectors](https://banes-lab.com/api/source/context/core/selectors.md), after [core/selectors/grammar.selector.ts](https://banes-lab.com/source/context/core/selectors/grammar.selector.ts.md) and before [core/selectors/pattern.selector.ts](https://banes-lab.com/source/context/core/selectors/pattern.selector.ts.md).

## Definitions

- `folderOfTerm` (lexical_declaration, line 25, exported)
- `tagOfTerm` (lexical_declaration, line 11, exported)
- `isMirrored` (lexical_declaration, line 33, exported)
- `statesPlacement` (lexical_declaration, line 37, exported)
- `statesRefusal` (lexical_declaration, line 41, exported)
- `filedFolderOf` (lexical_declaration, line 15)
- `opening` (lexical_declaration, line 16)
- `rest` (lexical_declaration, line 20)
- `close` (lexical_declaration, line 21)
- `filed` (lexical_declaration, line 26, exported)

## Contained in

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

## Used by

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

## Linked from

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

## Source

```typescript
import {
    FILED_OPENINGS,
    FOLDER_CLOSE,
    MIRRORED_CLAUSE,
    REFUSAL_OPENING,
    SAME_NAME_CLAUSES,
    TAG_SUFFIX,
} from "#configuration/constants/lexicon.constants";
import type { Term } from "#types/lexicon.types";

export const tagOfTerm = function tagOfTerm(term: Term): string | null {
    return term.id.endsWith(TAG_SUFFIX) ? term.id.slice(0, -TAG_SUFFIX.length) : null;
};

const filedFolderOf = function filedFolderOf(definition: string): string | null {
    const opening = FILED_OPENINGS.find((candidate) => definition.includes(candidate));
    if (opening === undefined) {
        return null;
    }
    const rest = definition.slice(definition.indexOf(opening) + opening.length);
    const close = rest.indexOf(FOLDER_CLOSE);
    return close > 0 ? rest.slice(0, close) : null;
};

export const folderOfTerm = function folderOfTerm(term: Term): string | null {
    const filed = filedFolderOf(term.definition);
    if (filed !== null) {
        return filed;
    }
    return SAME_NAME_CLAUSES.some((clause) => term.definition.includes(clause)) ? tagOfTerm(term) : null;
};

export const isMirrored = function isMirrored(term: Term): boolean {
    return term.definition.includes(MIRRORED_CLAUSE);
};

export const statesPlacement = function statesPlacement(term: Term): boolean {
    return tagOfTerm(term) !== null && (folderOfTerm(term) !== null || isMirrored(term));
};

export const statesRefusal = function statesRefusal(term: Term): boolean {
    return term.definition.startsWith(REFUSAL_OPENING);
};
```
