Extensible JSONL task editing library for code and formula inputs.
Project description
logicedit
logicedit processes JSON or JSONL task records, applies controlled line edits, runs edited variants through registered tools, evaluates tool outputs, and writes successful variants back as JSONL.
Features
- Dataclass-based record models with
extra_optionsfor forward-compatible schema changes. single_editmode for independent edits from the original input.cumulative_editmode for greedy accepted edits applied on top of prior edits.- Tool registry with in-memory tools, Python-file adapters, and built-in Z3 and Prover9 solver adapters.
- Explicit required tool selection via
tool. - Configurable label comparison strategies for label-preserving and label-variation workflows.
- Minimal examples with a mock tool and mock editor.
Install
python3 -m pip install -e .[dev]
This installs the library dependencies, including z3-solver, nltk, ply, and Unidecode for the built-in Z3 and Prover9 backends.
PyPI Release Flow
Build and upload to PyPI:
make publish-pypi
Install the published package from PyPI:
make install-pypi
If you prefer the raw commands:
python3 -m build
python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
python3 -m pip install logicedit
Run
python3 -m logicedit.cli \
--input /path/to/tasks.jsonl \
--output /path/to/successes.jsonl \
--tool csp_solver.py \
--edit-mode single_edit \
--number-of-edits 3 \
--label-variation \
--single-edit-ids 0,2,4
number_of_edits accepts either a positive integer or "all".
- In
single_editmode, the library evaluates independent edits from the original input and saves every successful independent edit.number_of_editsis ignored in this mode. Use--single-edit-idsorextra_options.selected_edit_idsto restrict which editable units are considered. - In
cumulative_editmode,number_of_editscontrols how many accepted cumulative edits are saved."all"means the runner walks the editable statements from first to last, tries the available operator edits for each statement against thelabel_variationcondition, applies the first acceptable edit, and then moves to the next statement. --toolis mandatory on the CLI. The library no longer defaults silently tocsp_solver.--no-label-variationis the default behavior: only save records whose tool output matches the original label.--label-variationinverts that rule: only save records whose tool output differs from the original label.
Available tool families:
csp_solver.pyor another Python tool file: uses the Python-file adapter. Pointextra_options.tool_search_pathsat the folder containing it. The adapter can call plain functions such asrun(input_text)and also supports theCSP_Programclass shape found in the source files.z3_solver: uses the built-in vendored Z3 backend and Z3-specific operator edits in the# Constraintssection:AND -> OR,XOR -> OR,OR -> XOR, andNOTremoval.prover9_solverortool_inference.py: uses the built-in vendored Prover9 backend and Prover9-specific premise edits such as∨ -> ∧,⊕ -> ∨,∨ -> ⊕, and¬removal.
The library only searches tool paths you provide or the input file directory added by the CLI.
Example Z3 run:
python3 -m logicedit.cli \
--input /path/to/z3_tasks.jsonl \
--output /path/to/z3_successes.jsonl \
--tool z3_solver \
--edit-mode cumulative_edit \
--number-of-edits all
Example Prover9 run:
export PROVER9=/path/to/LADR-2009-11A/bin/prover9
python3 -m logicedit.cli \
--input /path/to/prover9_tasks.jsonl \
--output /path/to/prover9_successes.jsonl \
--tool prover9_solver \
--edit-mode single_edit
prover9_solver expects each record to provide:
premise_translations: a list of"English ::: FOL"premise stringsconclusion_translation: one"English ::: FOL"conclusion string
You can point Prover9 at the LADR binary in any of these ways:
- Set
PROVER9=/path/to/LADR-2009-11A/bin/prover9 - Put
extra_options.prover9_pathorextra_options.prover9_executablein each record - Place an extracted
LADR-2009-11A/bin/prover9directory at the repo root or current working directory
Ways to include LADR-2009-11A.tar with the library:
- Recommended: keep the extracted
LADR-2009-11Adirectory outside the wheel and configurePROVER9orextra_options.prover9_path. This avoids shipping a large platform-specific binary inside the package. - Repo-local vendor: commit an extracted
LADR-2009-11A/directory next to the project and letlogiceditdiscoverLADR-2009-11A/bin/prover9automatically. This is simple but makes the repo much larger. - Managed bootstrap: add a separate setup script that unpacks
LADR-2009-11A.tarinto a known cache or vendor directory before running Prover9. This keeps the wheel cleaner while still supporting a self-contained checkout. - Platform-specific packaging: include the extracted executable as package data in a macOS/Linux-specific build. This is the most self-contained option, but it is heavier and harder to maintain across platforms.
Example Record
{
"id": "logical_deduction_0",
"tool": "csp_solver.py",
"input_type": "code",
"edit_mode": "single_edit",
"number_of_edits": 2,
"label_variation": false,
"expected_answer": "D",
"logic_program": "Domain:\n...\nConstraints:\nThe blue book is to the right of the yellow book. ::: blue_book > yellow_book\n...\n\nQuery:\n..."
}
Example Z3 record:
{
"id": "ar_lsat_0",
"tool": "z3_solver",
"input_type": "code",
"edit_mode": "single_edit",
"number_of_edits": 2,
"label_variation": true,
"expected_answer": "B",
"logic_program": "# Declarations\n...\n\n# Constraints\nrule ::: A AND B\n...\n\n# Options\nQuestion ::: ...\n..."
}
Example Prover9 record:
{
"id": "folio_0",
"tool": "prover9_solver",
"input_type": "code",
"edit_mode": "single_edit",
"number_of_edits": 2,
"label_variation": true,
"expected_answer": "A",
"question": "Is the conclusion entailed?",
"premise_translations": [
"All cats are either pets or strays. ::: ∀x (Cat(x) → (Pet(x) ∨ Stray(x)))",
"Milo is not a stray. ::: ¬Stray(Milo)"
],
"conclusion_translation": "Milo is a pet. ::: Pet(Milo)",
"extra_options": {
"prover9_path": "/path/to/LADR-2009-11A/bin/prover9"
}
}
Test
python3 -m pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logicedit-0.1.8.tar.gz.
File metadata
- Download URL: logicedit-0.1.8.tar.gz
- Upload date:
- Size: 39.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38f6c5e08acf60f7eff6a5a81876978652de97f2b533fe931ed0cbce0dfd540f
|
|
| MD5 |
52387c9815faec229d556afe80fe632c
|
|
| BLAKE2b-256 |
cc2943601a0a0a496ef5cc45bb118f48c18a1e7041db2c0ba27847de36ca6423
|
File details
Details for the file logicedit-0.1.8-py3-none-any.whl.
File metadata
- Download URL: logicedit-0.1.8-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44249ffb6bb795f2c9628af3d37a4cfb24236cf3dd7c9a8e4ac4948d053156ef
|
|
| MD5 |
7f703ad62a5458ba3cbcd6229006de55
|
|
| BLAKE2b-256 |
5a0ec44d6e9eee54ae36fe0278a383443df10fefc0de159c8c6f6102bcb86dfd
|