Metadata-Version: 2.4
Name: iyulab-gil
Version: 0.3.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Typing :: Typed
License-File: LICENSE
Summary: Suggests and decides form field values from how settled documents were filled.
Keywords: forms,suggestion,precision,replay,classification
License-Expression: Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Changelog, https://github.com/iyulab/gil/blob/rust-core/crates/gil/CHANGELOG.md
Project-URL: Repository, https://github.com/iyulab/gil

# Gil (Python — `iyulab-gil`)

Gil suggests the judged fields of a form from the documents people have already settled, and chooses — by
replaying them in the order they were settled — how far each suggestion can be trusted and how often a trusted one will
be right.

This package binds its Rust decision core: replay settled documents to choose how far each layer's suggestions for a
form field can be trusted, and get back the decision records the choice rests on.

```sh
pip install iyulab-gil
```

```python
import gil

form = gil.Form.from_dict(
    {
        "name": "ticket",
        "fields": [
            {"name": "product", "role": "observed"},
            {"name": "summary", "role": "observed"},
            {"name": "team", "role": "judged"},
        ],
    }
)
documents = gil.read_records(
    "settled.jsonl"
)  # one JSON object per line, in settlement order
thresholds, records = gil.select_layers(
    form, "team", documents, target_precision=0.8
)
print(thresholds["key"]["chosen"], len(records))
```

Before choosing thresholds, narrow the fields that key the judged field. A field that happened to settle with one
value for a while would otherwise key every later document that shares it:

```python
choice = gil.select_key_fields(form, "team", documents, target_precision=0.8, minimum_answered=30)
definition = {
    "name": "ticket",
    "fields": [
        {"name": "product", "role": "observed"},
        {"name": "summary", "role": "observed"},
        {"name": "team", "role": "judged", "key_fields": choice["key_fields"]},
    ],
}
thresholds, records = gil.select_layers(
    gil.Form.from_dict(definition), "team", documents, target_precision=0.8
)
```

`key_fields` is `None` when no narrower set did better than every field — leave it unset then.

The other settings follow the same pattern — choose, then set on the field: `select_key_concentrations` (set as
`key_concentrations`, after `key_fields`) and, for a field with a coarse level (`"coarse": {"prefix": 2}`),
`select_coarse` once its value thresholds are set.

**Status: early.** The API may change within 0.x — each change is listed in
[CHANGELOG.md](https://github.com/iyulab/gil/blob/rust-core/crates/gil/CHANGELOG.md) with what to do about it.

Apache-2.0 — see `LICENSE`.

