File size: 849 Bytes
d6c41fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import hashlib
import importlib
import os
import json

class TruthKernel:
    def __init__(self, rules_path="rules", config_path="config/manifest.json"):
        self.rules = []
        self.audits = []
        self.load_rules(rules_path, config_path)

    def load_rules(self, rules_path, config_path):
        with open(config_path, "r") as f:
            config = json.load(f)
        for rule in config.get("active_rules", []):
            module = importlib.import_module(f"{rules_path}.{rule}")
            self.rules.append((rule, module.validate))

    def validate(self, text):
        results = {}
        for name, fn in self.rules:
            results[name] = fn(text)
        return results

    def audit(self, text):
        hash = hashlib.sha256(text.encode()).hexdigest()
        self.audits.append((text, hash))
        return hash