Files
paper-atlas/paper_atlas/collectors/kdd2026.py
T
codex-bot 6e5202c81a
Metadata integrity checks / metadata (push) Successful in 8m7s
Inventory KDD 2026 programme cycles and withdrawal evidence
2026-11-18 23:14:36 +08:00

130 lines
5.4 KiB
Python

"""Inventory KDD 2026 programme DOI, cycle and track observations."""
import argparse
from collections import Counter
from hashlib import sha256
from html.parser import HTMLParser
import json
from pathlib import Path
import re
SOURCE_URL = 'https://kdd2026.kdd.org/papers/'
CYCLES = {1: 'july', 2: 'february'}
TRACKS = {
'rtp': 'research', 'ads': 'applied_data_science', 'dtb': 'datasets_and_benchmarks',
'ais': 'ai_for_sciences', 'bsi': 'blue_sky_ideas',
}
DOI_URL = re.compile(r'https://doi\.org/(10\.1145/\d+\.\d+)')
WITHDRAWN = re.compile(
r'^\*\*WITHDRAWN/New SUBMISSION ID for Authorship Order Change (\d{1,2}/\d{1,2}/26) -- (.+)$'
)
OTHER_STATUS = re.compile(r'^[*\[(!#\s]*(?:withdrawn|rejected|desk[\s_-]+rejected|retracted|cancell?ed)\b', re.I)
class ProgrammeScripts(HTMLParser):
def __init__(self):
super().__init__()
self.current = None
self.scripts = []
def handle_starttag(self, tag, attrs):
if tag == 'script' and 'src' not in dict(attrs):
self.current = []
def handle_data(self, data):
if self.current is not None:
self.current.append(data)
def handle_endtag(self, tag):
if tag == 'script' and self.current is not None:
self.scripts.append(''.join(self.current))
self.current = None
def cycle_rows(scripts, cycle):
pattern = re.compile(r'\bconst\s+cycle' + str(cycle) + r'Papers\s*=\s*(\[)')
matches = [(code, match) for code in scripts for match in pattern.finditer(code)]
if len(matches) != 1:
raise ValueError(f'Expected one KDD programme array for cycle {cycle}')
code, match = matches[0]
body = code[match.start(1):]
rows, consumed = json.JSONDecoder().raw_decode(body)
if not rows or not body[consumed:].lstrip().startswith('.map((paper, index)'):
raise ValueError(f'Unexpected KDD programme array boundary for cycle {cycle}')
return rows
def inventory(raw):
parser = ProgrammeScripts()
parser.feed(raw.decode('utf-8'))
parser.close()
records = {}
source_counts = {}
for cycle, cycle_name in CYCLES.items():
rows = cycle_rows(parser.scripts, cycle)
source_counts[cycle_name] = Counter()
for row in rows:
if (not isinstance(row, dict) or row.keys() != {'track', 'title', 'url', 'authors'}
or not all(isinstance(value, str) for value in row.values())
or row['track'] not in TRACKS or not row['title'].strip()):
raise ValueError('Unexpected KDD programme row')
match = DOI_URL.fullmatch(row['url'])
if not match:
raise ValueError('Invalid DOI link in KDD programme')
doi = match[1]
track = TRACKS[row['track']]
source_counts[cycle_name][track] += 1
row_hash = sha256(json.dumps(row, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
if doi in records:
entry = records[doi]
if (entry['cycle'], entry['source_row_sha256']) != (cycle_name, row_hash):
raise ValueError('Conflicting duplicate DOI in KDD programme: ' + doi)
entry['occurrences'] += 1
continue
status = 'listed'
withdrawn = WITHDRAWN.fullmatch(row['title'])
if withdrawn:
status = 'withdrawn_with_replacement_mentioned'
elif OTHER_STATUS.match(row['title']):
raise ValueError('Unrecognized status annotation in KDD programme: ' + doi)
records[doi] = {
'doi': doi, 'doi_url': row['url'], 'source_title': row['title'],
'title': withdrawn[2] if withdrawn else row['title'],
'cycle': cycle_name, 'track': track, 'programme_status': status,
'authors_listed': bool(row['authors'].strip()), 'occurrences': 1,
'source_row_sha256': row_hash,
}
if withdrawn:
records[doi]['source_withdrawal_date_literal'] = withdrawn[1]
ordered = [records[doi] for doi in sorted(records)]
return ordered, source_counts
def collect(snapshot, expected_sha256, out):
snapshot = Path(snapshot)
with snapshot.open('rb') as stream:
raw = stream.read(4_000_001)
if len(raw) > 4_000_000 or sha256(raw).hexdigest() != expected_sha256:
raise ValueError('KDD programme snapshot hash or size differs')
rows, cycle_counts = inventory(raw)
result = {
'source': SOURCE_URL, 'snapshot_sha256': expected_sha256,
'source_rows_by_cycle_and_track': cycle_counts, 'unique_dois': len(rows),
'identical_repeat_rows': sum(row['occurrences'] - 1 for row in rows),
'programme_status_counts': Counter(row['programme_status'] for row in rows),
'records': rows, 'database_written': False,
}
with Path(out).open('x', encoding='utf-8') as stream:
json.dump(result, stream, ensure_ascii=False, indent=2)
stream.write('\n')
return result
def main(argv=None, *, prog=None):
parser = argparse.ArgumentParser(prog=prog)
parser.add_argument('--snapshot', required=True)
parser.add_argument('--snapshot-sha256', required=True)
parser.add_argument('--out', required=True)
args = parser.parse_args(argv)
result = collect(args.snapshot, args.snapshot_sha256, args.out)
print(json.dumps({k: result[k] for k in ('unique_dois', 'identical_repeat_rows', 'programme_status_counts')}))