File size: 1,788 Bytes
ee1736c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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_<COLL>.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())