# lawref.query

*module*

LawQL — детерминированные запросы к CLIR как к данным.

Пакет намеренно не входит в семантический путь evaluator: структурный слой
только реифицирует уже построенный CLIR, а материализации вызывают существующий
`lawref.evaluator.evaluate` явно.

## lawref.query.FactStore

*class* · *dataclass*

```python
class FactStore
```

Re-exported from: `lawref.query.facts`

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

### lawref.query.FactStore.documents

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

```python
documents: list[dict] = field(default_factory=list)
```

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

### lawref.query.FactStore.enabled_relations

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

```python
enabled_relations: set[str] = field(default_factory=lambda : set(RELATION_FIELDS))
```

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

### lawref.query.FactStore.node_count

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

```python
node_count: int = 0
```

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

### lawref.query.FactStore.node_kinds

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

```python
node_kinds: tuple[str, ...] = field(default_factory=schema_node_kinds)
```

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

### lawref.query.FactStore.relations

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

```python
relations: dict[str, list[dict]] = field(default_factory=lambda : {name: [] for name in RELATION_FIELDS})
```

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

### lawref.query.FactStore.add_document

*method*

```python
def add_document(document: dict, path: Path, law_path: str | None = None) -> None
```

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

### lawref.query.FactStore.document

*method*

```python
def document(package: str) -> dict | None
```

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

### lawref.query.FactStore.finalize

*method*

```python
def finalize() -> None
```

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

### lawref.query.FactStore.node

*method*

```python
def node(node_id: str) -> dict | None
```

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

### lawref.query.FactStore.rows

*method*

```python
def rows(relation: str, package_glob: str = '*') -> list[dict]
```

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

### lawref.query.FactStore.schema

*method*

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

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

## lawref.query.QueryEngine

*class*

```python
class QueryEngine
```

Re-exported from: `lawref.query.engine`

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

### lawref.query.QueryEngine.base_path

*attribute* · *instance attribute*

```python
base_path = base_path or Path.cwd().resolve()
```

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

### lawref.query.QueryEngine.materialization_engine

*attribute* · *instance attribute*

```python
materialization_engine = materialization_engine
```

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

### lawref.query.QueryEngine.materialization_limit

*attribute* · *instance attribute*

```python
materialization_limit = materialization_limit
```

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

### lawref.query.QueryEngine.materializations

*attribute* · *instance attribute*

```python
materializations: dict[str, dict] = {}
```

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

### lawref.query.QueryEngine.store

*attribute* · *instance attribute*

```python
store = store
```

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

### lawref.query.QueryEngine.warnings

*attribute* · *instance attribute*

```python
warnings: list[dict] = []
```

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

### lawref.query.QueryEngine.execute

*method*

```python
def execute(query: Query) -> QueryResult
```

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

## lawref.query.QueryError

*class* · *dataclass*

```python
class QueryError(ValueError)
```

Bases: `ValueError`

Re-exported from: `lawref.query.errors`

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

### lawref.query.QueryError.code

*attribute* · *instance attribute*

```python
code: str
```

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

### lawref.query.QueryError.column

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

```python
column: int | None = None
```

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

### lawref.query.QueryError.hints

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

```python
hints: tuple[str, ...] = ()
```

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

### lawref.query.QueryError.line

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

```python
line: int | None = None
```

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

### lawref.query.QueryError.message

*attribute* · *instance attribute*

```python
message: str
```

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

## lawref.query.QueryResult

*class* · *dataclass*

```python
class QueryResult
```

Re-exported from: `lawref.query.engine`

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

### lawref.query.QueryResult.document

*attribute* · *instance attribute*

```python
document: dict
```

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

### lawref.query.QueryResult.explain

*attribute* · *instance attribute*

```python
explain: dict
```

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

## lawref.query.load_corpus

*function*

```python
def load_corpus(paths: Iterable[Path] | None = None, package_glob: str = '*', relations: Iterable[str] | None = None, package_globs: Iterable[str] | None = None, include_law_paths: bool = True, documents: Iterable[tuple[Path | str, dict]] | None = None) -> FactStore
```

Re-exported from: `lawref.query.facts`

Снимок корпуса в FactStore.

Два входа, взаимоисключающие: `paths` — файлы CLIR (по умолчанию весь
`corpus/clir`), `documents` — пары (путь, уже разобранный CLIR) от хоста,
который держит корпус в памяти (каталог MCP: те же документы, сверенные по
stat за миллисекунды, вместо второго чтения и разбора 184 МБ на каждый
вызов). Путь при документе нужен ровно тем, чем и при файле: порядком
обхода (первый в канонической сортировке — единственный снимок пакета) и
полем `path` строк фактов; байты результата от входа не зависят — это
держит `check_query.py`. Документы не копируются и не мутируются: строки
фактов ссылаются на их узлы, поэтому хост обязан отдавать их разделяемыми
и неизменяемыми (у каталога MCP это уже контракт corpus_snapshot).

Глоб пакета применяется ДО разбора, когда путь известен: имя подглядывается
в байтах (`peek_package_name`), и файл вне глоба не разбирается вовсе.
Следствие, названное честно: испорченный CLIR ВНЕ глоба запрос больше не
роняет — его целостность держат ворота компилятора, а не LawQL.

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

## lawref.query.main

*function*

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

Re-exported from: `lawref.query.cli`

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

## lawref.query.parse

*function*

```python
def parse(source: str) -> Query | InferenceQuery
```

Re-exported from: `lawref.query.parser`

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

**Modules**

- `lawref.query.cli`
- `lawref.query.engine`
- `lawref.query.errors`
- `lawref.query.facts`
- `lawref.query.inference`
- `lawref.query.materialize`
- `lawref.query.parser`
