feat(spatial): 契约加 conflicts——两份来源打架时,只有两个世界都成立的答案才算答案
This commit is contained in:
1 parent
e799e02e22
commit
a01ca7eab7
9 files changed
+206
-27
No files matched your search
+47
-6
@@ -239,8 +239,15 @@ def _contact_is_real(ents: dict, e: Edge) -> bool:
|
||||
return box[2] == float(other.attrs.get("plane", 0))
|
||||
|
||||
|
||||
def validate_evidence(full: FullState, query: Query, evidence) -> bool:
|
||||
"""Independent re-check of a claimed certificate."""
|
||||
def validate_evidence(full: FullState, query: Query, evidence,
|
||||
conflicts=()) -> bool:
|
||||
"""Independent re-check of a claimed certificate.
|
||||
|
||||
A certificate may not cite a relation two sources disagree on: the whole
|
||||
point of the dispute is that nobody has established that relation, so it
|
||||
cannot carry a proof. Same principle as ``_contact_is_real`` refusing a
|
||||
contact the geometry does not show.
|
||||
"""
|
||||
evidence = list(evidence or [])
|
||||
if not evidence or _removed_edge(query) in evidence:
|
||||
return False
|
||||
@@ -248,6 +255,10 @@ def validate_evidence(full: FullState, query: Query, evidence) -> bool:
|
||||
if any(eid not in by_id for eid in evidence):
|
||||
return False
|
||||
edges = [by_id[eid] for eid in evidence]
|
||||
if conflicts:
|
||||
named = {(c.get("kind"), frozenset((c.get("a"), c.get("b")))) for c in conflicts}
|
||||
if any((e.kind, frozenset((e.a, e.b))) in named for e in edges):
|
||||
return False
|
||||
if query.kind == "connection":
|
||||
return conduct_path(edges, query.a, query.b) is not None
|
||||
if query.kind == "freedom":
|
||||
@@ -279,6 +290,13 @@ def validate_evidence(full: FullState, query: Query, evidence) -> bool:
|
||||
# label
|
||||
|
||||
|
||||
def hostile(obs, edge) -> bool:
|
||||
"""Is this relation disputed between two sources."""
|
||||
key = frozenset((edge.a, edge.b))
|
||||
return any(c.get("kind") == edge.kind and frozenset((c.get("a"), c.get("b"))) == key
|
||||
for c in (obs.conflicts or []))
|
||||
|
||||
|
||||
def withheld_flag(obs) -> bool:
|
||||
"""Is the inventory bigger than what was handed over.
|
||||
|
||||
@@ -302,6 +320,8 @@ def withheld_flag(obs) -> bool:
|
||||
rel_r = scope.get("rendered_relations") or {}
|
||||
if any(rel.get(k, 0) > rel_r.get(k, 0) for k in rel):
|
||||
return True
|
||||
if scope.get("conflicts"):
|
||||
return True
|
||||
return bool(set(scope.get("layers") or []) - set(scope.get("rendered_layers") or []))
|
||||
|
||||
|
||||
@@ -331,11 +351,32 @@ def label(obs: Observation, full: FullState, query: Query,
|
||||
ans_vis = evaluate(alt[0].entities, alt[0].edges, query) if alt else ans_full
|
||||
withheld = withheld_flag(obs)
|
||||
|
||||
if withheld:
|
||||
if ans_vis is True:
|
||||
# the observation proves it on its own; nothing withheld can break it
|
||||
conflicts = list(obs.conflicts or [])
|
||||
if conflicts or withheld:
|
||||
# Two sources naming the same relation and disagreeing is not the same
|
||||
# kind of ignorance as "nobody told me". A disputed relation can be
|
||||
# present or absent, both consistent with everything we were told, so the
|
||||
# honest answer is whatever holds in *both* worlds -- and nothing else.
|
||||
#
|
||||
# That is sharper than the withheld rule, which cannot enumerate the
|
||||
# missing content and so must answer "unknown" as soon as the visible
|
||||
# structure fails to prove. Here the disputed item is named, so "false in
|
||||
# both worlds" is a legitimate false rather than an abstention.
|
||||
sure = alt[0] if alt else full
|
||||
if conflicts:
|
||||
disputed = {(c.get("kind"), frozenset((c.get("a"), c.get("b"))))
|
||||
for c in conflicts}
|
||||
kept = [e for e in sure.edges if (e.kind, frozenset((e.a, e.b))) not in disputed]
|
||||
sure = FullState(entities=list(sure.entities), edges=kept)
|
||||
ans_sure = evaluate(sure.entities, sure.edges, query)
|
||||
if ans_sure is True:
|
||||
# this proof never touches a disputed relation, so it stands
|
||||
return Label(answer="true", change=_change(full, query, True),
|
||||
evidence=evidence_for(alt[0], query) if alt else [], sufficient=True)
|
||||
evidence=evidence_for(sure, query), sufficient=True)
|
||||
if not withheld and ans_vis is False:
|
||||
# the answer is false whether the disputed relation exists or not
|
||||
return Label(answer="false", change=_change(full, query, False),
|
||||
evidence=[], sufficient=True)
|
||||
return Label(answer="unknown", change="unknown", evidence=[], sufficient=False)
|
||||
|
||||
if ans_full is None or ans_vis is None or ans_full != ans_vis:
|
||||
|
||||
Reference in new issue
Block a user