"""Web of Science collection lists (SCIE / SSCI / AHCI / ESCI) from Wikidata ("indexed in bibliographic review", P8875), for when Clarivate's Master Journal List downloads are not available. Wikidata is CC0 but incomplete (roughly 60-90 % of each collection), so a journal missing here may still be indexed. python devtools/fetch_wos_wikidata.py -> finder/data/wos/wikidata_.csv """ import csv import sys from pathlib import Path import requests COLLECTIONS = {"SCIE": "Q104047209", "SSCI": "Q1090953", "AHCI": "Q713927", "ESCI": "Q22908122"} OUT = Path(__file__).resolve().parent.parent / "finder" / "data" / "wos" QUERY = """SELECT ?j ?title ?issn WHERE { ?j p:P8875 ?st . ?st ps:P8875 wd:%s . FILTER NOT EXISTS { ?st pq:P582 ?end } # no longer indexed ?j wdt:P236 ?issn . OPTIONAL { ?j wdt:P1476 ?t } OPTIONAL { ?j rdfs:label ?l FILTER(LANG(?l) = "en") } BIND(COALESCE(?t, ?l) AS ?title) }""" def fetch(qid: str) -> list[tuple[str, str]]: r = requests.get("https://query.wikidata.org/sparql", params={"query": QUERY % qid, "format": "json"}, headers={"User-Agent": "CS-AI-Writing-Suite-Finder/1.0"}, timeout=300) r.raise_for_status() return [(b.get("title", {}).get("value", ""), b["issn"]["value"]) for b in r.json()["results"]["bindings"]] def main() -> int: OUT.mkdir(parents=True, exist_ok=True) for coll, qid in COLLECTIONS.items(): rows = sorted(set(fetch(qid))) with open(OUT / f"wikidata_{coll}.csv", "w", newline="", encoding="utf-8") as f: w = csv.writer(f) w.writerow(["Journal title", "ISSN"]) w.writerows(rows) print(f"{coll}: {len({i for _, i in rows}):,} ISSNs") return 0 if __name__ == "__main__": sys.exit(main())