Research toward building a content pack from a story corpus, kept on its own branch and independent of the game. Records the selection experiments against blind labels, and settles selection as gate G2 followed by a human review: review.py writes REVIEW.md and a review.json form, apply_review.py checks the filled form and writes situations.json for the next stage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C6UDQ9o6L6Ey173U7XVou6
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
"""Check a filled-in review form and turn it into situations.json.
|
|
|
|
python3 apply_review.py review/k60-s24
|
|
|
|
Reads candidates.json and review.json from that directory. If the form is complete and consistent, it
|
|
writes situations.json there and exits 0. Otherwise it prints every problem at once, writes nothing,
|
|
and exits 1.
|
|
"""
|
|
import datetime, json, pathlib, sys
|
|
import review_format as rf
|
|
|
|
|
|
def main(argv):
|
|
if len(argv) != 2:
|
|
print(__doc__.strip())
|
|
return 2
|
|
run_dir = pathlib.Path(argv[1])
|
|
cand_path, form_path = run_dir / 'candidates.json', run_dir / 'review.json'
|
|
for p in (cand_path, form_path):
|
|
if not p.exists():
|
|
print(f'{p} does not exist. Run review.py first, or check the directory name.')
|
|
return 1
|
|
candidates = json.loads(cand_path.read_text(encoding='utf-8'))
|
|
try:
|
|
form = json.loads(form_path.read_text(encoding='utf-8'))
|
|
except json.JSONDecodeError as e:
|
|
print(f'{form_path} is not valid JSON: line {e.lineno}, column {e.colno}: {e.msg}.')
|
|
print('Common causes: a missing comma between fields, a trailing comma before } or ], or a quote left open.')
|
|
return 1
|
|
|
|
errors, warnings, result = rf.validate(candidates, form)
|
|
for w in warnings:
|
|
print(f'warning: {w}')
|
|
if errors:
|
|
print(f'\n{len(errors)} problem(s) to fix in {form_path}; nothing was written:')
|
|
for e in errors:
|
|
print(f' - {e}')
|
|
return 1
|
|
|
|
result['applied'] = datetime.datetime.now().astimezone().isoformat(timespec='seconds')
|
|
out = run_dir / 'situations.json'
|
|
out.write_text(json.dumps(result, indent=1, ensure_ascii=False), encoding='utf-8')
|
|
c = result['counts']
|
|
print(f'\n{out}: {c["situations"]} situations from {c["accepted"]} accepted and {c["merged"]} merged '
|
|
f'candidates; {c["rejected"]} rejected, {c["skipped"]} skipped.')
|
|
for s in result['situations']:
|
|
print(f' {s["id"]} ({s["size"]} scenes, {s["stories"]} stories, from {"+".join(s["from"])}): {s["situation"]}')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv))
|