# lawref.measure

*module*

Документ меры формализации `law.formalization-measure/0.1` — оракул [§33.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/07-part-vii-source-and-document-model.ru.md#331-formalization-coverage).

Errata E-0249 (DECISION-0383): мера глубины считается против единиц деления
закреплённой публикации, уровни, которых реализация не вычисляет, названы,
`EXECUTABLE` единицы — утверждение о наличии выводящего узла, а не о полноте,
свежесть входов — часть отчёта. Документ канонизируется [§208](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#208-canonical-serialization) и сравнивается
байтово с крейтом `law-measure` (`lawc measure`) — differential ОТДЕЛЬНОГО
документа меры, evaluation-документ не затрагивается.

Что здесь НЕ решается: правовые вопросы. Текст режется объявленной либо
распознанной конвенцией из `spec/unit-conventions.json` (один файл на обе
реализации), CLIR читается структурно — fragment/locator, anchors, виды узлов,
принадлежность прочтению [§152](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/21-part-xx-interpretations-and-theories.ru.md#152-interpretation).

> **Вход**
>
> document     — CLIR (dict);
> texts        — список {"bytes": bytes, "declaration": dict} — закреплённые
>                публикации: текст сопоставляется узлу `publication` по
>                sha256 точных байтов (`documentHash` [§27.3](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/07-part-vii-source-and-document-model.ru.md#273-publication)), не по имени;
> params       — {"profile": {"name", "aggregatedMinBytes"},
>                 "attestation": {"origin": "sources"|"file", "contentHash"?}}.

Выход — dict документа; `canonical_measure_bytes` даёт байты [§208](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#208-canonical-serialization).

## lawref.measure.ALGORITHM

*attribute* · *module attribute*

```python
ALGORITHM = 'formalization/1'
```

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

## lawref.measure.DEFAULT_PROFILE

*attribute* · *module attribute*

```python
DEFAULT_PROFILE = {'name': 'static', 'aggregatedMinBytes': 2000}
```

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

## lawref.measure.DERIVING_KINDS

*attribute* · *module attribute*

```python
DERIVING_KINDS = frozenset({'rule', 'priority_rule', 'closure_policy', 'norm_template', 'constraint'})
```

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

## lawref.measure.EXTERNAL_ANCHOR_RE

*attribute* · *module attribute*

```python
EXTERNAL_ANCHOR_RE = re.compile('(?:ART-|ART)(\\d+(?:[-_]\\d+)?)(?:_P\\d+)?(?:_(?:RU|KK))?$')
```

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

## lawref.measure.FORMAT

*attribute* · *module attribute*

```python
FORMAT = 'law.formalization-measure/0.1'
```

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

## lawref.measure.LEVELS_COMPUTED

*attribute* · *module attribute*

```python
LEVELS_COMPUTED = ('SOURCE_ONLY', 'ANCHORED', 'EXECUTABLE')
```

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

## lawref.measure.LEVELS_NOT_COMPUTED

*attribute* · *module attribute*

```python
LEVELS_NOT_COMPUTED = ('STRUCTURED', 'SEMANTIC')
```

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

## lawref.measure.SPEC

*attribute* · *module attribute*

```python
SPEC = '0.1+E-0249'
```

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

## lawref.measure.MeasureError

*class*

```python
class MeasureError(Exception)
```

Bases: `Exception`

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

## lawref.measure.canonical_measure_bytes

*function*

```python
def canonical_measure_bytes(measure_document: dict) -> bytes
```

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

## lawref.measure.conventions

*function* · *cached*

```python
def conventions() -> dict
```

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

## lawref.measure.main

*function*

```python
def main(argv: list[str]) -> int
```

python -m lawref measure <ir.json> --text <файл> [--declaration <json>] [--params <json>]

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

## lawref.measure.measure

*function*

```python
def measure(document: dict, texts: list[dict], params: dict | None = None) -> dict
```

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

## lawref.measure.sha256

*function*

```python
def sha256(data: bytes) -> str
```

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