zerohallucination 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. api/__init__.py +2 -0
  2. api/index.py +8 -0
  3. api/zerohallucination/__init__.py +37 -0
  4. api/zerohallucination/dashboard_html.py +464 -0
  5. api/zerohallucination/decomposer.py +124 -0
  6. api/zerohallucination/engine.py +105 -0
  7. api/zerohallucination/gateway.py +606 -0
  8. api/zerohallucination/interceptor.py +44 -0
  9. api/zerohallucination/middleware.py +41 -0
  10. api/zerohallucination/physics_verifier.py +282 -0
  11. api/zerohallucination/proof_certificate.py +123 -0
  12. api/zerohallucination/rlvr_loop.py +101 -0
  13. api/zerohallucination/smt_solver.py +159 -0
  14. api/zerohallucination/sql_code_verifier.py +162 -0
  15. api/zerohallucination/symbolic_prover.py +191 -0
  16. api/zerohallucination/types.py +46 -0
  17. api/zerohallucination/zerobench.py +165 -0
  18. zerohallucination/__init__.py +40 -0
  19. zerohallucination/billing.py +297 -0
  20. zerohallucination/dashboard_html.py +464 -0
  21. zerohallucination/decomposer.py +165 -0
  22. zerohallucination/engine.py +111 -0
  23. zerohallucination/gateway.py +967 -0
  24. zerohallucination/interceptor.py +61 -0
  25. zerohallucination/middleware.py +41 -0
  26. zerohallucination/physics_verifier.py +282 -0
  27. zerohallucination/proof_certificate.py +128 -0
  28. zerohallucination/rlvr_loop.py +113 -0
  29. zerohallucination/smt_solver.py +300 -0
  30. zerohallucination/sql_code_verifier.py +162 -0
  31. zerohallucination/symbolic_prover.py +232 -0
  32. zerohallucination/types.py +46 -0
  33. zerohallucination/zerobench.py +165 -0
  34. zerohallucination-2.2.0.dist-info/METADATA +192 -0
  35. zerohallucination-2.2.0.dist-info/RECORD +38 -0
  36. zerohallucination-2.2.0.dist-info/WHEEL +5 -0
  37. zerohallucination-2.2.0.dist-info/licenses/LICENSE.md +73 -0
  38. zerohallucination-2.2.0.dist-info/top_level.txt +2 -0
