"""Cross-domain pattern synthesis over memory strands (journalism suite 4). The owner's closed-loop insight: every domain sits in one system, so a rung (number, year, name) or theme repeated across UNRELATED domains is a lead. The suite finds the overlap; the human decides whether the connection is causal, coincidental, or symbolic. Cards carry the base-rate caveat so a repeated number is never auto-promoted to a conclusion. Basis: helix rung model (research/helix.py) + memory skill's cross-domain reinforcement doctrine (tiny-model-memory). Usage: from research.patterns import CrossDomainPatterns p = CrossDomainPatterns() p.add_strand("economics", "the 1929 crash... gold standard...") p.add_strand("religion", "Genesis... serpent... 1929...") p.report() """ import re from collections import defaultdict from research.helix import rungs THEMES = [ "serpent", "snake", "eye", "pyramid", "coin", "flood", "plague", "fire", "tower", "gate", "seal", "crown", "star", "dove", "wolf", "mirror", "key", "blood", "gold", "iron", "wall", "circle", "garden", "beast", "mark", "number", "trumpet", "scroll", "angel", "dragon", ] _NAME = re.compile(r"\b[A-Z][a-z]{2,20}(?:\s+[A-Z][a-z]{2,20}){0,2}\b") class CrossDomainPatterns: def __init__(self): self.strands = [] # list of {"domain", "text"} def add_strand(self, domain, text): self.strands.append({"domain": domain, "text": text}) def domains(self): return sorted({s["domain"] for s in self.strands}) def shared_rungs(self): """Rungs (numbers/years/times/names) present in >=2 different domains.""" by_rung = defaultdict(dict) for s in self.strands: vals = set(rungs(s["text"])) for v in vals: by_rung[v][s["domain"]] = by_rung[v].get(s["domain"], 0) + 1 out = [] for v, doms in by_rung.items(): if len(doms) >= 2: out.append({"rung": v, "domains": sorted(doms), "strength": min(doms.values())}) return sorted(out, key=lambda c: -c["strength"]) def theme_overlap(self): """Themes present in >=2 different domains.""" by_theme = defaultdict(set) for s in self.strands: low = s["text"].lower() for t in THEMES: if t in low: by_theme[t].add(s["domain"]) return [{"theme": t, "domains": sorted(d)} for t, d in by_theme.items() if len(d) >= 2] def names(self, min_domains=2): """Proper-noun co-occurrence across domains (loose entity bridge).""" by_name = defaultdict(set) for s in self.strands: for m in _NAME.finditer(s["text"]): by_name[m.group(0)].add(s["domain"]) return [{"name": n, "domains": sorted(d)} for n, d in by_name.items() if len(d) >= min_domains] def report(self): lines = ["# Cross-Domain Pattern Synthesis", ""] lines.append(f"domains: {', '.join(self.domains())}") lines.append("") lines.append("## Shared rungs (numbers/years/times)") sr = self.shared_rungs() for c in sr[:20]: lines.append(f"- `{c['rung']}` (strength {c['strength']}) appears in " f"{', '.join(c['domains'])}") lines.append(" - LEAD: check whether causal, coincidental, or symbolic") if not sr: lines.append("- no cross-domain rungs") lines.append("") lines.append("## Theme overlap") for c in self.theme_overlap()[:20]: lines.append(f"- '{c['theme']}' in {', '.join(c['domains'])}") lines.append(" - LEAD: base-rate check first; repeated themes are " "common in text") if not self.theme_overlap(): lines.append("- no cross-domain themes") lines.append("") lines.append("## Name bridges") for c in self.names()[:20]: lines.append(f"- '{c['name']}' in {', '.join(c['domains'])}") if not self.names(): lines.append("- no cross-domain name bridges") lines.append("") lines.append("_Every card above is a LEAD, never a verdict._") return "\n".join(lines)