% Generated by rdf-prolog-roundtrip.

% RDF terms use rdf(Subject, Predicate, Object, Graph).

rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/kind'), iri('https://example.org/city/class/cooling-center'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/neighbourhood'), iri('https://example.org/city/neighbourhood/central'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/open'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/cooling'), iri('https://example.org/city/state/available'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/capacity'), literal('140', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/wheelchairAccess'), iri('https://example.org/city/value/yes'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/kind'), iri('https://example.org/city/class/cooling-center'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/neighbourhood'), iri('https://example.org/city/neighbourhood/north'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/open'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/cooling'), iri('https://example.org/city/state/available'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/capacity'), literal('80', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/wheelchairAccess'), iri('https://example.org/city/value/yes'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/kind'), iri('https://example.org/city/class/school'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/neighbourhood'), iri('https://example.org/city/neighbourhood/riverside'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/open'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/cooling'), iri('https://example.org/city/state/available'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/capacity'), literal('90', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/wheelchairAccess'), iri('https://example.org/city/value/yes'), iri('https://example.org/graph/city-facilities')).
rdf(iri('https://example.org/city/neighbourhood/riverside'), iri('https://example.org/vocab/expectedDemand'), literal('70', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/emergency-plan')).
rdf(iri('https://example.org/city/neighbourhood/riverside'), iri('https://example.org/vocab/mobileUnitAvailable'), iri('https://example.org/city/value/yes'), iri('https://example.org/graph/emergency-plan')).
rdf(iri('https://example.org/city/route/7'), iri('https://example.org/vocab/connects'), iri('https://example.org/city/facility/north-library'), iri('https://example.org/graph/transit-plan')).
rdf(iri('https://example.org/city/route/8'), iri('https://example.org/vocab/connects'), iri('https://example.org/city/facility/central-hall'), iri('https://example.org/graph/transit-plan')).
rdf(iri('https://example.org/city/route/7'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/running'), iri('https://example.org/graph/transit-plan')).
rdf(iri('https://example.org/city/route/8'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/running'), iri('https://example.org/graph/transit-plan')).
rdf(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/power'), iri('https://example.org/city/state/unstable'), iri('https://example.org/graph/power-sensors')).
rdf(iri('https://example.org/city/evidence/transit-api-20260827'), iri('https://example.org/vocab/evidenceKind'), iri('https://example.org/city/evidence-kind/official-feed'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/transit-api-20260827'), iri('https://example.org/vocab/publisher'), iri('https://example.org/city/publisher/city-transit'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/facilities-bulletin-20260827'), iri('https://example.org/vocab/evidenceKind'), iri('https://example.org/city/evidence-kind/official-document'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/facilities-bulletin-20260827'), iri('https://example.org/vocab/publisher'), iri('https://example.org/city/publisher/city-facilities'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/community-post-4812'), iri('https://example.org/vocab/evidenceKind'), iri('https://example.org/city/evidence-kind/public-report'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/community-post-4812'), iri('https://example.org/vocab/publisher'), iri('https://example.org/city/publisher/resident-network'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/volunteer-message-112'), iri('https://example.org/vocab/evidenceKind'), iri('https://example.org/city/evidence-kind/public-report'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/evidence/volunteer-message-112'), iri('https://example.org/vocab/publisher'), iri('https://example.org/city/publisher/volunteer-coordinator'), iri('https://example.org/graph/evidence-registry')).
rdf(iri('https://example.org/city/proposal/p1'), iri('https://example.org/vocab/statement'), triple(iri('https://example.org/city/route/7'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/suspended')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p1'), iri('https://example.org/vocab/agent'), iri('https://example.org/city/agent/language-agent'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p1'), iri('https://example.org/vocab/evidence'), iri('https://example.org/city/evidence/transit-api-20260827'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p1'), iri('https://example.org/vocab/confidencePercent'), literal('99', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p2'), iri('https://example.org/vocab/statement'), triple(iri('https://example.org/city/facility/riverside-school'), iri('https://example.org/vocab/emergencyDesignation'), iri('https://example.org/city/class/cooling-center')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p2'), iri('https://example.org/vocab/agent'), iri('https://example.org/city/agent/language-agent'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p2'), iri('https://example.org/vocab/evidence'), iri('https://example.org/city/evidence/facilities-bulletin-20260827'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p2'), iri('https://example.org/vocab/confidencePercent'), literal('93', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p3'), iri('https://example.org/vocab/statement'), triple(iri('https://example.org/city/facility/central-hall'), iri('https://example.org/vocab/status'), iri('https://example.org/city/state/closed')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p3'), iri('https://example.org/vocab/agent'), iri('https://example.org/city/agent/language-agent'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p3'), iri('https://example.org/vocab/evidence'), iri('https://example.org/city/evidence/community-post-4812'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p3'), iri('https://example.org/vocab/confidencePercent'), literal('78', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p4'), iri('https://example.org/vocab/statement'), triple(iri('https://example.org/city/facility/north-library'), iri('https://example.org/vocab/capacity'), literal('40', datatype('http://www.w3.org/2001/XMLSchema#integer'))), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p4'), iri('https://example.org/vocab/agent'), iri('https://example.org/city/agent/language-agent'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p4'), iri('https://example.org/vocab/evidence'), iri('https://example.org/city/evidence/volunteer-message-112'), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/proposal/p4'), iri('https://example.org/vocab/confidencePercent'), literal('66', datatype('http://www.w3.org/2001/XMLSchema#integer')), iri('https://example.org/graph/ai-proposals')).
rdf(iri('https://example.org/city/review/r2'), iri('https://example.org/vocab/aboutProposal'), iri('https://example.org/city/proposal/p2'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r2'), iri('https://example.org/vocab/reviewer'), iri('https://example.org/city/actor/emergency-coordinator'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r2'), iri('https://example.org/vocab/decision'), iri('https://example.org/city/decision/accept'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r2'), iri('https://example.org/vocab/note'), literal('facility bulletin verified by phone', datatype('http://www.w3.org/2001/XMLSchema#string')), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r3'), iri('https://example.org/vocab/aboutProposal'), iri('https://example.org/city/proposal/p3'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r3'), iri('https://example.org/vocab/reviewer'), iri('https://example.org/city/actor/operations-officer'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r3'), iri('https://example.org/vocab/decision'), iri('https://example.org/city/decision/reject'), iri('https://example.org/graph/human-review')).
rdf(iri('https://example.org/city/review/r3'), iri('https://example.org/vocab/note'), literal('official operations desk confirms Central Hall is open', datatype('http://www.w3.org/2001/XMLSchema#string')), iri('https://example.org/graph/human-review')).

% Rules
% Symbiotic knowledge graph rules for EyeProlog.
%
% The source rdf/4 facts above are generated by rdf-prolog-roundtrip from
% symbiotic-knowledge-graph-input.nq.  RDF stays the interchange and storage
% model; these rules provide the explicit reasoning and governance layer.

%% goal: proposal_state(X0, X1)
%% goal: conflict(X0, X1, X2, X3)
%% goal: knowledge_gain(X0, X1, X2)
%% goal: recommended_action(X0, X1, X2)
%% goal: decision_reason(X0, X1, X2)
%% goal: audit(X0, X1, X2, X3, X4)
%% goal: feedback_signal(X0, X1, X2)
%% goal: symbiosis_gain(X0, X1)
%% goal: knowledge_exchange(X0, X1)
%% goal: pipeline_step(X0, X1)
%% goal: cognitive_parallel(X0, X1)

% --- RDF vocabulary ----------------------------------------------------------

v(statement, iri('https://example.org/vocab/statement')).
v(agent, iri('https://example.org/vocab/agent')).
v(evidence, iri('https://example.org/vocab/evidence')).
v(confidence_percent, iri('https://example.org/vocab/confidencePercent')).
v(evidence_kind, iri('https://example.org/vocab/evidenceKind')).
v(about_proposal, iri('https://example.org/vocab/aboutProposal')).
v(reviewer, iri('https://example.org/vocab/reviewer')).
v(decision, iri('https://example.org/vocab/decision')).
v(note, iri('https://example.org/vocab/note')).
v(kind, iri('https://example.org/vocab/kind')).
v(neighbourhood, iri('https://example.org/vocab/neighbourhood')).
v(status, iri('https://example.org/vocab/status')).
v(cooling, iri('https://example.org/vocab/cooling')).
v(capacity, iri('https://example.org/vocab/capacity')).
v(wheelchair_access, iri('https://example.org/vocab/wheelchairAccess')).
v(expected_demand, iri('https://example.org/vocab/expectedDemand')).
v(mobile_unit_available, iri('https://example.org/vocab/mobileUnitAvailable')).
v(connects, iri('https://example.org/vocab/connects')).
v(power, iri('https://example.org/vocab/power')).
v(emergency_designation, iri('https://example.org/vocab/emergencyDesignation')).

graph(ai_proposals, iri('https://example.org/graph/ai-proposals')).
graph(human_review, iri('https://example.org/graph/human-review')).
graph(evidence_registry, iri('https://example.org/graph/evidence-registry')).
graph(accepted_knowledge, iri('https://example.org/graph/accepted-knowledge')).
graph(derived_decisions, iri('https://example.org/graph/derived-decisions')).

curated_graph(iri('https://example.org/graph/city-facilities')).
curated_graph(iri('https://example.org/graph/emergency-plan')).
curated_graph(iri('https://example.org/graph/transit-plan')).
curated_graph(iri('https://example.org/graph/power-sensors')).

curated(S, P, O) :- rdf(S, P, O, G), curated_graph(G).

integer_literal(literal(Text, datatype('http://www.w3.org/2001/XMLSchema#integer')), Number) :-
  atom_chars(Text, Chars),
  number_chars(Number, Chars).

% --- Candidate knowledge carried as RDF 1.2 triple terms --------------------

proposal(Id, Agent, Evidence, S, P, O, Confidence) :-
  graph(ai_proposals, G),
  v(statement, StatementP),
  v(agent, AgentP),
  v(evidence, EvidenceP),
  v(confidence_percent, ConfidenceP),
  rdf(Id, StatementP, triple(S, P, O), G),
  rdf(Id, AgentP, Agent, G),
  rdf(Id, EvidenceP, Evidence, G),
  rdf(Id, ConfidenceP, ConfidenceLiteral, G),
  integer_literal(ConfidenceLiteral, Confidence).

evidence_kind(Evidence, Kind) :-
  graph(evidence_registry, G),
  v(evidence_kind, Predicate),
  rdf(Evidence, Predicate, Kind, G).

human_review(Id, Reviewer, Decision, Note) :-
  graph(human_review, G),
  v(about_proposal, AboutP),
  v(reviewer, ReviewerP),
  v(decision, DecisionP),
  v(note, NoteP),
  rdf(Review, AboutP, Id, G),
  rdf(Review, ReviewerP, Reviewer, G),
  rdf(Review, DecisionP, DecisionIri, G),
  rdf(Review, NoteP, literal(Note, datatype('http://www.w3.org/2001/XMLSchema#string')), G),
  decision_atom(DecisionIri, Decision).

decision_atom(iri('https://example.org/city/decision/accept'), accept).
decision_atom(iri('https://example.org/city/decision/reject'), reject).

% --- Trust, conflict, and review policy --------------------------------------

auto_eligible(iri('https://example.org/city/evidence-kind/official-feed')).
replaceable(P) :- v(status, P).

authoritative_override(Evidence, Predicate) :-
  evidence_kind(Evidence, Kind),
  auto_eligible(Kind),
  replaceable(Predicate).

opposite(iri('https://example.org/city/state/open'), iri('https://example.org/city/state/closed')).
opposite(iri('https://example.org/city/state/closed'), iri('https://example.org/city/state/open')).
opposite(iri('https://example.org/city/state/running'), iri('https://example.org/city/state/suspended')).
opposite(iri('https://example.org/city/state/suspended'), iri('https://example.org/city/state/running')).

conflict_iri(Id, Subject, Predicate, Existing) :-
  proposal(Id, _Agent, _Evidence, Subject, Predicate, Proposed, _Confidence),
  curated(Subject, Predicate, Existing),
  opposite(Proposed, Existing).

proposal_state_iri(Id, auto_accepted) :-
  proposal(Id, _Agent, Evidence, Subject, Predicate, _Object, Confidence),
  evidence_kind(Evidence, Kind),
  auto_eligible(Kind),
  Confidence >= 95,
  ( \+ conflict_iri(Id, Subject, Predicate, _Existing)
  ; authoritative_override(Evidence, Predicate)
  ).

proposal_state_iri(Id, human_accepted) :-
  proposal(Id, _Agent, _Evidence, _S, _P, _O, _Confidence),
  human_review(Id, _Reviewer, accept, _Note).

proposal_state_iri(Id, human_rejected) :-
  proposal(Id, _Agent, _Evidence, _S, _P, _O, _Confidence),
  human_review(Id, _Reviewer, reject, _Note).

proposal_state_iri(Id, needs_review) :-
  proposal(Id, _Agent, _Evidence, _S, _P, _O, _Confidence),
  \+ proposal_state_iri(Id, auto_accepted),
  \+ human_review(Id, _Reviewer, _Decision, _Note).

% --- Stage-aware operational graph ------------------------------------------

stage(before_review).
stage(after_review).

accepted(before_review, Id) :- proposal_state_iri(Id, auto_accepted).
accepted(after_review, Id) :- proposal_state_iri(Id, auto_accepted).
accepted(after_review, Id) :- proposal_state_iri(Id, human_accepted).

has_accepted_override(Stage, S, P) :-
  replaceable(P),
  proposal(Id, _Agent, _Evidence, S, P, _O, _Confidence),
  accepted(Stage, Id).

known(Stage, S, P, O) :-
  curated(S, P, O),
  \+ has_accepted_override(Stage, S, P).

known(Stage, S, P, O) :-
  proposal(Id, _Agent, _Evidence, S, P, O, _Confidence),
  accepted(Stage, Id).

knowledge_gain_iri(S, P, O) :-
  known(after_review, S, P, O),
  \+ known(before_review, S, P, O).

% --- Operational reasoning ---------------------------------------------------

cooling_center(Stage, Center) :-
  v(kind, P),
  known(Stage, Center, P, iri('https://example.org/city/class/cooling-center')).
cooling_center(Stage, Center) :-
  v(emergency_designation, P),
  known(Stage, Center, P, iri('https://example.org/city/class/cooling-center')).

numeric_value(Stage, S, Predicate, Number) :-
  known(Stage, S, Predicate, Literal),
  integer_literal(Literal, Number).

sufficient_capacity(Stage, Center, Neighbourhood) :-
  v(capacity, CapacityP),
  v(expected_demand, DemandP),
  numeric_value(Stage, Center, CapacityP, Capacity),
  numeric_value(Stage, Neighbourhood, DemandP, Demand),
  Capacity >= Demand.

operational_center(Stage, Center, Neighbourhood) :-
  cooling_center(Stage, Center),
  v(status, StatusP),
  v(cooling, CoolingP),
  v(wheelchair_access, AccessP),
  v(power, PowerP),
  known(Stage, Center, StatusP, iri('https://example.org/city/state/open')),
  known(Stage, Center, CoolingP, iri('https://example.org/city/state/available')),
  known(Stage, Center, AccessP, iri('https://example.org/city/value/yes')),
  sufficient_capacity(Stage, Center, Neighbourhood),
  \+ known(Stage, Center, PowerP, iri('https://example.org/city/state/unstable')).

local_center(Stage, Neighbourhood, Center) :-
  operational_center(Stage, Center, Neighbourhood),
  v(neighbourhood, NeighbourhoodP),
  known(Stage, Center, NeighbourhoodP, Neighbourhood).

reachable_center(Stage, Neighbourhood, Center) :-
  operational_center(Stage, Center, Neighbourhood),
  v(connects, ConnectsP),
  v(status, StatusP),
  known(Stage, Route, ConnectsP, Center),
  known(Stage, Route, StatusP, iri('https://example.org/city/state/running')).

recommended_action_iri(Stage, Neighbourhood, open_local_center(Center)) :-
  stage(Stage),
  local_center(Stage, Neighbourhood, Center).

recommended_action_iri(Stage, Neighbourhood, use_transit_to(Center)) :-
  stage(Stage),
  \+ local_center(Stage, Neighbourhood, _Local),
  reachable_center(Stage, Neighbourhood, Center).

recommended_action_iri(Stage, Neighbourhood, deploy_mobile_unit) :-
  stage(Stage),
  \+ local_center(Stage, Neighbourhood, _Local),
  \+ reachable_center(Stage, Neighbourhood, _Remote),
  v(mobile_unit_available, MobileP),
  known(Stage, Neighbourhood, MobileP, iri('https://example.org/city/value/yes')).

% --- Friendly checked output -------------------------------------------------

short(iri('https://example.org/city/proposal/p1'), p1).
short(iri('https://example.org/city/proposal/p2'), p2).
short(iri('https://example.org/city/proposal/p3'), p3).
short(iri('https://example.org/city/proposal/p4'), p4).
short(iri('https://example.org/city/agent/language-agent'), language_agent).
short(iri('https://example.org/city/evidence/transit-api-20260827'), transit_api_20260827).
short(iri('https://example.org/city/evidence/facilities-bulletin-20260827'), facilities_bulletin_20260827).
short(iri('https://example.org/city/evidence/community-post-4812'), community_post_4812).
short(iri('https://example.org/city/evidence/volunteer-message-112'), volunteer_message_112).
short(iri('https://example.org/city/actor/emergency-coordinator'), emergency_coordinator).
short(iri('https://example.org/city/actor/operations-officer'), operations_officer).
short(iri('https://example.org/city/facility/central-hall'), central_hall).
short(iri('https://example.org/city/facility/north-library'), north_library).
short(iri('https://example.org/city/facility/riverside-school'), riverside_school).
short(iri('https://example.org/city/neighbourhood/riverside'), riverside).
short(iri('https://example.org/city/route/7'), route_7).
short(iri('https://example.org/vocab/status'), status).
short(iri('https://example.org/vocab/emergencyDesignation'), emergency_designation).
short(iri('https://example.org/city/state/running'), running).
short(iri('https://example.org/city/state/open'), open).
short(iri('https://example.org/city/class/cooling-center'), cooling_center).

proposal_state(Id, State) :-
  proposal_state_iri(IdIri, State),
  short(IdIri, Id).

conflict(Id, Subject, Predicate, Existing) :-
  conflict_iri(IdIri, SubjectIri, PredicateIri, ExistingIri),
  short(IdIri, Id),
  short(SubjectIri, Subject),
  short(PredicateIri, Predicate),
  short(ExistingIri, Existing).

knowledge_gain(Subject, Predicate, Object) :-
  knowledge_gain_iri(SubjectIri, PredicateIri, ObjectIri),
  short(SubjectIri, Subject),
  short(PredicateIri, Predicate),
  short(ObjectIri, Object).

friendly_action(deploy_mobile_unit, deploy_mobile_unit).
friendly_action(open_local_center(CenterIri), open_local_center(Center)) :- short(CenterIri, Center).
friendly_action(use_transit_to(CenterIri), use_transit_to(Center)) :- short(CenterIri, Center).

recommended_action(Stage, Neighbourhood, Action) :-
  recommended_action_iri(Stage, NeighbourhoodIri, ActionIri),
  short(NeighbourhoodIri, Neighbourhood),
  friendly_action(ActionIri, Action).

decision_reason(before_review, riverside,
  "Route 7 is suspended, Central Hall has unstable power, and Riverside School is not yet an approved cooling centre; deploy the mobile unit.") :-
  recommended_action(before_review, riverside, deploy_mobile_unit).

decision_reason(after_review, riverside,
  "Human review confirms Riverside School as an emergency cooling centre; its verified capacity and accessibility satisfy Riverside demand locally.") :-
  recommended_action(after_review, riverside, open_local_center(riverside_school)).

review_summary(Id, human(Reviewer, Decision)) :-
  human_review(Id, ReviewerIri, Decision, _Note),
  short(ReviewerIri, Reviewer).
review_summary(Id, automatic) :- proposal_state_iri(Id, auto_accepted).
review_summary(Id, pending) :- proposal_state_iri(Id, needs_review).

audit(Id, Agent, Evidence, State, Review) :-
  proposal(IdIri, AgentIri, EvidenceIri, _S, _P, _O, _Confidence),
  proposal_state_iri(IdIri, State),
  review_summary(IdIri, Review),
  short(IdIri, Id),
  short(AgentIri, Agent),
  short(EvidenceIri, Evidence).

feedback_signal(language_agent, Id, accepted_by_human) :-
  proposal_state_iri(IdIri, human_accepted), short(IdIri, Id).
feedback_signal(language_agent, Id, rejected_by_human) :-
  proposal_state_iri(IdIri, human_rejected), short(IdIri, Id).
feedback_signal(language_agent, Id, unresolved) :-
  proposal_state_iri(IdIri, needs_review), short(IdIri, Id).

symbiosis_gain(graph, accepted_machine_knowledge) :- proposal_state(p2, human_accepted).
symbiosis_gain(agent, better_operational_answer) :-
  recommended_action(after_review, riverside, open_local_center(riverside_school)).
symbiosis_gain(human, inspectable_reason) :- decision_reason(after_review, riverside, _Reason).
symbiosis_gain(governance, rejected_claim_remains_outside_operational_graph) :-
  proposal_state(p3, human_rejected).
symbiosis_gain(rdf, accepted_and_derived_knowledge_can_be_published_back) :-
  result_rdf(_, _, _, _).

knowledge_exchange(X, Y) :- knowledge_exchange_fact(X, Y).
knowledge_exchange_fact(machine_to_graph, candidate(p2, riverside_school, emergency_designation, cooling_center)).
knowledge_exchange_fact(graph_to_machine, constraint(central_hall, power, unstable)).
knowledge_exchange_fact(human_to_machine, review(p2, accept)).
knowledge_exchange_fact(human_to_machine, review(p3, reject)).
knowledge_exchange_fact(machine_to_human, recommendation(after_review, riverside, open_local_center(riverside_school))).
knowledge_exchange_fact(rdf_to_prolog, ordinary_rdf4_facts).
knowledge_exchange_fact(prolog_to_rdf, materialized_ground_rdf4).

pipeline_step(N, Description) :- pipeline_step_fact(N, Description).
pipeline_step_fact(1, 'RDF 1.2 N-Quads: named graphs keep source and governance boundaries explicit').
pipeline_step_fact(2, 'rdf-prolog-roundtrip: RDF becomes ordinary rdf/4 Prolog facts without a solver').
pipeline_step_fact(3, 'EyeProlog: ISO Prolog rules validate candidates, apply review policy, and derive actions').
pipeline_step_fact(4, 'EyeProlog: result_rdf/4 materializes accepted knowledge and decisions as ground RDF-shaped facts').
pipeline_step_fact(5, 'rdf-prolog-roundtrip: ground rdf/4 facts become RDF again for publication or federation').

cognitive_parallel(Prolog, Human) :- cognitive_parallel_fact(Prolog, Human).
cognitive_parallel_fact(fact, remembered_assertion).
cognitive_parallel_fact(rule, reusable_generalization).
cognitive_parallel_fact(query, explicit_question).
cognitive_parallel_fact(variable_binding, filling_in_an_answer).
cognitive_parallel_fact(backtracking, considering_alternatives).
cognitive_parallel_fact(proof, giving_reasons).
cognitive_parallel_fact(review, correcting_shared_knowledge).

% --- Materialization boundary back to RDF -----------------------------------

result_rdf(
  iri('https://example.org/city/facility/riverside-school'),
  iri('https://example.org/vocab/emergencyDesignation'),
  iri('https://example.org/city/class/cooling-center'),
  iri('https://example.org/graph/accepted-knowledge')) :-
  proposal_state(p2, human_accepted).

result_rdf(
  iri('https://example.org/city/proposal/p2'),
  iri('https://example.org/vocab/reviewOutcome'),
  iri('https://example.org/city/decision/accept'),
  iri('https://example.org/graph/human-review')) :-
  proposal_state(p2, human_accepted).

result_rdf(
  iri('https://example.org/city/proposal/p3'),
  iri('https://example.org/vocab/reviewOutcome'),
  iri('https://example.org/city/decision/reject'),
  iri('https://example.org/graph/human-review')) :-
  proposal_state(p3, human_rejected).

result_rdf(
  iri('https://example.org/city/decision/before-review'),
  iri('https://example.org/vocab/recommendedAction'),
  iri('https://example.org/city/action/deploy-mobile-unit'),
  iri('https://example.org/graph/derived-decisions')) :-
  recommended_action(before_review, riverside, deploy_mobile_unit).

result_rdf(
  iri('https://example.org/city/decision/after-review'),
  iri('https://example.org/vocab/recommendedAction'),
  iri('https://example.org/city/action/open-local-center'),
  iri('https://example.org/graph/derived-decisions')) :-
  recommended_action(after_review, riverside, open_local_center(riverside_school)).

result_rdf(
  iri('https://example.org/city/decision/after-review'),
  iri('https://example.org/vocab/selectedFacility'),
  iri('https://example.org/city/facility/riverside-school'),
  iri('https://example.org/graph/derived-decisions')) :-
  recommended_action(after_review, riverside, open_local_center(riverside_school)).

write_results :-
  result_rdf(S, P, O, G),
  write_term(rdf(S, P, O, G), [quoted(true)]),
  write('.'),
  nl,
  fail.
write_results.

:- set_prolog_flag(unknown, fail).
