Create truth_kernel.py
Browse files- truth_kernel.py +28 -0
truth_kernel.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import importlib
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
class TruthKernel:
|
| 7 |
+
def __init__(self, rules_path="rules", config_path="config/manifest.json"):
|
| 8 |
+
self.rules = []
|
| 9 |
+
self.audits = []
|
| 10 |
+
self.load_rules(rules_path, config_path)
|
| 11 |
+
|
| 12 |
+
def load_rules(self, rules_path, config_path):
|
| 13 |
+
with open(config_path, "r") as f:
|
| 14 |
+
config = json.load(f)
|
| 15 |
+
for rule in config.get("active_rules", []):
|
| 16 |
+
module = importlib.import_module(f"{rules_path}.{rule}")
|
| 17 |
+
self.rules.append((rule, module.validate))
|
| 18 |
+
|
| 19 |
+
def validate(self, text):
|
| 20 |
+
results = {}
|
| 21 |
+
for name, fn in self.rules:
|
| 22 |
+
results[name] = fn(text)
|
| 23 |
+
return results
|
| 24 |
+
|
| 25 |
+
def audit(self, text):
|
| 26 |
+
hash = hashlib.sha256(text.encode()).hexdigest()
|
| 27 |
+
self.audits.append((text, hash))
|
| 28 |
+
return hash
|