File size: 1,717 Bytes
832f0f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """Shared dataset paths, task identities, and JSON output."""
import hashlib
import json
import os
from pathlib import Path
import tempfile
ROOT = Path(__file__).resolve().parents[1]
CATEGORIES = {
'VSS': {'comparative_selection', 'npc_search'},
'IGC': {'deliver_report', 'dialogue_handoff', 'distributed_information'},
'IRA': {'conditional_instruction', 'instruction_revision'},
'MST': {'spatial_memory_return', 'state_tracking'},
'SARE': {'constraint_route', 'door_traversal', 'multi_stage_route'},
}
def read(path):
return json.loads(Path(path).read_text(encoding='utf-8'))
def digest(path):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
def write(path, value):
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
fd, name = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent)
try:
with os.fdopen(fd, 'w', encoding='utf-8') as stream:
json.dump(value, stream, ensure_ascii=False, indent=2, allow_nan=False)
stream.write('\n')
os.replace(name, path)
finally:
if os.path.exists(name):
os.unlink(name)
def definitions():
return {p.stem: read(p) for p in sorted((ROOT / 'subtasks').glob('*.json'))}
def canonical_id(value):
if not isinstance(value, str):
raise ValueError('Missing task ID')
aliases = read(ROOT / 'eval/task_aliases.json')
value = aliases.get(value, value)
if not (ROOT / 'data' / (value + '.json')).is_file() or Path(value).name != value:
raise ValueError('Unrecognized task ID: ' + value)
return value
def category(task_type):
return next(key for key, types in CATEGORIES.items() if task_type in types)
|