diff --git a/spatial/checker.py b/spatial/checker.py index 3f5e38f..ca82af3 100644 --- a/spatial/checker.py +++ b/spatial/checker.py @@ -254,22 +254,51 @@ def validate_evidence(full: FullState, query: Query, evidence) -> bool: def label(obs: Observation, full: FullState, query: Query, alternatives: Iterable[FullState] = ()) -> Label: - """Full state decides; the observation decides whether we may say so.""" - worlds = [full] + list(alternatives) - answers = [evaluate(w.entities, w.edges, query) for w in worlds] - if any(a is None for a in answers) or len(set(answers)) != 1: - # the observation admits more than one truth: this is the real - # "insufficient evidence" case, not an occlusion tag + """Full state decides; the observation decides whether we may say so. + + When something is withheld the rule is *monotone*: a hidden conduct edge can + only connect, a hidden contact can only support, a hidden mate can only lock + an axis. None of them can undo a proof the observation already contains. So + + * the visible structure already proves the answer -> decidable "true"; + * it does not -> the withheld item could be exactly the missing piece, and + the answer is unknown, however the one full state we happen to hold + resolves it. + + The cheaper rule -- compare the full state against the observation's own + world -- marks "the pedestal is behind the part and in this particular scene + it would not have helped" as decidable false. That is not a fact the agent + can know: another equally consistent world puts the pedestal under the + centroid and the answer flips. Measured: area.sup2h came out 36 decidable / + 92 not, and the model swung between answering all of them and abstaining + from all of them, because the split is not in the observation. + """ + ans_full = evaluate(full.entities, full.edges, query) + alt = list(alternatives) + ans_vis = evaluate(alt[0].entities, alt[0].edges, query) if alt else ans_full + withheld = bool(obs.dangling) or bool((obs.hidden or {}).get("entity")) \ + or bool((obs.hidden or {}).get("edge")) + + if withheld: + if ans_vis is True: + # the observation proves it on its own; nothing withheld can break it + return Label(answer="true", change=_change(full, query, True), + evidence=evidence_for(alt[0], query) if alt else [], sufficient=True) return Label(answer="unknown", change="unknown", evidence=[], sufficient=False) - ans_after = answers[0] + if ans_full is None or ans_vis is None or ans_full != ans_vis: + return Label(answer="unknown", change="unknown", evidence=[], sufficient=False) + + return Label(answer="true" if ans_full else "false", + change=_change(full, query, ans_full), + evidence=evidence_for(full, query), sufficient=True) + + +def _change(full: FullState, query: Query, ans_after) -> str: + if query.edit is None: + return "same" before = Query(kind=query.kind, a=query.a, b=query.b, edit=None) ans_before = evaluate(full.entities, full.edges, before) - if query.edit is None: - change = "same" - elif ans_before is None: - change = "unknown" - else: - change = "changed" if ans_before != ans_after else "same" - return Label(answer="true" if ans_after else "false", change=change, - evidence=evidence_for(full, query), sufficient=True) + if ans_before is None: + return "unknown" + return "changed" if ans_before != ans_after else "same"