001 package aima.logic.fol.inference.proof; 002 003 import java.util.ArrayList; 004 import java.util.Collections; 005 import java.util.LinkedHashMap; 006 import java.util.List; 007 import java.util.Map; 008 009 import aima.logic.fol.kb.data.Clause; 010 import aima.logic.fol.kb.data.Literal; 011 import aima.logic.fol.parsing.ast.Term; 012 import aima.logic.fol.parsing.ast.Variable; 013 014 /** 015 * @author Ciaran O'Reilly 016 * 017 */ 018 public class ProofStepBwChGoal extends AbstractProofStep { 019 // 020 private List<ProofStep> predecessors = new ArrayList<ProofStep>(); 021 // 022 private Clause toProve = null; 023 private Literal currentGoal = null; 024 private Map<Variable, Term> bindings = new LinkedHashMap<Variable, Term>(); 025 026 public ProofStepBwChGoal(Clause toProve, Literal currentGoal, 027 Map<Variable, Term> bindings) { 028 this.toProve = toProve; 029 this.currentGoal = currentGoal; 030 this.bindings.putAll(bindings); 031 } 032 033 public Map<Variable, Term> getBindings() { 034 return bindings; 035 } 036 037 public void setPredecessor(ProofStep predecessor) { 038 predecessors.clear(); 039 predecessors.add(predecessor); 040 } 041 042 // 043 // START-ProofStep 044 public List<ProofStep> getPredecessorSteps() { 045 return Collections.unmodifiableList(predecessors); 046 } 047 048 public String getProof() { 049 StringBuilder sb = new StringBuilder(); 050 List<Literal> nLits = toProve.getNegativeLiterals(); 051 for (int i = 0; i < toProve.getNumberNegativeLiterals(); i++) { 052 sb.append(nLits.get(i).getAtomicSentence()); 053 if (i != (toProve.getNumberNegativeLiterals() - 1)) { 054 sb.append(" AND "); 055 } 056 } 057 if (toProve.getNumberNegativeLiterals() > 0) { 058 sb.append(" => "); 059 } 060 sb.append(toProve.getPositiveLiterals().get(0)); 061 return sb.toString(); 062 } 063 064 public String getJustification() { 065 return "Current Goal " + currentGoal.getAtomicSentence().toString() 066 + ", " + bindings; 067 } 068 // END-ProofStep 069 // 070 }