"""WildClean — loaders for the NON-redistributable benchmark pairs. The WildClean release ships 33 of the 42 paired dirty/clean sets directly (see pairs/). The remaining 9 sources carry no license or a research-only status, so we do NOT redistribute them — instead this script downloads them from their origins and materializes them in exactly the layout the benchmark expects (pairs//{dirty.csv,clean.csv}). Sources fetched here (origins, accessed 2026-06): * ed2_restaurants — BigDaMa/ExampleDrivenErrorDetection (no license stated) * cleanml_company / cleanml_movie — CleanML 2020 datasets zip (research use) * fodors_zagats / dblp_acm / dblp_scholar — Magellan/DeepMatcher EM benchmarks (UW-Madison pages; redistribution terms unclear) * gidcl_imdb — SICS-FRC GIDCL imdb pair (no license stated) * zeroed_billionaire / zeroed_tax100k — WelkinNi/ZeroED pairs (no license) Usage: python loaders.py # materialize all 9 into ./pairs/ python loaders.py --only ed2_restaurants gidcl_imdb Requires: pandas. Mirrors the harvest logic of the ScrubData repo (training/harvest_stage2.py, training/harvest_stage3_paired.py) so the resulting pairs are byte-compatible with the published results/paired_bench.json. """ from __future__ import annotations import argparse import difflib import io import re import urllib.parse import urllib.request import zipfile from pathlib import Path import pandas as pd PAIRS = Path(__file__).resolve().parent / "pairs" UA = {"User-Agent": "wildclean-loader/1.0"} # ---- origins --------------------------------------------------------------- ED2 = "https://raw.githubusercontent.com/BigDaMa/ExampleDrivenErrorDetection/master/datasets" CLEANML_ZIP = "https://www.dropbox.com/s/nerfrhbrseev928/CleanML-datasets-2020.zip?dl=1" EM_BASE = "https://pages.cs.wisc.edu/~anhai/data1/deepmatcher_data/Structured" GIDCL = "https://raw.githubusercontent.com/SICS-Fundamental-Research-Center/GIDCL/main/GEIL_Data/imdb/original" ZEROED = "https://raw.githubusercontent.com/WelkinNi/ZeroED/main/data" # name -> (zip dir, zip file stem, canonical side) EM_SETS = { "fodors_zagats": ("Fodors-Zagats", "fodors_zagat", "B"), "dblp_acm": ("DBLP-ACM", "dblp_acm", "A"), "dblp_scholar": ("DBLP-GoogleScholar", "dblp_scholar", "A"), } # ---- shared helpers (mirrors training/real_data.py + harvest scripts) ------ def _read_csv(src, **kw) -> pd.DataFrame: try: return pd.read_csv(src, dtype=str, keep_default_na=False, **kw) except UnicodeDecodeError: if hasattr(src, "seek"): src.seek(0) return pd.read_csv(src, dtype=str, keep_default_na=False, encoding="latin-1", **kw) def _read_url(url: str) -> pd.DataFrame: req = urllib.request.Request(url, headers=UA) with urllib.request.urlopen(req, timeout=300) as r: return _read_csv(io.BytesIO(r.read())) def _norm(s: str) -> str: return "".join(ch.lower() for ch in str(s) if ch.isalnum()) def _is_variant(dirty: str, clean: str) -> bool: """True if `dirty` is a SURFACE VARIANT (typo / casing / punctuation / minor abbreviation) of `clean` — a learnable canonicalization, not a different valid value. Mirrors training/real_data.py.""" nd, nc = _norm(dirty), _norm(clean) if not nd or not nc: return False if nd == nc: # casing / punctuation only return True return difflib.SequenceMatcher(None, nd, nc).ratio() >= 0.72 def _write_pair(name: str, dirty: pd.DataFrame, clean: pd.DataFrame) -> None: n = min(len(dirty), len(clean)) dirty = dirty.head(n).reset_index(drop=True) clean = clean.head(n).reset_index(drop=True) d = PAIRS / name d.mkdir(parents=True, exist_ok=True) dirty.to_csv(d / "dirty.csv", index=False) clean.to_csv(d / "clean.csv", index=False) diff = sum((dirty.iloc[:, j].astype(str) != clean.iloc[:, j].astype(str)).sum() for j in range(min(dirty.shape[1], clean.shape[1]))) print(f" {name}: {n} rows x {dirty.shape[1]} cols, {diff} diff cells -> {d}") # ---- ed2_restaurants -------------------------------------------------------- def load_ed2_restaurants() -> None: frames = [] for kind in ("dirty", "clean"): req = urllib.request.Request(f"{ED2}/Restaurants_{kind}.csv", headers=UA) with urllib.request.urlopen(req) as r: frames.append(_read_csv(io.BytesIO(r.read()))) dirty, clean = frames for df in (dirty, clean): # re-keyed ids aren't corrections for c in list(df.columns): if c.lower() == "id": df.drop(columns=[c], inplace=True) _write_pair("ed2_restaurants", dirty, clean) # ---- cleanml_company / cleanml_movie ---------------------------------------- def load_cleanml(members=("Company", "Movie")) -> None: import tempfile tmp = Path(tempfile.gettempdir()) / "cleanml-2020.zip" if not tmp.exists(): print(" downloading CleanML zip (large, one-time)...") urllib.request.urlretrieve(CLEANML_ZIP, tmp) zf = zipfile.ZipFile(tmp) names = zf.namelist() for ds in members: raw = next((n for n in names if n.endswith(f"{ds}/raw/raw.csv")), None) cln = next((n for n in names if n.endswith(f"{ds}/raw/inconsistency_clean_raw.csv")), None) if not raw or not cln: print(f" cleanml_{ds.lower()}: pair not found in zip — skipped") continue dirty = _read_csv(zf.open(raw)) clean = _read_csv(zf.open(cln)) _write_pair(f"cleanml_{ds.lower()}", dirty, clean) # ---- fodors_zagats / dblp_acm / dblp_scholar (EM benchmarks -> pair tables) -- def load_em() -> None: """Turn entity-matching benchmarks into row-aligned pair TABLES: one row per gold match, dirty side = messy table, clean side = canonical table. Matched records may legitimately DISAGREE on an attribute (cuisine classification, author-list format) — that is not an error; only surface-variant diffs are kept as (dirty, clean) corrections, otherwise the messy value is accepted as truth on both sides (the VARIANT MASK).""" for name, (zdir, stem, canon_side) in EM_SETS.items(): req = urllib.request.Request(f"{EM_BASE}/{zdir}/{stem}_raw_data.zip", headers=UA) with urllib.request.urlopen(req) as r: zf = zipfile.ZipFile(io.BytesIO(r.read())) A = _read_csv(zf.open("tableA.csv")) B = _read_csv(zf.open("tableB.csv")) M = _read_csv(zf.open("matches.csv")) a = A.set_index(A.columns[0]) b = B.set_index(B.columns[0]) cols = [c for c in a.columns if c in b.columns] dirty_rows, clean_rows, seen = [], [], set() masked = 0 for _, m in M.iterrows(): ia, ib = str(m.iloc[0]), str(m.iloc[1]) if ia not in a.index or ib not in b.index or ia in seen: continue seen.add(ia) ra = a.loc[ia] if not isinstance(a.loc[ia], pd.DataFrame) else a.loc[ia].iloc[0] rb = b.loc[ib] if not isinstance(b.loc[ib], pd.DataFrame) else b.loc[ib].iloc[0] canon, messy = (ra, rb) if canon_side == "A" else (rb, ra) drow, crow = [], [] for c in cols: dv, cv = str(messy[c]), str(canon[c]) if dv != cv and not _is_variant(dv, cv): cv = dv masked += 1 drow.append(dv) crow.append(cv) dirty_rows.append(drow) clean_rows.append(crow) print(f" {name}: masked {masked} non-variant attribute disagreements") _write_pair(name, pd.DataFrame(dirty_rows, columns=cols), pd.DataFrame(clean_rows, columns=cols)) # ---- gidcl_imdb -------------------------------------------------------------- def load_gidcl_imdb(max_clean_sample: int = 30000) -> None: """Row-aligned SUBSET of the 1M-row GIDCL imdb pair: every dirty row plus a deterministic sample of clean rows (keeps the pair small but error-complete).""" dirty = _read_url(f"{GIDCL}/dirty.csv") clean = _read_url(f"{GIDCL}/clean.csv") n = min(len(dirty), len(clean)) dirty, clean = dirty.head(n), clean.head(n) neq = (dirty.astype(str).values != clean.astype(str).values).any(axis=1) err_idx = dirty.index[neq] clean_idx = dirty.index[~neq][:: max(1, (n - len(err_idx)) // max_clean_sample)][:max_clean_sample] keep = sorted(set(err_idx) | set(clean_idx)) _write_pair("gidcl_imdb", dirty.loc[keep], clean.loc[keep]) # ---- zeroed_billionaire / zeroed_tax100k ------------------------------------- def load_zeroed(names=("billionaire", "tax100k")) -> None: for nm in names: dirty = _read_url(f"{ZEROED}/{nm}_error-01.csv") clean = _read_url(f"{ZEROED}/{nm}_clean.csv") _write_pair(f"zeroed_{nm}", dirty, clean) LOADERS = { "ed2_restaurants": load_ed2_restaurants, "cleanml": load_cleanml, # cleanml_company + cleanml_movie "em": load_em, # fodors_zagats + dblp_acm + dblp_scholar "gidcl_imdb": load_gidcl_imdb, "zeroed": load_zeroed, # zeroed_billionaire + zeroed_tax100k } def main() -> None: ap = argparse.ArgumentParser(description=__doc__) ap.add_argument("--only", nargs="*", default=None, help=f"subset of loaders to run: {sorted(LOADERS)}") args = ap.parse_args() todo = args.only or list(LOADERS) print(f"WildClean loaders -> {PAIRS}") for key in todo: if key not in LOADERS: print(f" unknown loader '{key}' (choices: {sorted(LOADERS)})") continue print(f"[{key}]") LOADERS[key]() print("done — the full 42-pair benchmark is now materialized under pairs/.") if __name__ == "__main__": main()