|
import json |
|
import os |
|
from pathlib import Path |
|
|
|
def test_jsonl_file(filepath): |
|
print(f"\nTesting file: {filepath}") |
|
try: |
|
if not os.path.exists(filepath): |
|
print(f"ERROR: File does not exist: {filepath}") |
|
return False |
|
|
|
with open(filepath, 'r', encoding='utf-8') as f: |
|
for idx, line in enumerate(f, 1): |
|
try: |
|
data = json.loads(line.strip()) |
|
|
|
required_fields = ["context", "question", "prerequisit", "groundtruth_zoo", "answer"] |
|
missing_fields = [field for field in required_fields if field not in data] |
|
if missing_fields: |
|
print(f"Warning: Line {idx} is missing fields: {missing_fields}") |
|
except json.JSONDecodeError as e: |
|
print(f"ERROR: Invalid JSON at line {idx}: {e}") |
|
return False |
|
print("File is valid!") |
|
return True |
|
except Exception as e: |
|
print(f"ERROR: Failed to process file: {e}") |
|
return False |
|
|
|
def main(): |
|
|
|
base_dir = Path(__file__).parent |
|
|
|
|
|
test_files = [ |
|
base_dir / "all" / "train.jsonl", |
|
base_dir / "all" / "test.jsonl", |
|
base_dir / "basic" / "test.jsonl", |
|
base_dir / "advance" / "test.jsonl", |
|
base_dir / "challenge" / "test.jsonl", |
|
] |
|
|
|
all_valid = True |
|
for file_path in test_files: |
|
if not test_jsonl_file(file_path): |
|
all_valid = False |
|
|
|
if all_valid: |
|
print("\nAll files are valid!") |
|
else: |
|
print("\nSome files have errors. Please fix them before proceeding.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|