| |
| import sys |
| import re |
| import os |
|
|
| DNA_FILE = "/home/j/Área de trabalho/crompressor-ia/v4.3_cognitive_leap/DNA_ATOMS.md" |
|
|
| def load_atoms(): |
| |
| atoms = {"W": [], "F": [], "P": [], "dna": []} |
| current_type = None |
| |
| if os.path.exists(DNA_FILE): |
| with open(DNA_FILE, "r", encoding="utf-8") as f: |
| for line in f: |
| line = line.strip() |
| if "## ⌬W_" in line: current_type = "W" |
| elif "## ⌬F_" in line: current_type = "F" |
| elif "## ⌬P_" in line: current_type = "P" |
| elif "## ⌬dna" in line: current_type = "dna" |
| elif line.startswith("- ⌬") or line.startswith("- @dna"): |
| if current_type: |
| atoms[current_type].append(line) |
| return atoms |
|
|
| def retrieve_context(query, atoms): |
| |
| query_terms = query.lower().split() |
| |
| |
| result = [] |
| |
| |
| result.extend(atoms["dna"][:3]) |
| |
| |
| for t in ["W", "F", "P"]: |
| for a in atoms[t]: |
| if any(term in a.lower() for term in query_terms): |
| if a not in result and len(result) < 8: |
| result.append(a) |
| |
| |
| for t in ["W", "F", "P"]: |
| for a in atoms[t]: |
| if a not in result and len(result) < 6: |
| result.append(a) |
| |
| return result |
|
|
| if __name__ == "__main__": |
| query = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else "" |
| atoms_db = load_atoms() |
| context_atoms = retrieve_context(query, atoms_db) |
| |
| if context_atoms: |
| for atom in context_atoms: |
| |
| print(atom) |
|
|