# lawref.evaluator.engine

*module*

Конвейер вычисления: порядок фаз и запуск вектора.

Порядок фаз нормативен и проверяется differential-ом, менять его нельзя:
context [§89.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/13-part-xiii-context-scope-applicability.ru.md#891-named-context-profiles) → ingest [§71](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/11-part-xi-assertions-facts-evidence.ru.md#71-assertion)–[§73](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/11-part-xi-assertions-facts-evidence.ru.md#73-origin) → dynamic references [§30.2](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/07-part-vii-source-and-document-model.ru.md#302-dynamic-reference) → манифест [§170](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/24-part-xxiii-cases-snapshots-evaluation.ru.md#170-evaluation-input-manifest-и-execution-receipt) →
halt E-0001 → [§194](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/27-part-xxvi-static-semantics-and-diagnostics.ru.md#194-sourceprovenance-checks) → стратификация [§110](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#110-stratification) → strict [§103](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#103-strict-closure) → closure [§70](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/10-part-x-propositions-and-four-valued-support.ru.md#70-closed-world-declarations) → strict →
defeasible [§104](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#104-defeasible-candidate)–[§115](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/16-part-xv-defeasible-semantics-and-conflict-resolution.ru.md#115-конфликтный-результат) → цепочка норм [§143](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/19-part-xviii-norm-lifecycle-fulfillment-violation.ru.md#143-chains) → keys [§45.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/08-part-viii-type-system.ru.md#451-relation-keys) → ветвь запроса.

## lawref.evaluator.engine.EvaluationRequest

*class* · *dataclass*

```python
class EvaluationRequest
```

Типизированный единственный вход evaluation (DECISION-0111 [§2.2](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/01-part-i-audit.ru.md#22-четырёхзначной-логики-самой-по-себе-недостаточно)).

Семантические options живут только в ``case["options"]``. Calendar,
external snapshots и receipt — transport-поля запроса и не входят в
caseHash. Неизвестный верхнеуровневый ключ wire-формы отклоняет схема.

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

### lawref.evaluator.engine.EvaluationRequest.calendar_resource

*attribute* · *class attribute* · *instance attribute*

```python
calendar_resource: bytes | None = None
```

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

### lawref.evaluator.engine.EvaluationRequest.case

*attribute* · *instance attribute*

```python
case: dict
```

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

### lawref.evaluator.engine.EvaluationRequest.editions_as_presented

*attribute* · *class attribute* · *instance attribute*

```python
editions_as_presented: str | None = None
```

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

### lawref.evaluator.engine.EvaluationRequest.external_snapshots

*attribute* · *class attribute* · *instance attribute*

```python
external_snapshots: tuple[dict, ...] = field(default_factory=tuple)
```

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

### lawref.evaluator.engine.EvaluationRequest.ir

*attribute* · *instance attribute*

```python
ir: dict
```

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

### lawref.evaluator.engine.EvaluationRequest.proof_graph

*attribute* · *class attribute* · *instance attribute*

```python
proof_graph: bool = True
```

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

### lawref.evaluator.engine.EvaluationRequest.query

*attribute* · *instance attribute*

```python
query: dict
```

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

### lawref.evaluator.engine.EvaluationRequest.receipt

*attribute* · *class attribute* · *instance attribute*

```python
receipt: dict | None = None
```

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

### lawref.evaluator.engine.EvaluationRequest.semantic_version

*attribute* · *class attribute* · *instance attribute*

```python
semantic_version: str = ''
```

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

### lawref.evaluator.engine.EvaluationRequest.build

*method* · *classmethod*

```python
def build(ir: dict, case: dict, query: dict, options: dict | None = None, external_snapshots: list[dict] | tuple[dict, ...] | None = None, *, semantic_version: str | None = None, editions_as_presented: str | None = None) -> 'EvaluationRequest'
```

Собрать typed request из внутренних объектов хоста.

``options`` здесь — лишь адаптер старых хостовых переменных на
единственное нормативное место ``case.options``. Несемантические
calendar/receipt извлекаются из него и в caseHash не попадают.
Если хост не передал версию явно, она наследуется из закреплённого IR.
Отозванная ветвь 0.1 отклоняется по обеим осям: ни IR, ни явная
версия request не могут вернуть её в active evaluation.
Публичная граница исполнения всё равно одна: ``evaluate(request)``.

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

### lawref.evaluator.engine.EvaluationRequest.from_dict

*method* · *classmethod*

```python
def from_dict(document: dict) -> 'EvaluationRequest'
```

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

### lawref.evaluator.engine.EvaluationRequest.from_wire_bytes

*method* · *classmethod*

```python
def from_wire_bytes(raw: bytes) -> 'EvaluationRequest'
```

Build a request from the exact bytes admitted to the verdict cache.

The cache key is safe only when this method itself parsed ``raw`` into
the object passed to validation. Object callers use :meth:`from_dict`.

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

## lawref.evaluator.engine.EvaluationRequestError

*class*

```python
class EvaluationRequestError(ValueError)
```

Bases: `ValueError`

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

### lawref.evaluator.engine.EvaluationRequestError.code

*attribute* · *class attribute* · *instance attribute*

```python
code = 'EVALUATION_REQUEST_INVALID'
```

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

### lawref.evaluator.engine.EvaluationRequestError.message

*attribute* · *instance attribute*

```python
message = EvaluationRequest не соответствует evaluation-request.schema.json: {detail} (DECISION-0111 §2.2)
```

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

## lawref.evaluator.engine.UnsupportedLanguageVersionError

*class*

```python
class UnsupportedLanguageVersionError(EvaluationRequestError)
```

Bases: `lawref.evaluator.engine.EvaluationRequestError`

LDC-E1401 на evaluation boundary для отозванной семантики.

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

### lawref.evaluator.engine.UnsupportedLanguageVersionError.code

*attribute* · *class attribute* · *instance attribute*

```python
code = 'UNSUPPORTED_LANGUAGE_VERSION'
```

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

### lawref.evaluator.engine.UnsupportedLanguageVersionError.diagnostic_code

*attribute* · *class attribute* · *instance attribute*

```python
diagnostic_code = 'LDC-E1401'
```

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

### lawref.evaluator.engine.UnsupportedLanguageVersionError.message

*attribute* · *instance attribute*

```python
message = revision.withdrawn_evaluation_message(version)
```

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

## lawref.evaluator.engine.evaluate

*function*

```python
def evaluate(request: EvaluationRequest) -> dict
```

Публичная граница исполнения (DECISION-0111 [§2.2](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/01-part-i-audit.ru.md#22-четырёхзначной-логики-самой-по-себе-недостаточно)).

Отчёт acceptance-фазы [§78.2.7](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/11-part-xi-assertions-facts-evidence.ru.md#7827-доказательство) вкладывается ЗДЕСЬ, одним владельцем на все
девять ветвей запроса: `_evaluate` кладёт его в `sink`, а `attach_acceptance`
вкладывает и пересчитывает `resultHash`. Без выбранной политики `sink`
пуст и документ возвращается тем же объектом — байты прежние ([§78.2.8](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/11-part-xi-assertions-facts-evidence.ru.md#7828-выбор-политики-идентичность-и-совместимость)).

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

## lawref.evaluator.engine.run_vector

*function*

```python
def run_vector(vector_dir, layer: str | None = None, semantic_version: str | None = None) -> tuple[str, dict]
```

Исполнение evaluate-вектора: ('result', doc) | ('error', {'error': {...}}).

Артефакты: ir.json (hand-authored CLIR до появления парсера M3 — G-M1b
заменит их выходом компилятора), case.json (интерим-JSON вместо .lawcase до
M3), query.json, calendar.resource.json (для calendar_op), expected.json.

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