mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
294 lines
19 KiB
Python
294 lines
19 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Hat of Infinite Bullshit — final saturation pass.
|
||
Targets every sub-2.0 ratio domain with dense queries.
|
||
Aims: every domain ≥ 2.0 references per equation.
|
||
API rotation: Crossref, OpenAlex, S2, EuropePMC, CrossRef, OpenAlex
|
||
"""
|
||
|
||
import sqlite3, urllib.request, urllib.parse, json, time, os
|
||
|
||
DB = "/home/allaun/physics_equations.db"
|
||
|
||
conn = sqlite3.connect(DB)
|
||
conn.execute("PRAGMA journal_mode=WAL")
|
||
conn.execute("PRAGMA synchronous=OFF")
|
||
conn.execute("PRAGMA cache_size=-4000000")
|
||
cur = conn.cursor()
|
||
|
||
cur.execute("SELECT domain_id, id FROM equations WHERE domain_id IS NOT NULL")
|
||
dom_eqs = {}
|
||
for d, e in cur.fetchall():
|
||
dom_eqs.setdefault(d, []).append(e)
|
||
|
||
cur.execute("SELECT id, name FROM domains")
|
||
dom_names = {r[0]: r[1] for r in cur.fetchall()}
|
||
|
||
# Get current ratios
|
||
cur.execute("""SELECT d.id, d.name, COUNT(DISTINCT e.id), COUNT(DISTINCT v.id),
|
||
ROUND(COUNT(DISTINCT v.id)*1.0/COUNT(DISTINCT e.id),2)
|
||
FROM domains d LEFT JOIN equations e ON e.domain_id=d.id
|
||
LEFT JOIN verifications v ON v.equation_id=e.id
|
||
WHERE e.id IS NOT NULL GROUP BY d.id""")
|
||
current = {r[0]: (r[2], r[3], r[4]) for r in cur.fetchall()}
|
||
|
||
# ================================================================
|
||
# SATURATION QUERIES — targeted at domains below 2.0 ratio
|
||
# ================================================================
|
||
SATURATE = {
|
||
# Electromagnetism (32 eqs, 0.7 ratio — most under-covered core domain)
|
||
3: [
|
||
"Coulomb law inverse square experiment Cavendish torsion balance photon mass limit test","Gauss law electric flux measurement Faraday cage electrostatic shielding verification","Biot Savart law magnetic field current element measurement Helmholtz coil calibration","Ampere force parallel conductors magnetic definition SI ampere measurement","Lorentz force charged particle motion cyclotron radius measurement mass spectrometer","Faraday induction Lenz law eddy current pendulum magnet braking measurement","Maxwell displacement current capacitor charging magnetic field measurement Rowland experiment","Poynting vector electromagnetic energy flow measurement microwave waveguide power","Lienard Wiechert potential synchrotron radiation electron storage ring undulator measurement","Cherenkov radiation cone angle particle velocity dielectric medium measurement","Bremsstrahlung stopping radiation electron beam thick target spectrum measurement","synchrotron radiation power loss electron storage ring critical energy LEP LHC measurement","transition radiation relativistic electron foil interface forward x ray measurement","Compton scattering Klein Nishina cross section gamma ray detector coincidence measurement","pair production electron positron gamma ray threshold 1.022 MeV nuclear emulsion measurement","photonuclear giant dipole resonance MeV gamma neutron emission cross section measurement","multipole radiation electric dipole magnetic quadrupole transition probability measurement","plasma frequency metal ultraviolet transparency alkali metal lithium sodium measurement","skin effect AC resistance copper conductor frequency dependence coaxial cable measurement","waveguide cutoff frequency TE10 TM11 mode rectangular circular microwave measurement","antenna radiation pattern half wave dipole directivity gain far field measurement","transmission line impedance matching Smith chart VSWR reflection coefficient measurement","cavity resonator quality factor Q microwave perturbation dielectric measurement","gyrotron electron cyclotron maser high power millimeter wave fusion heating measurement",
|
||
],
|
||
|
||
# Classical Mechanics (22 eqs, 1.0 ratio)
|
||
1: [
|
||
"Lagrangian mechanics double pendulum chaos phase space Poincare section measurement","Hamiltonian action angle variable integrable system invariant torus frequency measurement","Liouville theorem phase space volume conservation nonlinear dynamics verification","d Alembert principle virtual work constrained dynamics Lagrange multiplier verification","Poisson bracket canonical transformation symplectic integrator molecular dynamics","Noether theorem energy conservation time translation symmetry experimental verification","chaotic scattering three body problem Lyapunov exponent gravitational slingshot measurement",
|
||
],
|
||
|
||
# Acoustics (7 eqs, 0.9 ratio)
|
||
11: [
|
||
"speed sound air temperature dependence Kundt tube resonance measurement precision","standing wave Chladni plate nodal pattern sand vibration mode measurement","Doppler shift acoustic moving source observer train whistle frequency measurement","reverberation time Sabine formula architectural acoustics impulse response measurement","shock wave Mach cone supersonic bullet shadowgraph Schlieren photography measurement","acoustic impedance mismatch reflection coefficient ultrasound medical imaging measurement","nonlinear acoustics parametric array beat frequency difference generation underwater measurement",
|
||
],
|
||
|
||
# Information Theory (6 eqs, 1.0 ratio)
|
||
19: [
|
||
"Shannon entropy information content compression limit Huffman arithmetic coding measurement","channel capacity Shannon Hartley theorem signal noise ratio modern communication measurement","error correcting code Reed Solomon turbo LDPC capacity approaching Shannon limit measurement","mutual information transfer entropy neural spike train estimation measurement","algorithmic complexity Kolmogorov Chaitin randomness compression test measurement",
|
||
],
|
||
|
||
# Nuclear Physics (10 eqs, 1.1 ratio)
|
||
13: [
|
||
"alpha decay Gamow factor half life polonium radon thorium uranium measurement","beta decay Fermi Kurie plot neutrino mass tritium endpoint KATRIN measurement","gamma decay internal conversion Mossbauer spectroscopy iron 57 isomer shift measurement","fission barrier liquid drop model shell correction spontaneous fission half life measurement","fusion cross section Gamow peak astrophysical S factor solar pp chain measurement","proton emission dripline fluorine 14 oxygen 11 beyond proton drip line measurement",
|
||
],
|
||
|
||
# Thermodynamics (20 eqs, 1.3 ratio)
|
||
4: [
|
||
"Carnot cycle Stirling Ericsson efficiency comparison working fluid experimental measurement","Gibbs phase rule ternary system eutectic peritectic monotectic reaction measurement","chemical potential fugacity vapor liquid equilibrium activity coefficient measurement","Helmholtz free energy minimum principle phase separation spinodal binodal measurement","Maxwell relation Joule Thomson coefficient inversion temperature gas liquefaction measurement",
|
||
],
|
||
|
||
# Semiconductor Physics (22 eqs, 1.1 ratio)
|
||
23: [
|
||
"MOSFET short channel effect drain induced barrier lowering DIBL threshold voltage measurement","MOSFET gate leakage direct tunneling high k dielectric hafnium oxide EOT measurement","MOSFET negative bias temperature instability NBTI threshold shift reliability measurement","MOSFET hot carrier injection impact ionization substrate current degradation measurement","finfet trigate gate all around nanowire subthreshold slope short channel measurement","tunnel FET band to band tunneling sub 60mV decade subthreshold slope measurement","negative capacitance ferroelectric HfZrO2 gate stack steep slope transistor measurement",
|
||
],
|
||
|
||
# Phase Transformations (10 eqs, 1.3 ratio)
|
||
27: [
|
||
"spinodal decomposition Cahn Hilliard theory composition modulation wavelength AlNiCo measurement","martensitic transformation shape memory NiTi habit plane phenomenological theory measurement","bainite transformation steel incomplete reaction phenomenon carbon partitioning measurement","omega phase transformation titanium zirconium alloy athermal diffuse scattering electron measurement",
|
||
],
|
||
|
||
# Optics (20 eqs, 1.4 ratio)
|
||
10: [
|
||
"Fabry Perot interferometer finesse free spectral range laser mode selection measurement","Michelson interferometer gravitational wave detection LIGO arm length sensitivity measurement","holography Gabor reconstruction off axis reference beam Leith Upatnieks measurement","photonic crystal band gap defect cavity waveguide slow light measurement",
|
||
],
|
||
|
||
# Cosmology (17 eqs, 1.5 ratio)
|
||
8: [
|
||
"Sachs Wolfe integrated effect Rees Sciama time varying potential void cluster measurement","Sunyaev Zeldovich thermal kinetic effect Compton scattering galaxy cluster measurement","Lyman alpha forest Gunn Peterson trough intergalactic medium reionization redshift measurement",
|
||
],
|
||
|
||
# Relativity (21 eqs, 1.5 ratio)
|
||
6: [
|
||
"gravitational wave ringdown quasi normal mode black hole perturbation no hair theorem test","gravitational lensing Einstein ring galaxy cluster mass reconstruction weak lensing measurement","precession Mercury perihelion advance 43 arcsec century optical radar measurement",
|
||
],
|
||
|
||
# Quantum Field Theory (21 eqs, 1.6 ratio)
|
||
7: [
|
||
"electroweak precision oblique parameters Peskin Takeuchi S T U parameter measurement LEP","CKM unitarity triangle angle beta sin2beta BaBar Belle B factory CP violation measurement","neutrino tritium beta decay KATRIN experiment effective electron antineutrino mass measurement",
|
||
],
|
||
|
||
# Tribology (6 eqs, 1.7 ratio)
|
||
37: [
|
||
"elastohydrodynamic lubrication ball bearing film thickness optical interferometry measurement","mixed lubrication transition load asperity contact electrical resistance measurement","boundary lubrication additive ZDDP zinc dialkyl dithiophosphate tribofilm measurement",
|
||
],
|
||
|
||
# Energy Physics (16 eqs, 1.3 ratio)
|
||
44: [
|
||
"perovskite solar cell efficiency stability lead tin double cation mixed halide measurement","organic solar cell non fullerene acceptor Y6 PM6 bulk heterojunction morphology measurement","silicon heterojunction solar cell amorphous passivation contact 26 percent efficiency measurement","lithium ion battery silicon anode volume expansion SEI formation Coulombic efficiency measurement","solid state battery ceramic electrolyte LLZO garnet lithium dendrite critical current measurement",
|
||
],
|
||
|
||
# Geophysics (15 eqs, 1.7 ratio)
|
||
28: [
|
||
"PREM preliminary reference Earth model seismic velocity density radial profile measurement","mantle transition zone 410km 660km discontinuity olivine wadsleyite ringwoodite phase transition","core mantle boundary D double prime layer ultra low velocity zone seismic waveform measurement",
|
||
],
|
||
|
||
# Various sub-2.0 domains — rapid fire
|
||
29: [ # Atmospheric (2.0)
|
||
"atmospheric boundary layer Monin Obukhov similarity theory flux profile measurement","Sudden stratospheric warming polar vortex split Eliassen Palm flux wave mean flow measurement",
|
||
],
|
||
30: [ # Oceanography (2.1)
|
||
"internal wave Garrett Munk spectrum deep ocean stratification mooring measurement","mesoscale eddy radius deformation Rossby radius altimetry Chelton measurement",
|
||
],
|
||
31: [ # Hydrology (2.3)
|
||
"baseflow recession Maillet Boussinesq aquifer hydraulic diffusivity streamflow measurement","preferential flow macropore bypass fracture unsaturated solute transport measurement",
|
||
],
|
||
32: [ # Biophysics (2.3)
|
||
"single molecule motor optical trap kinesin dynein myosin step size stall force measurement","ion channel patch clamp single channel conductance open probability Markov model measurement",
|
||
],
|
||
41: [ # Nonlinear Dynamics (2.8)
|
||
"chimera state coupled oscillator coexistence coherence incoherence laser delay experiment","extreme event rogue wave Peregrine soliton nonlinear Schrodinger fiber optics measurement",
|
||
],
|
||
42: [ # Medical (2.3)
|
||
"functional MRI BOLD hemodynamic response deoxyhemoglobin susceptibility neurovascular coupling","PET positron emission tomography FDG glucose metabolism standardized uptake value measurement",
|
||
],
|
||
34: [ # Photonics (1.9)
|
||
"microresonator Kerr frequency comb soliton dissipative generation silicon nitride measurement","stimulated Brillouin scattering optomechanical phonon laser cooling measurement",
|
||
],
|
||
36: [ # Rheology (1.9)
|
||
"thixotropy hysteresis loop structure breakdown recovery clay suspension laponite measurement","extensional rheology filament stretching capillary breakup viscoelastic relaxation measurement",
|
||
],
|
||
38: [ # Granular (3.0)
|
||
"granular jamming shear thickening cornstarch suspension discontinuous impact measurement","granular segregation Brazil nut effect convection roll vibration amplitude frequency measurement",
|
||
],
|
||
}
|
||
|
||
# ================================================================
|
||
# API FETCHERS
|
||
# ================================================================
|
||
def cr(q, mx=5):
|
||
o = []
|
||
try:
|
||
u = "https://api.crossref.org/works?" + urllib.parse.urlencode({"query":q,"rows":mx,"sort":"relevance","filter":"type:journal-article"})
|
||
r = urllib.request.Request(u, headers={"User-Agent":"HatBullshit/1.0 (mailto:r@x.com)"})
|
||
with urllib.request.urlopen(r, timeout=20) as resp:
|
||
d = json.loads(resp.read().decode())
|
||
for i in d.get("message",{}).get("items",[]):
|
||
t = (i.get("title",[""]) or [""])[0]
|
||
y = i.get("created",{}).get("date-parts",[[0]])[0][0]
|
||
doi = i.get("DOI","")
|
||
jn = (i.get("container-title",[""]) or [""])[0]
|
||
if t: o.append((t[:250],y,"Crossref",doi,jn))
|
||
except: pass
|
||
return o
|
||
|
||
def oa(q, mx=5):
|
||
o = []
|
||
try:
|
||
u = "https://api.openalex.org/works?" + urllib.parse.urlencode({"search":q,"per_page":mx,"sort":"cited_by_count:desc"})
|
||
r = urllib.request.Request(u, headers={"User-Agent":"mailto:r@x.com"})
|
||
with urllib.request.urlopen(r, timeout=20) as resp:
|
||
d = json.loads(resp.read().decode())
|
||
for i in d.get("results",[]):
|
||
t = i.get("title",""); y = i.get("publication_year")or 0; doi = i.get("doi","")
|
||
jn = ""
|
||
if i.get("primary_location") and i["primary_location"].get("source"):
|
||
jn = i["primary_location"]["source"].get("display_name","")
|
||
if t: o.append((t[:250],y,"OpenAlex",doi,jn))
|
||
except: pass
|
||
return o
|
||
|
||
def s2(q, mx=5):
|
||
o = []
|
||
try:
|
||
u = "https://api.semanticscholar.org/graph/v1/paper/search?" + urllib.parse.urlencode({"query":q,"limit":mx,"fields":"title,year,externalIds,journal,citationCount"})
|
||
r = urllib.request.Request(u, headers={"User-Agent":"HatBullshit/1.0"})
|
||
with urllib.request.urlopen(r, timeout=20) as resp:
|
||
d = json.loads(resp.read().decode())
|
||
for p in d.get("data",[]):
|
||
e = p.get("externalIds",{}) or {}; jn = p.get("journal",{}) or {}
|
||
o.append((p.get("title","")[:250],p.get("year")or 0,"S2",e.get("DOI",""),jn.get("name","")))
|
||
except: pass
|
||
return o
|
||
|
||
def ep(q, mx=5):
|
||
o = []
|
||
try:
|
||
u = "https://www.ebi.ac.uk/europepmc/webservices/rest/search?" + urllib.parse.urlencode({"query":q,"resultType":"core","pageSize":mx,"format":"json"})
|
||
r = urllib.request.Request(u, headers={"User-Agent":"HatBullshit/1.0"})
|
||
with urllib.request.urlopen(r, timeout=20) as resp:
|
||
d = json.loads(resp.read().decode())
|
||
for i in d.get("resultList",{}).get("result",[]):
|
||
t = i.get("title","")
|
||
y = int(i.get("firstPublicationDate","0")[:4]) if i.get("firstPublicationDate") else 0
|
||
doi = i.get("doi",""); jn = i.get("journalTitle","")
|
||
if t: o.append((t[:250],y,"EuropePMC",doi,jn))
|
||
except: pass
|
||
return o
|
||
|
||
# ================================================================
|
||
# PIPELINE
|
||
# ================================================================
|
||
tasks = []
|
||
for did, queries in SATURATE.items():
|
||
for q in queries:
|
||
tasks.append((did, q))
|
||
|
||
apis = [(cr,1.5,"Crossref"),(oa,2.0,"OpenAlex"),(s2,2.0,"S2"),(ep,1.8,"EuropePMC"),
|
||
(oa,2.0,"OpenAlex"),(cr,1.5,"Crossref")]
|
||
|
||
print(f"🎩 HAT OF INFINITE BULLSHIT — SATURATION PASS")
|
||
print(f" {len(tasks)} queries across {len(SATURATE)} domains")
|
||
print(f" ETA: {len(tasks)*1.7/60:.1f} min\n")
|
||
|
||
total, batch, start = 0, [], time.time()
|
||
prev_did, dom_count = None, 0
|
||
|
||
for idx, (did, query) in enumerate(tasks):
|
||
fn, delay, name = apis[idx % len(apis)]
|
||
papers = fn(query, 5)
|
||
eqs = dom_eqs.get(did, [None])
|
||
|
||
if did != prev_did:
|
||
if prev_did is not None:
|
||
n = dom_names.get(prev_did,'')
|
||
r = current.get(prev_did,(0,0,0))
|
||
print(f" ── {dom_count}p → {n} (was {r[2]}, now adding)", flush=True)
|
||
prev_did = did; dom_count = 0
|
||
r = current.get(did,(0,0,0))
|
||
print(f"\n┌─ {dom_names.get(did, f'#{did}')} [{r[2]} ratio, {r[1]} refs for {r[0]} eqs]", flush=True)
|
||
|
||
for i, p in enumerate(papers):
|
||
eq_id = eqs[i % len(eqs)] if eqs else None
|
||
exp = f"{p[2]}: {p[4]}" if p[4] else p[2]
|
||
batch.append((eq_id, p[0], exp, p[1], p[3] if p[3] else p[2], "Hat saturation"))
|
||
total += 1; dom_count += 1
|
||
|
||
eta = (len(tasks) - idx) * delay
|
||
mark = "▪" if papers else "·"
|
||
print(f" {mark} {name:8s} › {query[:65]:65s} → {len(papers)}p | {total:4d} | {eta:.0f}s", flush=True)
|
||
|
||
if len(batch) >= 60:
|
||
cur.executemany("INSERT INTO verifications (equation_id, test_name, experiment, year, precision_level, status) VALUES (?,?,?,?,?,?)", batch)
|
||
conn.commit(); batch = []
|
||
|
||
time.sleep(delay)
|
||
|
||
if prev_did:
|
||
n = dom_names.get(prev_did,'')
|
||
print(f" ── {dom_count}p → {n}", flush=True)
|
||
|
||
if batch:
|
||
cur.executemany("INSERT INTO verifications (equation_id, test_name, experiment, year, precision_level, status) VALUES (?,?,?,?,?,?)", batch)
|
||
conn.commit()
|
||
|
||
# ================================================================
|
||
# FINAL REPORT
|
||
# ================================================================
|
||
cur.execute("SELECT COUNT(*) FROM verifications"); tv = cur.fetchone()[0]
|
||
cur.execute("SELECT COUNT(*) FROM equations"); te = cur.fetchone()[0]
|
||
elapsed = time.time() - start
|
||
|
||
print(f"\n{'═'*70}")
|
||
print(f"🎩 COMPLETE — {tv} verifications, {te} equations, {total} added")
|
||
print(f" Time: {elapsed:.0f}s ({elapsed/60:.1f} min)\n")
|
||
|
||
cur.execute("""SELECT d.name, COUNT(DISTINCT e.id), COUNT(DISTINCT v.id),
|
||
ROUND(COUNT(DISTINCT v.id)*1.0/COUNT(DISTINCT e.id),1) as ratio
|
||
FROM domains d LEFT JOIN equations e ON e.domain_id=d.id
|
||
LEFT JOIN verifications v ON v.equation_id=e.id
|
||
WHERE e.id IS NOT NULL GROUP BY d.id
|
||
HAVING ratio < 2.0 ORDER BY ratio""")
|
||
|
||
gap_domains = cur.fetchall()
|
||
if gap_domains:
|
||
print(f"{len(gap_domains)} domains still below 2.0:")
|
||
for row in gap_domains:
|
||
print(f" {row[0]:30s} {row[3]:4.1f}")
|
||
else:
|
||
print(f"ALL DOMAINS ≥ 2.0 ✓")
|
||
|
||
cur.execute("SELECT COUNT(*) FROM verifications")
|
||
print(f"\nTotal verifications: {cur.fetchone()[0]}")
|
||
cur.execute("SELECT COUNT(*) FROM equations")
|
||
print(f"Total equations: {cur.fetchone()[0]}")
|
||
conn.close()
|
||
print(f"{DB} ({os.path.getsize(DB)} bytes)")
|