# lawref.evaluator.queries

*module*

Ветви запроса: результат и корневой proof-узел на каждый вид query.

Конвейер вычисления (engine) заканчивается общим состоянием — store, proof-
реестр, манифест, позиции; здесь оно превращается в документ [§208](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#208-canonical-serialization). Каждая
ветвь самостоятельна и возвращает готовый документ.

## lawref.evaluator.queries.judgment_declarations

*function*

```python
def judgment_declarations(ir_nodes: list[dict]) -> dict[str, dict]
```

[§47.3](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#473-judgment): judgment-relations программы — id → декларация с `judgment`
{authority, requestSchema?} (DECISION-0024/0036). `external_decl` канала
— носитель органа; сюда он сводится к историческому виду symbol_decl.
Одна таблица на все носители канала (E-0100): тело правила, `valid_when`
[§127](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#127-power), `condition` цели [§123](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#123-duty), условие дефитера [§149](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/20-part-xix-definitions-presumptions-fictions-exceptions.ru.md#149-unless) — и на материализацию
эффектов, где решается, выпускать ли POWER_INVALID_EXERCISE.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L66-L86)

## lawref.evaluator.queries.query_argumentation

*function*

```python
def query_argumentation(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], nodes: list[dict], legal_time: str, limits: dict | None = None) -> dict
```

Профиль [§274.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2741-область-и-вход)–[§274.7](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2747-результат-и-проверяемость) (law.argumentation/0.2, DECISION-0039).

Вид результата — GRAPH: AF целиком в value (аргументы, атаки,
разметки, класс ответа [§274.6](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2746-классы-ответа)); proof graph — пустой корень
`query_evaluation` (профиль объясняет граф value, прецедент [§185](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/26-part-xxv-proof-graph-and-explanations.ru.md#185-why-not)).
Превышение капов [§274.2](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2742-аргументы)/[§274.5](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2745-семантики-af) — fatal RESOURCE_LIMIT без частичного
вывода (дисциплина [§238](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/31-part-xxx-scalability.ru.md#238-resource-limits)).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L377-L434)

## lawref.evaluator.queries.query_calendar_op

*function*

```python
def query_calendar_op(query: dict, query_id: str, snapshot: dict | None, effective: dict, manifest: dict, issues: list[dict], calendar_resource: bytes | None) -> dict
```

Календарная операция над pinned снапшотом — [§85](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/12-part-xii-events-actions-temporal-model.ru.md#85-calendar-snapshot)–[§86](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/12-part-xii-events-actions-temporal-model.ru.md#86-deadline-policy).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L842-L933)

## lawref.evaluator.queries.query_collect

*function*

```python
def query_collect(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], interpretation_dependent: bool | None = None) -> dict
```

Finite relation comprehension [§52.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#521-finite-relation-comprehensions): distinct ground values,
COLLECTION без truth-измерения ([§174.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/25-part-xxiv-queries-and-results.ru.md#1741-result-kinds-и-обязательные-dimensions), T036-контракт).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L446-L526)

## lawref.evaluator.queries.query_formula

*function*

```python
def query_formula(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], term_env: Any = None) -> dict
```

Four-valued status of an arbitrary closed Formula ([§62](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/10-part-x-propositions-and-four-valued-support.ru.md#62-support-pair)).

This internal query is shared by finite counterfactual search.  It reads
the already-computed support store and never rewrites the program, which
keeps external-snapshot program bindings stable.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L18-L63)

## lawref.evaluator.queries.query_interpretation_analysis

*function*

```python
def query_interpretation_analysis(query: dict, query_id: str, ir: dict, case: dict, options: dict, registry: ProofRegistry, manifest: dict, issues: list[dict], nodes: list[dict], evaluate_fn) -> dict
```

Analysis mode [§156](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/21-part-xx-interpretations-and-theories.ru.md#156-evaluation-of-alternatives): каждая alternative указанной exactly_one-группы
вычисляется ОТДЕЛЬНЫМ изолированным прогоном (рекурсивный evaluate с
selectedInterpretations=[alt]) — results_by_interpretation; результаты
не смешиваются по построению. В value — ядро результата каждой
альтернативы; в attributes — resultHash каждого изолированного документа
(детерминированная сцепка [§209](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#209-theory-hash-и-artifact-hash)/[§211](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/29-part-xxviii-compiler-pipeline.ru.md#211-determinism)).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L687-L758)

## lawref.evaluator.queries.query_positions

*function*

```python
def query_positions(query_id: str, registry: ProofRegistry, manifest: dict, issues: list[dict], norm_positions: list[dict], position_supports: dict[str, list[dict]], store: SupportStore | None = None, judgment_decls: dict[str, dict] | None = None, interpretation_dependent: bool | None = None) -> dict
```

NORM_POSITION-результат [§134](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/19-part-xviii-norm-lifecycle-fulfillment-violation.ru.md#134-positioninstance-statuses): summary-статусы позиций
с normativeStatusSupports; сами позиции — top-level документа.

E-0100 ([§47.3](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#473-judgment)/[§123](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#123-duty)/[§124](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#124-goal-types)): `condition` цели, читающее отношение суждения
при паре NEITHER, не решается вычислением — статус позиции остаётся как
есть (ACTIVE), но evaluation status REQUIRES_JUDGMENT и JudgmentRequest
называют, кто решает (`whynot.position_judgment_blockers`).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L529-L600)

## lawref.evaluator.queries.query_precedent

*function*

```python
def query_precedent(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], nodes: list[dict], legal_time: str, limits: dict | None = None) -> dict
```

Профиль [§276.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2761-область-и-вход)–[§276.9](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2769-результат-и-проверяемость) (law.precedent/0.2, DECISION-0090).

Вид результата — GRAPH: статусы прецедентов, связанность и
непротиворечивость базы целиком в value; proof graph — пустой корень
`query_evaluation` (профиль объясняет декларации, а holding исполнил
baseline — прецедент [§274](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#274-structured-argumentation-extension)). Кап [§276.9](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/39-part-xxxvii-open-issues-0-2.ru.md#2769-результат-и-проверяемость) — fatal RESOURCE_LIMIT.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L318-L374)

## lawref.evaluator.queries.query_term

*function*

```python
def query_term(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], env: Any = None) -> dict
```

Data-term вычисление [§57](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/09-part-ix-values-terms-expressions.ru.md#57-equality)–[§58](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/09-part-ix-values-terms-expressions.ru.md#58-arithmetic) (несовместимости [§48](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#48-отсутствие-implicit-conversions)/[§49](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#49-dimensional-checking)/[§50](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#50-money) — T022–T024).

`env` — окружение [§85](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/12-part-xii-events-actions-temporal-model.ru.md#85-calendar-snapshot)/[§86](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/12-part-xii-events-actions-temporal-model.ru.md#86-deadline-policy): term-запрос считает срок тем же
`add_business_days`, что и правило ([§86](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/12-part-xii-events-actions-temporal-model.ru.md#86-deadline-policy)), одним кодом.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L761-L839)

## lawref.evaluator.queries.query_truth

*function*

```python
def query_truth(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], conflict_reports: list[dict], norm_positions: list[dict], blocked_effects: dict[str, dict] | None = None, interpretation_required: bool = False, judgment_decls: dict[str, dict] | None = None, judgment_nodes: list[dict] | None = None, legal_time: str = '', term_env: Any = None) -> dict
```

Truth status ground-литерала — [§62](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/10-part-x-propositions-and-four-valued-support.ru.md#62-support-pair)/[§65](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/10-part-x-propositions-and-four-valued-support.ru.md#65-status-tests); конфликты [§115](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#115-конфликтный-результат) попадают в
результат. Transformation-запрос по эффекту, заблокированному
непобеждённой парой Power/Immunity, — UNRESOLVED_NORMATIVE_CONFLICT [§127](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#127-power).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L133-L239)

## lawref.evaluator.queries.query_weak_permission

*function*

```python
def query_weak_permission(query: dict, query_id: str, registry: ProofRegistry, manifest: dict, issues: list[dict], norm_positions: list[dict], applicable_prohibitions: set[str]) -> dict
```

Weak permission [§126](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#126-weak-permission) — query result, НЕ норма: `weakly_permitted(actor,
action)` истинен только относительно явно выбранной политики (rule
universe; source/time snapshot и interpretation уже пиннуты манифестом).
Без политики отсутствие запрета — MISSING_POLICY («UNDETERMINED, а не
permission»); v1-политика: query.policy == {"ruleUniverse": true} —
правила пакета объявлены полным универсумом применимых запретов.
Запрет: активная позиция с forbearance-goal ([§130](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/18-part-xvii-normative-positions.ru.md#130-prohibition-sugar) prohibition sugar:
канонический CLIR — duty-to-forbear) с bearer=actor и goal.action=action.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L603-L684)

## lawref.evaluator.queries.query_why_not

*function*

```python
def query_why_not(query: dict, query_id: str, store: SupportStore, registry: ProofRegistry, manifest: dict, issues: list[dict], nodes: list[dict], legal_time: str, env=None, excluded: tuple[list[dict], dict[str, str]] | None = None) -> dict
```

[§185](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/26-part-xxv-proof-graph-and-explanations.ru.md#185-why-not) `why_not(P)` — blocker graph по кандидатам-правилам.

Вид результата — `GRAPH` ([§174.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/25-part-xxiv-queries-and-results.ru.md#1741-result-kinds-и-обязательные-dimensions): «graph reference/value; semantic statuses
относятся к его root nodes»), поэтому `truthStatus` корня — статус самой
цели: спрашивающий видит и то, ЧТО получилось, и то, что этому помешало.

Blocker graph лежит в `value`, а не в proof graph: proof доказывает ОТВЕТ,
а здесь доказывать нечего — вывод не получен. Попытка выдать кандидатов
узлами `rule_application` была отвергнута Lean-ядром, и по делу: [§180](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/26-part-xxv-proof-graph-and-explanations.ru.md#180-rule-application-proof)
требует от такого узла `rule` и `substitution`, которых у несработавшего
правила нет. Словарь `ApplicabilityStatus`/`TriggerStatus` [§174.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/25-part-xxiv-queries-and-results.ru.md#1741-result-kinds-и-обязательные-dimensions) при этом
сохранён — он лежит у каждого кандидата внутри value.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/evaluator/queries.py#L242-L315)
