from typing import Any, Protocol class SemanticLike(Protocol): def query(self, domain, limit): ... class ContradictionDetector: def __init__(self, semantic=None): self._semantic = semantic def check(self, claim, context=None): out = [] if not claim or not claim.strip(): return out ctx = context or {} domain = ctx.get("domain", "") if self._semantic: facts = self._semantic.query(domain or None, 50) for f in facts: st = f.get("statement", "") if st and "not " in claim.lower() and st.lower() in claim.lower(): out.append("Contradicts: " + st[:100]) return out