File size: 4,765 Bytes
f5684cd
8fbb1ec
 
 
f5684cd
8fbb1ec
8e5ce5e
 
611ad3d
39d122d
 
8fbb1ec
 
 
 
 
 
 
68095de
8fbb1ec
 
 
f5684cd
 
8fbb1ec
 
 
 
 
 
 
 
 
 
 
68095de
 
8fbb1ec
 
 
 
 
8e5ce5e
 
 
f5684cd
39d122d
 
f5684cd
b1b50d4
8fbb1ec
b1b50d4
 
 
 
8fbb1ec
b1b50d4
 
 
39d122d
b1b50d4
 
 
68095de
 
59489c5
388a501
f5684cd
388a501
59489c5
f5684cd
59489c5
 
 
 
 
 
f5684cd
59489c5
 
 
 
 
b1b50d4
 
 
 
39d122d
8fbb1ec
 
 
 
f5684cd
8fbb1ec
b1b50d4
8fbb1ec
 
 
 
 
 
 
 
 
 
 
b1b50d4
 
 
8fbb1ec
 
b1b50d4
8fbb1ec
 
39d122d
b1b50d4
8fbb1ec
 
 
 
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""Build the Space's data in dataset/site/ from ../claims/*.json.

Usage (from the project root or this folder):
  python3 space/build_data.py
  python3 space/publish_dataset.py   # then upload it to the dataset the Space reads from

Only papers with verdict "include" or "borderline" are published, minus
those listed in claims/site_exclude.json.
Compute estimates are kept internal (not written to papers.json).
Papers listed in pwc_indexed.json (refresh with check_pwc.py) get "pwc": true,
so the page links to Papers with Code for them and to arXiv otherwise.
"""
import csv
import glob
import json
import os
import shutil
import struct
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
OUT = os.path.join(HERE, "dataset")  # uploaded by publish_dataset.py
SITE = os.path.join(OUT, "site")
CLAIMS = os.path.join(ROOT, "claims")
SHOW = {"include", "borderline"}


def png_size(path):
    with open(path, "rb") as f:
        head = f.read(24)
    return struct.unpack(">II", head[16:24])


def main():
    if not glob.glob(os.path.join(CLAIMS, "*.json")):
        sys.exit(f"No claim files in {CLAIMS}; nothing written. Run this where the claims folder exists.")
    manifest = {}
    path = os.path.join(ROOT, "manifest.csv")
    if os.path.exists(path):
        manifest = {r["arxiv_id"]: r for r in csv.DictReader(open(path, newline=""))}

    exclude_path = os.path.join(CLAIMS, "site_exclude.json")
    exclude = json.load(open(exclude_path)) if os.path.exists(exclude_path) else {}

    pwc_path = os.path.join(OUT, "pwc_indexed.json")
    pwc = set(json.load(open(pwc_path))) if os.path.exists(pwc_path) else set()

    os.makedirs(os.path.join(SITE, "img"), exist_ok=True)
    papers, skipped = [], []
    for f in sorted(glob.glob(os.path.join(CLAIMS, "*.json"))):
        try:
            d = json.load(open(f))
        except Exception:
            skipped.append((os.path.basename(f), "unparseable"))
            continue
        if not isinstance(d, dict) or d.get("verdict") not in SHOW or d.get("arxiv_id") in exclude:
            continue
        try:
            papers.append(entry(d, manifest, pwc))
        except Exception as e:
            skipped.append((os.path.basename(f), repr(e)[:120]))

    if not papers:
        sys.exit(f"No publishable papers found in {CLAIMS}; nothing written.")
    compact = dict(ensure_ascii=False, separators=(",", ":"))
    # 1) tiny index for the first paint: just the IDs, enough to shuffle, count and show the first paper
    with open(os.path.join(SITE, "index.json"), "w") as out:
        json.dump([p["id"] for p in papers], out, **compact)
    # 2) one small file per paper, fetched when that paper is shown
    pdir = os.path.join(SITE, "p")
    shutil.rmtree(pdir, ignore_errors=True)
    os.makedirs(pdir)
    for p in papers:
        with open(os.path.join(pdir, p["id"] + ".json"), "w") as out:
            json.dump(p, out, **compact)
    # 3) search corpus, fetched only when someone types in the search box
    with open(os.path.join(SITE, "search.json"), "w") as out:
        json.dump([[p["id"], " ".join([p["title"], p["authors"], p["claim"], p["background"]]).lower()] for p in papers], out, **compact)
    old = os.path.join(HERE, "papers.json")
    if os.path.exists(old):
        os.remove(old)
    print(f"wrote {len(papers)} papers (index.json, p/<id>.json, search.json); skipped {len(skipped)} invalid")
    for name, why in skipped:
        print(f"  skipped {name}: {why}")


def entry(d, manifest, pwc):
        c = d["main_claim"]
        img_src = os.path.join(CLAIMS, c["image"])
        img_name = f"img/{d['arxiv_id']}.png"
        img_w, img_h = png_size(img_src)
        shutil.copyfile(img_src, os.path.join(SITE, img_name))
        m = manifest.get(d["arxiv_id"], {})
        return {
            "id": d["arxiv_id"],
            "title": " ".join(d["title"].split()),
            "authors": m.get("authors", ""),
            "openreview_id": d.get("openreview_id", ""),
            "presentation": d.get("presentation") or m.get("presentation", "poster"),
            "track": d.get("track") or m.get("track", ""),
            "verdict": d["verdict"],
            "background": d["background"],
            "method": d["method"],
            "claim": c["statement"],
            "source": c["source"],
            "metric": c.get("metric", ""),
            "comparison": c.get("comparison", ""),
            "falsification": c.get("falsification_criterion", ""),
            "caption": c["caption"],
            "image": img_name,
            "kind": c.get("kind") or "table",
            "image_w": img_w,
            "image_h": img_h,
            "pwc": d["arxiv_id"] in pwc,
        }


if __name__ == "__main__":
    main()