#!/usr/bin/env python3
"""Job #1502 probe round 3: the *readable* carriers of Motohashi's mechanism.
Round 1-2 established: the 1976 paper is paywalled on Project Euclid, J-Stage
answers 500 from this computer, and the zbMATH record Zbl 0355.10035 carries NO
review text (record-only). Round 3 therefore reads the carriers that a modern
reader actually uses:
(a) Semantic Scholar for the 1976 record's abstract/open-access pointer,
(b) the arXiv API for the 2023 "induction principle over F_q[t]" paper, whose
zbMATH review states Motohashi's principle as convolution-preservation,
(c) that paper's full HTML text (arXiv LaTeXML), searched for every mention of
Motohashi -- an author who *uses* the induction principle has to say how
the transfer works.
Read-only, public, no credentials. Raw replies saved + hashed in sources/.
"""
import hashlib
import json
import os
import re
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, "sources")
os.makedirs(OUT, exist_ok=True)
UA = {"User-Agent": "solveathome-local-probe/1 (research)",
"Accept": "application/json, text/html, application/xml;q=0.8"}
DOI = "10.3792/pja/1195518296"
def fetch(url, tries=2, timeout=45, accept=None):
last = None
for i in range(tries):
req = urllib.request.Request(url, headers=dict(UA, **({"Accept": accept} if accept else {})))
try:
with urllib.request.urlopen(req, timeout=timeout) as r:
return r.status, r.read(), r.geturl()
except urllib.error.HTTPError as e:
return e.code, e.read(), url
except Exception as e:
last = repr(e)
time.sleep(2)
return None, (last or "unknown").encode(), url
def save(name, body):
with open(os.path.join(OUT, name), "wb") as f:
f.write(body)
return {"file": name, "bytes": len(body), "sha256": hashlib.sha256(body).hexdigest()}
def plain(body):
s = body.decode("utf-8", "replace")
s = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?\1>", " ", s)
s = re.sub(r"(?s)<[^>]+>", " ", s)
for a, b in (("'", "'"), (" ?", " "), ("&", "&"), ("<", "<"), (">", ">")):
s = re.sub(a, b, s)
return re.sub(r"\s+", " ", s).strip()
def main():
rec = {"round": 3, "probes": [], "motohashi_mentions": []}
# (a) Semantic Scholar: abstract / OA pointer for the 1976 paper
url = ("https://api.semanticscholar.org/graph/v1/paper/DOI:%s"
"?fields=title,abstract,year,venue,externalIds,openAccessPdf,citationCount" % DOI)
status, body, final = fetch(url, accept="application/json")
rec["probes"].append({"label": "s2-motohashi", "channel": "semanticscholar",
"url": url, "status": status, **save("r3-s2-motohashi.json", body),
"text_head": body.decode("utf-8", "replace")[:1500]})
time.sleep(2)
# (b) arXiv API: the modern adaptation(s) of the induction principle
for label, q in [("arxiv-induction-principle",
'all:"induction principle" AND all:"Bombieri"'),
("arxiv-motohashi", 'all:"Motohashi" AND all:"Bombieri"')]:
u = ("http://export.arxiv.org/api/query?search_query=" + urllib.parse.quote(q)
+ "&start=0&max_results=20&sortBy=relevance")
status, body, final = fetch(u, accept="application/atom+xml")
ids = re.findall(r"