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