Skip to content

lawref.population_bind

population-binding/0.1 — эталон материализации таблиц микроданных в пакет-дело §168.4 (DECISION-0264, трек О).

Оркестрация без семантики (инвариант CLAUDE.md №5): адаптер ничего не вычисляет и не выводит из права. Каждая ячейка источника становится литералом факта дела origin case_input по объявленному в привязке типу, каждая строка корневой таблицы — делом и строкой банка. Результат детерминирован и не зависит от порядка строк во входных файлах: дела пишутся в байтовом порядке имён, факты — в порядке записей привязки и ключей дочерних строк, строки манифеста — в порядке rowId.

Поток (все отказы операции — до записи, §8 решения):

USAGE флаги (--binding, --clir, --out)
→ каталог --out не существует (POPULATION_BIND_OUT_EXISTS)
→ привязка: схема, самопин, структура (POPULATION_BINDING_INVALID)
→ класс данных synthetic (POPULATION_BINDING_DATA_CLASS)
→ CLIR модели: semanticHash, предикаты,
арность, типы, перечисления, сущности (POPULATION_BINDING_MODEL_MISMATCH)
→ таблицы: файл, закрытое подмножество CSV [§3](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/02-part-ii-goals-and-scope.ru.md#3-цели-law-dsl-core-01), ключи, сироты,
дубликаты rowId и имён дел (POPULATION_SOURCE_INVALID)
→ дело каждой корневой строки: rowId → имя → вес → дата → факты;
сбой значения — отказ строки в манифест (ROW_*), не исчезновение
→ пакет (law.toml, package.law, cases/*.lawcase) и манифест
law.population.materialization/0.1 (канон [§208](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#208-canonical-serialization), самопин).

Код выхода: 0 — все строки материализованы; 4 — есть отказанные строки (INCOMPLETE: пакет и манифест записаны); 2 — отказ операции, ничего не записано.

Attributes

NameDescription
BINDING_INVALIDNo description.
CASE_NAME_RENo description.
CURRENCY_RENo description.
DATA_CLASSNo description.
DATE_RENo description.
DEFAULT_FALSENo description.
DEFAULT_TRUENo description.
ENTITY_ID_RENo description.
FACT_LIMITNo description.
INCOMPLETE_EXITNo description.
INSTANT_RENo description.
LITERAL_KINDSNo description.
MANIFEST_SCHEMA_VERSIONNo description.
MODEL_MISMATCHNo description.
NAME_RENo description.
OK_EXITNo description.
OUT_EXISTSNo description.
PLACEHOLDER_RENo description.
REFUSED_EXITNo description.
ROW_CARDINALITYNo description.
ROW_DATE_INVALIDNo description.
ROW_ENUM_UNKNOWNNo description.
ROW_FACT_LIMITNo description.
ROW_KEY_NULLNo description.
ROW_REQUIRED_NULLNo description.
ROW_TYPE_INVALIDNo description.
ROW_WEIGHT_INVALIDNo description.
SCHEMA_VERSIONNo description.
SOURCE_INVALIDNo description.
STDNo description.
TOOLNo description.
USAGENo description.
USAGE_TEXTNo description.

Classes

NameDescription
BindRefusalОтказ операции: код, текст; строка stderr по контракту §8.
MaterializedNo description.
RowRefusalОтказ строки: попадает в манифест, не прерывает операцию.
TableDataNo description.
TableSpecNo description.

Functions

NameDescription
binding_content_hashСамопин привязки: канон §208 без поля contentHash (как у screen).
canonical_numberКанон Integer/Decimal §208 из текста источника: знак, цифры,
check_bindingФорма по схеме, самопин и структурные проверки §2 решения.
check_modelПривязка против CLIR модели: semanticHash, сущности, перечисления,
literalЛитерал .lawcase из ячейки по типу колонки; ValueError с кодом ROW_*.
load_bindingNo description.
load_clirNo description.
mainNo description.
materializeNo description.
parse_booleanNo description.
parse_csvRFC 4180 без переводов строки в полях: UTF-8 без BOM, заголовок,
parse_time(вид, литерал без @) для Date или Instant; None — ни то, ни другое.
read_tableNo description.
render_textNo description.
substituteПодстановка {колонка} сырым значением; ValueError(ROW_KEY_NULL) при NULL.
write_out<out>/package/** и <out>/materialization.json; каталог создаётся здесь.

BINDING_INVALIDattributemodule attribute#

BINDING_INVALID = 'POPULATION_BINDING_INVALID'

CASE_NAME_REattributemodule attribute#

CASE_NAME_RE = re.compile('^[A-Za-z_][A-Za-z0-9_]*$')

CURRENCY_REattributemodule attribute#

CURRENCY_RE = re.compile('^[A-Z]{3}$')

DATA_CLASSattributemodule attribute#

DATA_CLASS = 'POPULATION_BINDING_DATA_CLASS'

DATE_REattributemodule attribute#

DATE_RE = re.compile('^(\\d{4})-(\\d{2})-(\\d{2})$')

DEFAULT_FALSEattributemodule attribute#

DEFAULT_FALSE = ['false', '0']

DEFAULT_TRUEattributemodule attribute#

DEFAULT_TRUE = ['true', '1']

ENTITY_ID_REattributemodule attribute#

ENTITY_ID_RE = re.compile('^[A-Za-z][A-Za-z0-9+.-]*:[^\\s\\"\\\\]+$')

FACT_LIMITattributemodule attribute#

FACT_LIMIT = 9999

INCOMPLETE_EXITattributemodule attribute#

INCOMPLETE_EXIT = 4

INSTANT_REattributemodule attribute#

INSTANT_RE = re.compile(
  '^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?(Z|[+-]\\d{2}:\\d{2})$'
)

LITERAL_KINDSattributemodule attribute#

LITERAL_KINDS = {
  STD + 'Integer': 'integer',
  STD + 'Decimal': 'decimal',
  STD + 'Money': 'money',
  STD + 'Boolean': 'boolean',
  STD + 'Text': 'text',
  STD + 'Date': 'date',
  STD + 'Instant': 'instant'
}

MANIFEST_SCHEMA_VERSIONattributemodule attribute#

MANIFEST_SCHEMA_VERSION = 'law.population.materialization/0.1'

MODEL_MISMATCHattributemodule attribute#

MODEL_MISMATCH = 'POPULATION_BINDING_MODEL_MISMATCH'

NAME_REattributemodule attribute#

NAME_RE = re.compile('^[A-Za-z0-9_.-]+$')

OK_EXITattributemodule attribute#

OK_EXIT = 0

OUT_EXISTSattributemodule attribute#

OUT_EXISTS = 'POPULATION_BIND_OUT_EXISTS'

PLACEHOLDER_REattributemodule attribute#

PLACEHOLDER_RE = re.compile('\\{([^{}]+)\\}')

REFUSED_EXITattributemodule attribute#

REFUSED_EXIT = 2

ROW_CARDINALITYattributemodule attribute#

ROW_CARDINALITY = 'ROW_CARDINALITY'

ROW_DATE_INVALIDattributemodule attribute#

ROW_DATE_INVALID = 'ROW_DATE_INVALID'

ROW_ENUM_UNKNOWNattributemodule attribute#

ROW_ENUM_UNKNOWN = 'ROW_ENUM_UNKNOWN'

ROW_FACT_LIMITattributemodule attribute#

ROW_FACT_LIMIT = 'ROW_FACT_LIMIT'

ROW_KEY_NULLattributemodule attribute#

ROW_KEY_NULL = 'ROW_KEY_NULL'

ROW_REQUIRED_NULLattributemodule attribute#

ROW_REQUIRED_NULL = 'ROW_REQUIRED_NULL'

ROW_TYPE_INVALIDattributemodule attribute#

ROW_TYPE_INVALID = 'ROW_TYPE_INVALID'

ROW_WEIGHT_INVALIDattributemodule attribute#

ROW_WEIGHT_INVALID = 'ROW_WEIGHT_INVALID'

SCHEMA_VERSIONattributemodule attribute#

SCHEMA_VERSION = 'law.population.binding/0.1'

SOURCE_INVALIDattributemodule attribute#

SOURCE_INVALID = 'POPULATION_SOURCE_INVALID'

STDattributemodule attribute#

STD = 'urn:law:std#'

TOOLattributemodule attribute#

TOOL = 'population-bind'

USAGEattributemodule attribute#

USAGE = 'POPULATION_BIND_USAGE'

USAGE_TEXTattributemodule attribute#

USAGE_TEXT = 'python -m lawref population-bind --binding <привязка.json> --clir <модель.lawir.json> --out <каталог> [--json]'

BindRefusalclass#

class BindRefusal(code: str, message: str)

Bases: Exception

Отказ операции: код, текст; строка stderr по контракту §8.

codeattributeinstance attribute#

code = code

messageattributeinstance attribute#

message = message

linemethod#

def line() -> str

Materializedclassdataclass#

class Materialized(files: dict[str, bytes], manifest: dict, manifest_bytes: bytes, exit_code: int)

exit_codeattributeinstance attribute#

exit_code: int

filesattributeinstance attribute#

files: dict[str, bytes]

manifestattributeinstance attribute#

manifest: dict

manifest_bytesattributeinstance attribute#

manifest_bytes: bytes

RowRefusalclass#

class RowRefusal(code: str, detail: str, table: str, key: list[str])

Bases: Exception

Отказ строки: попадает в манифест, не прерывает операцию.

codeattributeinstance attribute#

code = code

detailattributeinstance attribute#

detail = detail

keyattributeinstance attribute#

key = key

tableattributeinstance attribute#

table = table

TableDataclassdataclass#

class TableData(spec: TableSpec, content_hash: str, rows: list[dict[str, str | None]], by_key: dict[tuple[str, ...], dict[str, str | None]])

by_keyattributeinstance attribute#

by_key: dict[tuple[str, ...], dict[str, str | None]]

content_hashattributeinstance attribute#

content_hash: str

rowsattributeinstance attribute#

rows: list[dict[str, str | None]]

specattributeinstance attribute#

spec: TableSpec

TableSpecclassdataclass#

class TableSpec(name: str, file: str, key: list[str], id_pattern: str, entity_type: dict, parent: dict | None, columns: dict[str, dict], order: list[str])

columnsattributeinstance attribute#

columns: dict[str, dict]

entity_typeattributeinstance attribute#

entity_type: dict

fileattributeinstance attribute#

file: str

id_patternattributeinstance attribute#

id_pattern: str

keyattributeinstance attribute#

key: list[str]

nameattributeinstance attribute#

name: str

orderattributeinstance attribute#

order: list[str]

parentattributeinstance attribute#

parent: dict | None

binding_content_hashfunction#

def binding_content_hash(binding: dict) -> str

Самопин привязки: канон §208 без поля contentHash (как у screen).

canonical_numberfunction#

def canonical_number(raw: str, separator: str, allow_fraction: bool) -> str | None

Канон Integer/Decimal §208 из текста источника: знак, цифры, необязательно разделитель и цифры. None — не число.

check_bindingfunction#

def check_binding(binding: object) -> dict[str, TableSpec]

Форма по схеме, самопин и структурные проверки §2 решения.

check_modelfunction#

def check_model(binding: dict, tables: dict[str, TableSpec], document: dict) -> dict[str, dict]

Привязка против CLIR модели: semanticHash, сущности, перечисления, предикаты, арность и типы аргументов (побайтово как JSON TypeRef). Возвращает предикат → объявление.

literalfunction#

def literal(column: dict, raw: str, source: dict, model_name: str) -> str

Литерал .lawcase из ячейки по типу колонки; ValueError с кодом ROW_*.

load_bindingfunction#

def load_binding(path: Path) -> dict

load_clirfunction#

def load_clir(path: Path) -> dict

mainfunction#

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

materializefunction#

def materialize(binding_path: Path, clir_path: Path) -> Materialized

parse_booleanfunction#

def parse_boolean(column: dict, raw: str) -> bool

parse_csvfunction#

def parse_csv(data: bytes, delimiter: str, where: str) -> list[list[str]]

RFC 4180 без переводов строки в полях: UTF-8 без BOM, заголовок, \n или \r\n, кавычки удваиваются, управляющие символы — отказ. Возвращает записи (первая — заголовок).

parse_timefunction#

def parse_time(raw: str) -> tuple[str, str] | None

(вид, литерал без @) для Date или Instant; None — ни то, ни другое.

read_tablefunction#

def read_table(base: Path, spec: TableSpec, source: dict) -> TableData

render_textfunction#

def render_text(manifest: dict) -> str

substitutefunction#

def substitute(pattern: str, row: dict[str, str | None]) -> str

Подстановка {колонка} сырым значением; ValueError(ROW_KEY_NULL) при NULL.

write_outfunction#

def write_out(result: Materialized, out: Path) -> None

<out>/package/** и <out>/materialization.json; каталог создаётся здесь.

Documentation for Arxo. Writings — blog.arxo.io.

Anonymous visit counts on stats.arxo.io, no cookies.