api/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ # Package marker for Vercel
2
+
api/index.py ADDED
@@ -0,0 +1,8 @@
1
+ import sys
2
+ import os
3
+
4
+ api_dir = os.path.dirname(os.path.abspath(__file__))
5
+ if api_dir not in sys.path:
6
+ sys.path.insert(0, api_dir)
7
+
8
+ from zerohallucination.gateway import app
@@ -0,0 +1,37 @@
1
+ """ZeroHallucinationAI: Enterprise Neuro-Symbolic Deterministic Verification Engine.
2
+
3
+ Author: Md Mahmudul Hoque (mahmudulhoque934@gmail.com)
4
+ Copyright (c) 2026 Md Mahmudul Hoque. All Rights Reserved.
5
+ """
6
+
7
+ __version__ = "2.2.0"
8
+ __author__ = "Md Mahmudul Hoque"
9
+ __email__ = "mahmudulhoque934@gmail.com"
10
+
11
+ from .types import Claim, ClaimType, VerificationStatus, VerificationResult, ProofStep
12
+ from .engine import ZeroHallucinationEngine
13
+ from .smt_solver import SMTSolver
14
+ from .physics_verifier import PhysicsVerifier
15
+ from .sql_code_verifier import SQLSchemaVerifier, SchemaRegistry
16
+ from .rlvr_loop import RLVRRefiner
17
+ from .proof_certificate import MerkleAuditor, ProofCertificate
18
+ from .interceptor import StreamingTruthInterceptor
19
+ from .middleware import ZeroHallucinationMiddleware
20
+
21
+ __all__ = [
22
+ "Claim",
23
+ "ClaimType",
24
+ "VerificationStatus",
25
+ "VerificationResult",
26
+ "ProofStep",
27
+ "ZeroHallucinationEngine",
28
+ "SMTSolver",
29
+ "PhysicsVerifier",
30
+ "SQLSchemaVerifier",
31
+ "SchemaRegistry",
32
+ "RLVRRefiner",
33
+ "MerkleAuditor",
34
+ "ProofCertificate",
35
+ "StreamingTruthInterceptor",
36
+ "ZeroHallucinationMiddleware",
37
+ ]
@@ -0,0 +1,464 @@
1
+ DASHBOARD_HTML = r"""<!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>ZeroHallucinationAI - Deterministic Verification Console</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
8
+ <style>
9
+ :root {
10
+ --bg: #090d16;
11
+ --surface: #111726;
12
+ --surface-border: #1f293d;
13
+ --primary: #3b82f6;
14
+ --accent: #6366f1;
15
+ --success: #10b981;
16
+ --danger: #ef4444;
17
+ --warning: #f59e0b;
18
+ --text-main: #f8fafc;
19
+ --text-muted: #94a3b8;
20
+ }
21
+
22
+ * { margin: 0; padding: 0; box-sizing: border-box; }
23
+ body {
24
+ background-color: var(--bg);
25
+ color: var(--text-main);
26
+ font-family: 'Plus Jakarta Sans', sans-serif;
27
+ min-height: 100vh;
28
+ display: flex;
29
+ flex-direction: column;
30
+ }
31
+
32
+ header {
33
+ padding: 1.5rem 2.5rem;
34
+ display: flex;
35
+ justify-content: space-between;
36
+ align-items: center;
37
+ border-bottom: 1px solid var(--surface-border);
38
+ background: rgba(17, 23, 38, 0.6);
39
+ backdrop-filter: blur(12px);
40
+ }
41
+
42
+ .brand {
43
+ display: flex;
44
+ align-items: center;
45
+ gap: 0.75rem;
46
+ }
47
+
48
+ .logo-badge {
49
+ background: linear-gradient(135deg, #3b82f6, #6366f1);
50
+ color: white;
51
+ font-weight: 700;
52
+ font-size: 1.1rem;
53
+ padding: 0.35rem 0.75rem;
54
+ border-radius: 8px;
55
+ box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
56
+ }
57
+
58
+ .brand h1 {
59
+ font-size: 1.25rem;
60
+ font-weight: 700;
61
+ letter-spacing: -0.02em;
62
+ }
63
+
64
+ .brand span {
65
+ color: #60a5fa;
66
+ }
67
+
68
+ .status-pill {
69
+ display: flex;
70
+ align-items: center;
71
+ gap: 0.5rem;
72
+ font-size: 0.85rem;
73
+ font-family: 'JetBrains Mono', monospace;
74
+ padding: 0.3rem 0.8rem;
75
+ border-radius: 20px;
76
+ background: rgba(16, 185, 129, 0.1);
77
+ border: 1px solid rgba(16, 185, 129, 0.3);
78
+ color: #34d399;
79
+ }
80
+
81
+ .status-dot {
82
+ width: 8px;
83
+ height: 8px;
84
+ border-radius: 50%;
85
+ background: #10b981;
86
+ box-shadow: 0 0 8px #10b981;
87
+ }
88
+
89
+ main {
90
+ flex: 1;
91
+ max-width: 1200px;
92
+ width: 100%;
93
+ margin: 0 auto;
94
+ padding: 2.5rem 1.5rem;
95
+ display: grid;
96
+ grid-template-columns: 1fr 1fr;
97
+ gap: 2rem;
98
+ }
99
+
100
+ @media (max-width: 900px) {
101
+ main { grid-template-columns: 1fr; }
102
+ }
103
+
104
+ .card {
105
+ background: var(--surface);
106
+ border: 1px solid var(--surface-border);
107
+ border-radius: 16px;
108
+ padding: 1.5rem;
109
+ display: flex;
110
+ flex-direction: column;
111
+ gap: 1.25rem;
112
+ }
113
+
114
+ .card-header {
115
+ display: flex;
116
+ justify-content: space-between;
117
+ align-items: center;
118
+ }
119
+
120
+ .card-title {
121
+ font-size: 1rem;
122
+ font-weight: 600;
123
+ color: var(--text-main);
124
+ display: flex;
125
+ align-items: center;
126
+ gap: 0.5rem;
127
+ }
128
+
129
+ textarea {
130
+ width: 100%;
131
+ height: 220px;
132
+ background: #0b0f19;
133
+ border: 1px solid var(--surface-border);
134
+ border-radius: 12px;
135
+ padding: 1rem;
136
+ color: var(--text-main);
137
+ font-family: 'JetBrains Mono', monospace;
138
+ font-size: 0.95rem;
139
+ line-height: 1.6;
140
+ resize: none;
141
+ outline: none;
142
+ transition: border-color 0.2s;
143
+ }
144
+
145
+ textarea:focus {
146
+ border-color: var(--primary);
147
+ box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
148
+ }
149
+
150
+ .presets {
151
+ display: flex;
152
+ gap: 0.5rem;
153
+ flex-wrap: wrap;
154
+ }
155
+
156
+ .preset-btn {
157
+ background: #192237;
158
+ border: 1px solid var(--surface-border);
159
+ color: var(--text-muted);
160
+ font-size: 0.78rem;
161
+ padding: 0.4rem 0.8rem;
162
+ border-radius: 6px;
163
+ cursor: pointer;
164
+ transition: all 0.2s;
165
+ }
166
+
167
+ .preset-btn:hover {
168
+ color: var(--text-main);
169
+ border-color: #3b82f6;
170
+ background: #1e293b;
171
+ }
172
+
173
+ .verify-btn {
174
+ background: linear-gradient(135deg, #2563eb, #4f46e5);
175
+ color: white;
176
+ font-weight: 600;
177
+ padding: 0.85rem;
178
+ border: none;
179
+ border-radius: 10px;
180
+ cursor: pointer;
181
+ display: flex;
182
+ justify-content: center;
183
+ align-items: center;
184
+ gap: 0.5rem;
185
+ font-size: 0.95rem;
186
+ box-shadow: 0 4px 15px rgba(37, 99, 235, 0.35);
187
+ transition: transform 0.1s, opacity 0.2s;
188
+ }
189
+
190
+ .verify-btn:hover {
191
+ opacity: 0.95;
192
+ transform: translateY(-1px);
193
+ }
194
+
195
+ .verify-btn:active {
196
+ transform: translateY(1px);
197
+ }
198
+
199
+ .metrics-row {
200
+ display: grid;
201
+ grid-template-columns: repeat(3, 1fr);
202
+ gap: 1rem;
203
+ }
204
+
205
+ .metric-box {
206
+ background: #0b0f19;
207
+ border: 1px solid var(--surface-border);
208
+ border-radius: 10px;
209
+ padding: 0.85rem;
210
+ text-align: center;
211
+ }
212
+
213
+ .metric-label {
214
+ font-size: 0.75rem;
215
+ color: var(--text-muted);
216
+ text-transform: uppercase;
217
+ font-weight: 600;
218
+ letter-spacing: 0.05em;
219
+ }
220
+
221
+ .metric-value {
222
+ font-family: 'JetBrains Mono', monospace;
223
+ font-size: 1.15rem;
224
+ font-weight: 700;
225
+ margin-top: 0.25rem;
226
+ }
227
+
228
+ .verdict-badge {
229
+ display: inline-block;
230
+ padding: 0.4rem 0.9rem;
231
+ border-radius: 8px;
232
+ font-size: 0.85rem;
233
+ font-weight: 700;
234
+ font-family: 'JetBrains Mono', monospace;
235
+ }
236
+
237
+ .verdict-true {
238
+ background: rgba(16, 185, 129, 0.15);
239
+ border: 1px solid rgba(16, 185, 129, 0.4);
240
+ color: #34d399;
241
+ }
242
+
243
+ .verdict-false {
244
+ background: rgba(239, 68, 68, 0.15);
245
+ border: 1px solid rgba(239, 68, 68, 0.4);
246
+ color: #f87171;
247
+ }
248
+
249
+ .verdict-contradiction {
250
+ background: rgba(245, 158, 11, 0.15);
251
+ border: 1px solid rgba(245, 158, 11, 0.4);
252
+ color: #fbbf24;
253
+ }
254
+
255
+ .proof-list {
256
+ display: flex;
257
+ flex-direction: column;
258
+ gap: 0.75rem;
259
+ max-height: 240px;
260
+ overflow-y: auto;
261
+ }
262
+
263
+ .proof-item {
264
+ background: #0b0f19;
265
+ border: 1px solid var(--surface-border);
266
+ border-radius: 8px;
267
+ padding: 0.85rem;
268
+ font-size: 0.85rem;
269
+ font-family: 'JetBrains Mono', monospace;
270
+ }
271
+
272
+ .correction-box {
273
+ background: rgba(16, 185, 129, 0.05);
274
+ border: 1px dashed rgba(16, 185, 129, 0.3);
275
+ border-radius: 10px;
276
+ padding: 1rem;
277
+ }
278
+
279
+ .correction-title {
280
+ color: #34d399;
281
+ font-size: 0.8rem;
282
+ font-weight: 700;
283
+ margin-bottom: 0.5rem;
284
+ text-transform: uppercase;
285
+ }
286
+
287
+ .correction-text {
288
+ font-family: 'JetBrains Mono', monospace;
289
+ font-size: 0.9rem;
290
+ line-height: 1.5;
291
+ color: #e2e8f0;
292
+ }
293
+ </style>
294
+ </head>
295
+ <body>
296
+ <header>
297
+ <div class="brand">
298
+ <div class="logo-badge">0H</div>
299
+ <h1>Zero<span>Hallucination</span> AI</h1>
300
+ </div>
301
+ <div class="status-pill">
302
+ <div class="status-dot"></div>
303
+ DETERMINISTIC SOLVER ACTIVE
304
+ </div>
305
+ </header>
306
+
307
+ <main>
308
+ <!-- Left: Input & Verification Controller -->
309
+ <div class="card">
310
+ <div class="card-header">
311
+ <div class="card-title">Untrusted AI Stream</div>
312
+ <span style="font-size: 0.8rem; color: var(--text-muted)">Real-time Interception</span>
313
+ </div>
314
+
315
+ <textarea id="aiInput" placeholder="Paste or type any AI-generated text, calculation, or logic deduction here..."></textarea>
316
+
317
+ <div class="presets">
318
+ <button class="preset-btn" onclick="loadPreset(1)">Financial Slip</button>
319
+ <button class="preset-btn" onclick="loadPreset(2)">Compute Error</button>
320
+ <button class="preset-btn" onclick="loadPreset(3)">Logical Loop</button>
321
+ <button class="preset-btn" onclick="loadPreset(4)">Sound Deduction</button>
322
+ <button class="preset-btn" onclick="loadPreset(5)">Z3 SMT Solver</button>
323
+ <button class="preset-btn" style="border-color: #6366f1; color: #818cf8; font-weight: 600;" onclick="simulateStream()">⚡ Live Stream Interceptor</button>
324
+ </div>
325
+
326
+ <button class="verify-btn" onclick="runVerification()">
327
+ <svg width="18" height="18" fill="none" viewBox="0 0 24 24" stroke="currentColor">
328
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
329
+ </svg>
330
+ Verify & Prove Deterministic Truth
331
+ </button>
332
+ </div>
333
+
334
+ <!-- Right: Verification Certificate & Auto-Correction -->
335
+ <div class="card" id="resultsCard">
336
+ <div class="card-header">
337
+ <div class="card-title">Mathematical Proof Certificate</div>
338
+ <div id="verdictBadge" class="verdict-badge verdict-true">READY</div>
339
+ </div>
340
+
341
+ <div class="metrics-row">
342
+ <div class="metric-box">
343
+ <div class="metric-label">Latency</div>
344
+ <div class="metric-value" id="latencyVal">0.00 ms</div>
345
+ </div>
346
+ <div class="metric-box">
347
+ <div class="metric-label">Hallucination Index</div>
348
+ <div class="metric-value" id="hallucinationVal">0.0%</div>
349
+ </div>
350
+ <div class="metric-box">
351
+ <div class="metric-label">Claims Analyzed</div>
352
+ <div class="metric-value" id="claimsVal">0</div>
353
+ </div>
354
+ </div>
355
+
356
+ <div class="correction-box" id="correctionBox" style="display:none;">
357
+ <div class="correction-title">Certified Auto-Correction (Ground Truth)</div>
358
+ <div class="correction-text" id="correctedOutput"></div>
359
+ </div>
360
+
361
+ <div>
362
+ <div class="card-title" style="margin-bottom: 0.75rem; font-size: 0.9rem;">Proof Traces & Axioms</div>
363
+ <div class="proof-list" id="proofList">
364
+ <div style="color: var(--text-muted); font-size: 0.85rem; padding: 1rem; text-align: center;">
365
+ Press "Verify" to run formal axiomatic solver.
366
+ </div>
367
+ </div>
368
+ </div>
369
+ </div>
370
+ </main>
371
+
372
+ <script>
373
+ const PRESETS = {
374
+ 1: "The quarterly revenue grew by 15% of 240 is 38 million dollars.",
375
+ 2: "Total cluster uptime across zones: 25 * 4 = 105 hours.",
376
+ 3: "Alice is older than Bob. Bob is older than Charlie. Therefore, Charlie is older than Alice.",
377
+ 4: "The total unit capacity is 12 * 8 = 96 nodes. Alpha is greater than Beta. Beta is greater than Gamma.",
378
+ 5: "Server load balances: 2*x + 10 = 30, so x = 8 workers assigned."
379
+ };
380
+
381
+ function loadPreset(id) {
382
+ document.getElementById('aiInput').value = PRESETS[id];
383
+ runVerification();
384
+ }
385
+
386
+ async function simulateStream() {
387
+ const sample = "The quarterly expansion was significant. 15% of 240 is 38 million dollars. Server load balances: 2*x + 10 = 30, so x = 8 workers assigned.";
388
+ const inputEl = document.getElementById('aiInput');
389
+ inputEl.value = "";
390
+ const tokens = sample.split(" ");
391
+ for (let i = 0; i < tokens.length; i++) {
392
+ inputEl.value += (i === 0 ? "" : " ") + tokens[i];
393
+ await new Promise(r => setTimeout(r, 45));
394
+ }
395
+ runVerification();
396
+ }
397
+
398
+ async function runVerification() {
399
+ const text = document.getElementById('aiInput').value.trim();
400
+ if (!text) return;
401
+
402
+ try {
403
+ const res = await fetch('/api/verify', {
404
+ method: 'POST',
405
+ headers: { 'Content-Type': 'application/json' },
406
+ body: JSON.stringify({ text })
407
+ });
408
+ const data = await res.json();
409
+ renderResults(data);
410
+ } catch (err) {
411
+ alert('Verification engine connection failed: ' + err);
412
+ }
413
+ }
414
+
415
+ function renderResults(data) {
416
+ document.getElementById('latencyVal').innerText = data.execution_time_ms.toFixed(3) + ' ms';
417
+ document.getElementById('hallucinationVal').innerText = (data.hallucination_score * 100).toFixed(1) + '%';
418
+ document.getElementById('claimsVal').innerText = data.claims_detected.length;
419
+
420
+ const badge = document.getElementById('verdictBadge');
421
+ badge.className = 'verdict-badge ';
422
+
423
+ if (data.status === 'PROVEN_TRUE') {
424
+ badge.classList.add('verdict-true');
425
+ badge.innerText = 'PROVEN TRUE';
426
+ } else if (data.status.includes('CONTRADICTION')) {
427
+ badge.classList.add('verdict-contradiction');
428
+ badge.innerText = 'CONTRADICTION';
429
+ } else {
430
+ badge.classList.add('verdict-false');
431
+ badge.innerText = 'HALLUCINATION';
432
+ }
433
+
434
+ const corrBox = document.getElementById('correctionBox');
435
+ const corrText = document.getElementById('correctedOutput');
436
+ if (data.certified_correction && data.status !== 'PROVEN_TRUE') {
437
+ corrBox.style.display = 'block';
438
+ corrText.innerText = data.certified_correction;
439
+ } else {
440
+ corrBox.style.display = 'none';
441
+ }
442
+
443
+ const proofList = document.getElementById('proofList');
444
+ proofList.innerHTML = '';
445
+ if (data.proof_steps.length === 0) {
446
+ proofList.innerHTML = '<div style="color: #94a3b8; font-size: 0.85rem;">No mathematical or formal relations detected to verify.</div>';
447
+ } else {
448
+ data.proof_steps.forEach(s => {
449
+ const item = document.createElement('div');
450
+ item.className = 'proof-item';
451
+ const color = s.is_valid ? '#34d399' : '#f87171';
452
+ const icon = s.is_valid ? '[PASS]' : '[FAIL]';
453
+ item.innerHTML = `<span style="color:${color}; font-weight:700;">${icon}</span> <b>Rule:</b> ${s.inference_rule}<br><span style="color:#cbd5e1">${s.diagnostic}</span>`;
454
+ proofList.appendChild(item);
455
+ });
456
+ }
457
+ }
458
+
459
+ window.onload = () => loadPreset(1);
460
+ </script>
461
+ </body>
462
+ </html>
463
+ """
464
+
@@ -0,0 +1,124 @@
1
+ import re
2
+ from typing import List
3
+ from .types import Claim, ClaimType
4
+ from .physics_verifier import PhysicsVerifier
5
+ from .sql_code_verifier import SQLSchemaVerifier
6
+
7
+ class ClaimDecomposer:
8
+ """
9
+ Parses natural language text emitted by LLMs into formalized atomic claims.
10
+ Extracts mathematical equations, logical deductions, and temporal assertions.
11
+ """
12
+
13
+ # Matches expressions like "15% of 240 is 38", "5 * 12 = 50", "12 * 8 = 96"
14
+ MATH_CALC_REGEX = re.compile(
15
+ r'(\b\d+(?:\.\d+)?\s*(?:%|percent)\s*(?:of)?\s*\d+(?:\.\d+)?\s*(?:is|=|equals|amounts to)\s*\d+(?:\.\d+)?|\b\d+(?:\.\d+)?\s*[\+\-\*\/]\s*\d+(?:\.\d+)?\s*(?:=|\bis\b|\bequals\b)\s*\d+(?:\.\d+)?)',
16
+ re.IGNORECASE
17
+ )
18
+
19
+ # Algebraic constraints with variables: "2*x + 10 = 30, so x = 8", "3y - 9 = 0, therefore y = 3"
20
+ ALGEBRAIC_REGEX = re.compile(
21
+ r'(\b[a-zA-Z0-9_\s\+\-\*\/\^]+\s*=\s*[a-zA-Z0-9_\s\+\-\*\/\^]+[,\s]+(?:so|therefore|then)\s+[a-zA-Z]+\s*(?:=|\bis\b)\s*[-+]?\d+(?:\.\d+)?)',
22
+ re.IGNORECASE
23
+ )
24
+
25
+ # Relational propositions: "X is greater than Y", "A is taller than B"
26
+ RELATIONAL_REGEX = re.compile(
27
+ r'\b([A-Za-z0-9_\'\"]+)\s+is\s+(greater than|less than|taller than|shorter than|older than|younger than|equal to|not equal to)\s+([A-Za-z0-9_\'\"]+)',
28
+ re.IGNORECASE
29
+ )
30
+
31
+ # Temporal assertions: "X happened before Y"
32
+ TEMPORAL_REGEX = re.compile(
33
+ r'\b([A-Za-z0-9_\s]+)\s+(happened|occurred|was born|died|started|ended)\s+(before|after|in|during)\s+([A-Za-z0-9_\s]+)',
34
+ re.IGNORECASE
35
+ )
36
+
37
+ def __init__(self):
38
+ self.physics = PhysicsVerifier()
39
+ self.sql_verifier = SQLSchemaVerifier()
40
+
41
+ def extract_claims(self, text: str) -> List[Claim]:
42
+ claims: List[Claim] = []
43
+ seen_texts = set()
44
+
45
+ # 0. Check for SQL & Code Queries
46
+ sql_claims = self.sql_verifier.extract_sql_claims(text)
47
+ for sc in sql_claims:
48
+ if sc.raw_text not in seen_texts:
49
+ seen_texts.add(sc.raw_text)
50
+ claims.append(sc)
51
+
52
+ # 0. Check for Physical Invariants & Dimensional Claims
53
+ physics_claims = self.physics.extract_physics_claims(text)
54
+ for pc in physics_claims:
55
+ if pc.raw_text not in seen_texts:
56
+ seen_texts.add(pc.raw_text)
57
+ claims.append(pc)
58
+
59
+ sentences = re.split(r'[\.\n;]+', text)
60
+
61
+ for sentence in sentences:
62
+ sentence = sentence.strip()
63
+ if not sentence:
64
+ continue
65
+
66
+ # 1. Check for Algebraic equations & constraints (SMT)
67
+ alg_matches = self.ALGEBRAIC_REGEX.findall(sentence)
68
+ for match in alg_matches:
69
+ match_clean = match.strip()
70
+ if match_clean not in seen_texts:
71
+ seen_texts.add(match_clean)
72
+ claims.append(Claim(
73
+ raw_text=match_clean,
74
+ claim_type=ClaimType.ALGEBRAIC_CONSTRAINT,
75
+ formal_expression=match_clean
76
+ ))
77
+
78
+ # 2. Check for Math calculations
79
+ calc_matches = self.MATH_CALC_REGEX.findall(sentence)
80
+ for match in calc_matches:
81
+ match_clean = match.strip()
82
+ if match_clean not in seen_texts:
83
+ seen_texts.add(match_clean)
84
+ claims.append(Claim(
85
+ raw_text=match_clean,
86
+ claim_type=ClaimType.MATHEMATICAL,
87
+ formal_expression=match_clean
88
+ ))
89
+
90
+ # 3. Check for Relational Logic
91
+ rel_matches = self.RELATIONAL_REGEX.findall(sentence)
92
+ for subj, relation, obj in rel_matches:
93
+ raw_rel = f"{subj.strip()} is {relation.strip()} {obj.strip()}"
94
+ if raw_rel not in seen_texts:
95
+ seen_texts.add(raw_rel)
96
+ claims.append(Claim(
97
+ raw_text=raw_rel,
98
+ claim_type=ClaimType.LOGICAL_RELATION,
99
+ formal_expression=f"{subj.strip().lower()} {relation.lower().replace(' ', '_')} {obj.strip().lower()}",
100
+ extracted_variables={
101
+ "subject": subj.strip(),
102
+ "relation": relation.strip().lower(),
103
+ "object": obj.strip()
104
+ }
105
+ ))
106
+
107
+ # 3. Check for Temporal Causality
108
+ temp_matches = self.TEMPORAL_REGEX.findall(sentence)
109
+ for event_a, verb, order, event_b in temp_matches:
110
+ raw_temp = f"{event_a.strip()} {verb.strip()} {order.strip()} {event_b.strip()}"
111
+ if raw_temp not in seen_texts:
112
+ seen_texts.add(raw_temp)
113
+ claims.append(Claim(
114
+ raw_text=raw_temp,
115
+ claim_type=ClaimType.TEMPORAL_ORDER,
116
+ formal_expression=f"order({event_a.strip().lower()}, {order.lower()}, {event_b.strip().lower()})",
117
+ extracted_variables={
118
+ "event_a": event_a.strip(),
119
+ "relation": order.strip().lower(),
120
+ "event_b": event_b.strip()
121
+ }
122
+ ))
123
+
124
+ return claims