File size: 5,273 Bytes
2f8cc61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""Build the prepared Ørïelith//9 dataset from the completed release.

Uses Python standard library only. Does not fabricate experimental records.
This packaging builder is kept outside the upload directory.
"""
from pathlib import Path
import csv
import hashlib
import json

REPO = Path(__file__).resolve().parents[1]


def write_json(path, value):
    path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")


def csv_records(name):
    with (REPO / "research" / name).open(encoding="utf-8", newline="") as f:
        return list(csv.DictReader(f))


def build_data(repo=REPO):
    """Deterministically convert source files to eight separate table schemas."""
    global REPO
    REPO = Path(repo)
    data = REPO / "data"
    data.mkdir(parents=True, exist_ok=True)
    source = "research/Orielith9_Research_Source.md"
    blocks = (REPO / source).read_text(encoding="utf-8").split("<!-- PAGE -->")
    sections = []
    for i, block in enumerate(blocks):
        block = block.strip()
        if not block:
            continue
        title = next(line[2:] for line in block.splitlines() if line.startswith("# "))
        sections.append({"id": f"section-{i:02d}", "section_index": i,
                         "title": title, "text": block, "source_path": source,
                         "record_type": "research_manuscript",
                         "evidence_status": "proposal_and_conditional_analysis; see section for cited component evidence"})
    configs = {"manuscript": sections}
    params = json.loads((REPO / "research/design_parameters.json").read_text(encoding="utf-8"))
    configs["design_parameters"] = [
        {"id": f"parameter-{i:03d}", "parameter": key,
         "value_json": json.dumps(value, ensure_ascii=False, separators=(",", ":")),
         "source_path": "research/design_parameters.json",
         "evidence_status": "design_input_or_design_metadata; not a measured integrated property"}
        for i, (key, value) in enumerate(params.items())]
    for config, filename, status in [
        ("layers", "layer_stack.csv", "nominal_design_geometry"),
        ("formulations", "chemical_formulations.csv", "candidate_feed; qualification_required"),
        ("technology_compatibility", "technology_compatibility.csv", "proposed_integration_route; custom_qualification_required"),
        ("frontier_comparisons", "frontier_comparison.csv", "source_scoped_comparison; evidence_type_column_controls_interpretation"),
        ("reference_model", "nonlinear_reference_reconstruction.csv", "dimensionless_conditional_model; no_experimental_measurements"),
        ("capture_control", "illustrative_capture_trajectory.csv", "illustrative_reference_free_control_model; no_experimental_measurements"),
    ]:
        rows = csv_records(filename)
        for i, row in enumerate(rows):
            if config == "layers":
                for field in ("z0_um", "z1_um", "thickness_um"):
                    row[field] = int(row[field])
            if config in ("reference_model", "capture_control"):
                row = {key: float(value) for key, value in row.items()}
            row = {"id": f"{config}-{i:03d}", **row,
                   "source_path": f"research/{filename}", "evidence_status": status}
            configs.setdefault(config, []).append(row)
    for name, rows in configs.items():
        (data / f"{name}.jsonl").write_text(
            "".join(json.dumps(row, ensure_ascii=False, allow_nan=False) + "\n" for row in rows), encoding="utf-8")
    info = {}
    for name, rows in configs.items():
        types = {key: type(value).__name__ for key, value in rows[0].items()}
        assert all({key: type(value).__name__ for key, value in row.items()} == types for row in rows)
        info[name] = {"rows": len(rows), "split": "train", "path": f"data/{name}.jsonl", "fields": types}
    write_json(REPO / "dataset_schema.json", {
        "project_id": "orielith9", "release": "3.0", "configs": info,
        "split_note": "train is the Hub storage convention only; no training/evaluation partition is implied",
        "experimental_records": 0,
        "transformations": ["manuscript split at explicit page markers; text preserved after outer whitespace trimming",
                            "design JSON top-level values encoded as JSON strings to preserve heterogeneous types",
                            "CSV rows preserved; layer coordinates cast to integers and model coordinates to floats",
                            "deterministic IDs and explicit provenance/evidence labels added"]})
    return info


def manifest(repo=REPO):
    repo = Path(repo)
    files = []
    for path in sorted(repo.rglob("*")):
        if path.is_file() and path.name != "MANIFEST.json":
            files.append({"path": path.relative_to(repo).as_posix(), "bytes": path.stat().st_size,
                          "sha256": hashlib.sha256(path.read_bytes()).hexdigest()})
    write_json(repo / "MANIFEST.json", {"project_id": "orielith9", "release": "3.0",
                                       "checksum_algorithm": "sha256", "files": files})


if __name__ == "__main__":
    info = build_data()
    manifest()
    print(json.dumps({key: value["rows"] for key, value in info.items()}, indent=2))